From 4c0a594685bf3af3562d4a3127c8a77eefae8b81 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Fri, 11 Jan 2019 13:26:46 +0100 Subject: [PATCH 1/7] add method to focus widget --- library/cwm/src/lib/cwm/abstract_widget.rb | 7 +++++++ library/cwm/test/abstract_widget_test.rb | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/library/cwm/src/lib/cwm/abstract_widget.rb b/library/cwm/src/lib/cwm/abstract_widget.rb index 5e4f802c2..3e6d7cb2c 100644 --- a/library/cwm/src/lib/cwm/abstract_widget.rb +++ b/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) @@ -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 diff --git a/library/cwm/test/abstract_widget_test.rb b/library/cwm/test/abstract_widget_test.rb index befb9ac9c..a396e80ba 100755 --- a/library/cwm/test/abstract_widget_test.rb +++ b/library/cwm/test/abstract_widget_test.rb @@ -5,6 +5,8 @@ require "cwm/abstract_widget" require "cwm/rspec" +Yast.import "UI" + describe CWM::AbstractWidget do include_examples "CWM::AbstractWidget" @@ -190,4 +192,21 @@ 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 From 00a1f7bbca60680c6840e241ca2d57083237d805 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Fri, 11 Jan 2019 13:32:04 +0100 Subject: [PATCH 2/7] add more common widgets to rspec of cwm --- library/cwm/src/lib/cwm/rspec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/library/cwm/src/lib/cwm/rspec.rb b/library/cwm/src/lib/cwm/rspec.rb index 467844bb4..1246b5ea3 100644 --- a/library/cwm/src/lib/cwm/rspec.rb +++ b/library/cwm/src/lib/cwm/rspec.rb @@ -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 @@ -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" From b2d5e237c492bc8c3f817a7d9e3e32be46492c96 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Fri, 11 Jan 2019 18:23:32 +0100 Subject: [PATCH 3/7] CWM: allow dialogs and popups to have its help and also fix popup to display help --- library/cwm/src/lib/cwm/dialog.rb | 23 ++++++++++++++++++++++- library/cwm/src/lib/cwm/popup.rb | 3 +++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/library/cwm/src/lib/cwm/dialog.rb b/library/cwm/src/lib/cwm/dialog.rb index 22ac8f897..60cd40a8e 100644 --- a/library/cwm/src/lib/cwm/dialog.rb +++ b/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" @@ -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) @@ -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, diff --git a/library/cwm/src/lib/cwm/popup.rb b/library/cwm/src/lib/cwm/popup.rb index 47ed6b657..b94e135dc 100644 --- a/library/cwm/src/lib/cwm/popup.rb +++ b/library/cwm/src/lib/cwm/popup.rb @@ -20,6 +20,8 @@ # find current contact information at www.suse.com. require "cwm/dialog" +Yast.import "Popup" + module CWM # CWM pop-up dialog # @@ -52,6 +54,7 @@ def wizard_create_dialog(&block) # @return [Yast::Term] def layout VBox( + Id(:WizardDialog), HSpacing(50), Left(Heading(Id(:title), title)), VStretch(), From 979b0ff2cd99f441df96480af6b0fadde023f45c Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 14 Jan 2019 11:02:38 +0100 Subject: [PATCH 4/7] add example of popup with help and also with own help and fix crash with default title --- library/cwm/examples/popup.rb | 75 ++++++++++++++++++++++++++++++++ library/cwm/src/lib/cwm/popup.rb | 6 +++ 2 files changed, 81 insertions(+) create mode 100644 library/cwm/examples/popup.rb diff --git a/library/cwm/examples/popup.rb b/library/cwm/examples/popup.rb new file mode 100644 index 000000000..8794f5fca --- /dev/null +++ b/library/cwm/examples/popup.rb @@ -0,0 +1,75 @@ +# 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 + _("

Goat will eat cabbage.

") + end +end + +class Cabbage < CWM::CheckBox + def initialize + textdomain "example" + end + + def label + _("Cabbage") + end + + def help + _("

Poor cabbage cannot eat anyone.

") + end +end + +class Wolf < CWM::CheckBox + def initialize + textdomain "example" + end + + def label + _("Wolf") + end + + def help + _("

Wolf hates vegans, so will eat goat and won't even touch cabbage.

") + end +end + +class Ferryman < ::CWM::Popup + def initialize + textdomain "example" + end + + def contents + HBox( + Cabbage.new, + Goat.new, + Wolf.new + ) + end + + def help + _("

