Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cwm improvements2 #888

Merged
merged 7 commits into from Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 74 additions & 0 deletions library/cwm/examples/popup.rb
@@ -0,0 +1,74 @@
# Simple example to demonstrate object API for CWM

require_relative "example_helper"

require "cwm"
require "cwm/popup"

Yast.import "CWM"

class Goat < CWM::CheckBox
def initialize
textdomain "example"
end

def label
_("Goat")
end

def help
_("<p>Goat will eat cabbage.</p>")
end
end

class Cabbage < CWM::CheckBox
def initialize
textdomain "example"
end

def label
_("Cabbage")
end

def help
_("<p>Poor cabbage cannot eat anyone.</p>")
end
end

class Wolf < CWM::CheckBox
def initialize
textdomain "example"
end

def label
_("Wolf")
end

def help
_("<p>Wolf hates vegans, so will eat goat and won't even touch cabbage.</p>")
end
end

class Ferryman < ::CWM::Popup
def initialize
textdomain "example"
end

def contents
HBox(
Cabbage.new,
Goat.new,
Wolf.new
)
end

def help
_("<h3>Ferryman</h3><p>Represents common Ferryman challenge with two place in boat and following rules for passengers:</p>")
end

def title
_("Ferryman")
end
end

Ferryman.new.run
7 changes: 7 additions & 0 deletions library/cwm/src/lib/cwm/abstract_widget.rb
@@ -1,6 +1,8 @@
require "abstract_method"
require "yast"

Yast.import "UI"

module CWM
# A Yast::Term that can be passed as is to Yast::UI methods
# (OpenDialog, ReplaceWidget)
Expand Down Expand Up @@ -183,6 +185,11 @@ def disable
Yast::UI.ChangeWidget(Id(widget_id), :Enabled, false)
end

# Focus the widget. Useful when validation failed to highlight it.
def focus
Yast::UI.SetFocus(Id(widget_id))
end

protected

# A helper to check if an event is invoked by this widget
Expand Down
23 changes: 22 additions & 1 deletion library/cwm/src/lib/cwm/dialog.rb
@@ -1,5 +1,6 @@
require "yast"
require "abstract_method"
require "cwm/common_widgets"

Yast.import "CWM"
Yast.import "Wizard"
Expand Down Expand Up @@ -103,8 +104,28 @@ def abort_handler
true
end

def help
""
end

private

# Empty widget which is first on the page and contain help for whole dialog
class FakeHelp < Empty
def initialize(text)
@text = text
end

def init
Yast::CWM.ReplaceWidgetHelp # needed for popup to properly set help text outside wizard
log.info "calling init on fake help"
end

def help
@text
end
end

# Create a wizard dialog, run the *block*, ensure the dialog is closed.
# @param block
def wizard_create_dialog(&block)
Expand All @@ -118,7 +139,7 @@ def wizard_create_dialog(&block)
# @return [Symbol] wizard sequencer symbol
def cwm_show
Yast::CWM.show(
contents,
Yast::Term.new(:HBox, FakeHelp.new(help), contents),
caption: title,
back_button: back_button,
abort_button: abort_button,
Expand Down
9 changes: 9 additions & 0 deletions library/cwm/src/lib/cwm/popup.rb
Expand Up @@ -20,6 +20,8 @@
# find current contact information at www.suse.com.
require "cwm/dialog"

Yast.import "Popup"

module CWM
# CWM pop-up dialog
#
Expand All @@ -34,6 +36,12 @@ def should_open_dialog?
true
end

# Popup does not allow nil, so overwrite Dialog default value.
# @return [String,nil] The dialog title.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it does not allow nil, then the return should be modified accordingly, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right. Nil cause libyui red warning.

def title
""
end

private

# Redefines the mechanism to open the dialog to use the adapted layout
Expand All @@ -52,6 +60,7 @@ def wizard_create_dialog(&block)
# @return [Yast::Term]
def layout
VBox(
Id(:WizardDialog),
HSpacing(50),
Left(Heading(Id(:title), title)),
VStretch(),
Expand Down
25 changes: 25 additions & 0 deletions library/cwm/src/lib/cwm/rspec.rb
Expand Up @@ -89,6 +89,16 @@
include_examples "CWM::ItemsSelection"
end

RSpec.shared_examples "CWM::SelectionBox" do
include_examples "CWM::AbstractWidget"
include_examples "CWM::ItemsSelection"
end

RSpec.shared_examples "CWM::MultiSelectionBox" do
include_examples "CWM::AbstractWidget"
include_examples "CWM::ItemsSelection"
end

RSpec.shared_examples "CWM::PushButton" do
include_examples "CWM::AbstractWidget"
end
Expand Down Expand Up @@ -128,6 +138,21 @@
include_examples "CWM::ValueBasedWidget"
end

RSpec.shared_examples "CWM::InputField" do
include_examples "CWM::AbstractWidget"
include_examples "CWM::ValueBasedWidget"
end

RSpec.shared_examples "CWM::Password" do
include_examples "CWM::AbstractWidget"
include_examples "CWM::ValueBasedWidget"
end

RSpec.shared_examples "CWM::IntField" do
include_examples "CWM::AbstractWidget"
include_examples "CWM::ValueBasedWidget"
end

RSpec.shared_examples "CWM::Table" do
include_examples "CWM::AbstractWidget"

Expand Down
18 changes: 18 additions & 0 deletions library/cwm/test/abstract_widget_test.rb
Expand Up @@ -5,6 +5,8 @@
require "cwm/abstract_widget"
require "cwm/rspec"

Yast.import "UI"

describe CWM::AbstractWidget do
include_examples "CWM::AbstractWidget"

Expand Down Expand Up @@ -190,4 +192,20 @@ def cleanup
expect(TCleanup.new.cwm_definition).to be_key("cleanup")
end
end

describe "#focus" do
class TFocus < CWM::AbstractWidget
self.widget_type = :empty

def initialize
self.widget_id = "test"
end
end

it "sets focus on given widget" do
expect(Yast::UI).to receive(:SetFocus).with(Id("test"))

TFocus.new.focus
end
end
end
9 changes: 9 additions & 0 deletions package/yast2.changes
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Mon Jan 14 10:55:20 UTC 2019 - Josef Reidinger <jreidinger@suse.com>

- CWM: Add method focus to object CWM widgets (FATE#324662)
- CWM: Add rspec helper for common CWM widgets
- CWM: Allow CWM dialogs/popups to have own help
- CWM: Fix showing help for CWM Popup (FATE#324662)
- 4.1.50

-------------------------------------------------------------------
Thu Jan 10 14:45:03 UTC 2019 - Josef Reidinger <jreidinger@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 4.1.49
Version: 4.1.50
Release: 0
Summary: YaST2 - Main Package
License: GPL-2.0-only
Expand Down