Skip to content

Commit

Permalink
Merge pull request #1044 from yast/cwm-improvements
Browse files Browse the repository at this point in the history
CWM improvements
  • Loading branch information
imobachgs committed Sep 28, 2020
2 parents d0120e4 + 891b272 commit c7b90ff
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
27 changes: 27 additions & 0 deletions library/cwm/src/lib/cwm/common_widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,25 @@ class ComboBox < AbstractWidget
include ValueBasedWidget
include ItemsSelection
abstract_method :label

alias_method :orig_value=, :value=

# Sets the current value
#
# If the given value is not in the list of items but the widget is editable,
# the item is added to the list.
#
# @param val [Object] Value to assign to the widget
def value=(val)
change_items([[val, val]] + items) if editable? && !items.map(&:first).include?(val)
self.orig_value = val
end

private

def editable?
opt.include?(:editable)
end
end

# Widget representing selection box to select value.
Expand Down Expand Up @@ -349,6 +368,14 @@ class MenuButton < AbstractWidget

include ItemsSelection
abstract_method :label

# @see AbstractWidget#cwm_definition
# @return [WidgetHash]
def cwm_definition
res = super
res["handle_events"] = items.map(&:first) unless handle_all_events
res
end
end

# Multiline text widget
Expand Down
27 changes: 27 additions & 0 deletions library/cwm/test/common_widgets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,30 @@ def hspacing
end
end
end

describe CWM::ComboBox do
class MountPointSelector < CWM::ComboBox
def label
""
end

def opt
[:editable]
end

def items
[["/", "/ (root)"]]
end
end

subject { MountPointSelector.new }

describe "#value=" do
describe "when the widget is editable" do
it "adds the given value to the list of items" do
expect(subject).to receive(:change_items).with([["/srv", "/srv"], ["/", "/ (root)"]])
subject.value = "/srv"
end
end
end
end
10 changes: 10 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
-------------------------------------------------------------------
Fri Sep 25 08:59:57 UTC 2020 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Small improvements to CWM based widgets (related to bsc#1136454):
- An editable ComboBox will refresh the list of items when a new
one is given as its current value.
- By default, a MenuButton widget listens to events from all its
buttons.
- 4.3.31

-------------------------------------------------------------------
Thu Sep 24 07:25:01 UTC 2020 - Ladislav Slezák <lslezak@suse.cz>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


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

0 comments on commit c7b90ff

Please sign in to comment.