Ferryman

Represents common Ferryman challenge with two place in boat and following rules for passengers:

") + end + + def title + "" +#_("Ferryman") + end +end + +Ferryman.new.run diff --git a/library/cwm/src/lib/cwm/popup.rb b/library/cwm/src/lib/cwm/popup.rb index b94e135dc..03937af6e 100644 --- a/library/cwm/src/lib/cwm/popup.rb +++ b/library/cwm/src/lib/cwm/popup.rb @@ -36,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. + def title + "" + end + private # Redefines the mechanism to open the dialog to use the adapted layout From e4c902ae66ba93f0621b4f48fb3e6e28eaf4869e Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 14 Jan 2019 11:08:01 +0100 Subject: [PATCH 5/7] make rubocop happy --- library/cwm/examples/popup.rb | 3 +-- library/cwm/test/abstract_widget_test.rb | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/library/cwm/examples/popup.rb b/library/cwm/examples/popup.rb index 8794f5fca..d86ed8f20 100644 --- a/library/cwm/examples/popup.rb +++ b/library/cwm/examples/popup.rb @@ -67,8 +67,7 @@ def help end def title - "" -#_("Ferryman") + _("Ferryman") end end diff --git a/library/cwm/test/abstract_widget_test.rb b/library/cwm/test/abstract_widget_test.rb index a396e80ba..08b375926 100755 --- a/library/cwm/test/abstract_widget_test.rb +++ b/library/cwm/test/abstract_widget_test.rb @@ -202,7 +202,6 @@ def initialize end end - it "sets focus on given widget" do expect(Yast::UI).to receive(:SetFocus).with(Id("test")) From 9f433081e5db68422bc87301cbffe57d112e4c10 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 14 Jan 2019 11:57:23 +0100 Subject: [PATCH 6/7] changes --- package/yast2.changes | 9 +++++++++ package/yast2.spec | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/package/yast2.changes b/package/yast2.changes index b26ba6cff..17783879f 100644 --- a/package/yast2.changes +++ b/package/yast2.changes @@ -1,3 +1,12 @@ +------------------------------------------------------------------- +Mon Jan 14 10:55:20 UTC 2019 - Josef Reidinger + +- 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 diff --git a/package/yast2.spec b/package/yast2.spec index 5b502e08c..02997a48e 100644 --- a/package/yast2.spec +++ b/package/yast2.spec @@ -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 From c79463909221c17a163ff7d8d6d8b56d07abbdee Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 14 Jan 2019 12:38:25 +0100 Subject: [PATCH 7/7] fixes from review --- library/cwm/src/lib/cwm/dialog.rb | 6 ++++++ library/cwm/src/lib/cwm/popup.rb | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/library/cwm/src/lib/cwm/dialog.rb b/library/cwm/src/lib/cwm/dialog.rb index 60cd40a8e..d640c4cc0 100644 --- a/library/cwm/src/lib/cwm/dialog.rb +++ b/library/cwm/src/lib/cwm/dialog.rb @@ -9,6 +9,7 @@ module CWM # An OOP API and the pieces missing from {Yast::CWMClass#show Yast::CWM.show}: # - creating and closing a wizard dialog # - Back/Abort/Next buttons + # - Help introduction for dialog # # @see UI::Dialog # @see CWM::AbstractWidget @@ -104,6 +105,11 @@ def abort_handler true end + # Introduction for help. This help text will be displayed before widget specific help. + # Default implementation is empty. If dialog want its help it need to + # overwrite the method with own text. + # @note text should be marked for translation + # @return [String] help text with rich text formatting def help "" end diff --git a/library/cwm/src/lib/cwm/popup.rb b/library/cwm/src/lib/cwm/popup.rb index 03937af6e..87e47a04c 100644 --- a/library/cwm/src/lib/cwm/popup.rb +++ b/library/cwm/src/lib/cwm/popup.rb @@ -26,6 +26,7 @@ module CWM # CWM pop-up dialog # # This class offers a CWM dialog which behaves as a pop-up. + # @see {CWM::Dialog} for remaining configuration options. class Popup < Dialog # Determines that a dialog should always be open # @@ -37,7 +38,7 @@ def should_open_dialog? end # Popup does not allow nil, so overwrite Dialog default value. - # @return [String,nil] The dialog title. + # @return [String] The dialog title. def title "" end