diff --git a/library/cwm/src/lib/cwm/tree.rb b/library/cwm/src/lib/cwm/tree.rb index e7633facb..afab2ad9b 100644 --- a/library/cwm/src/lib/cwm/tree.rb +++ b/library/cwm/src/lib/cwm/tree.rb @@ -34,17 +34,6 @@ def ui_term # A tree of nested {TreeItem}s class Tree < CustomWidget - # @return [Enumerable] - attr_reader :items - attr_reader :label - - # @param label [String] - # @param items [Array] - def initialize(items, label:) - @label = label - @items = items - end - def contents item_terms = items.map(&:ui_term) Tree(Id(widget_id), Opt(:notify), label, item_terms) @@ -61,9 +50,18 @@ def value=(val) Yast::UI.ChangeWidget(Id(widget_id), :CurrentItem, val) end + # An alias for {TreeItem.new} + def new_item(*args, **kwargs) + TreeItem.new(*args, **kwargs) + end + + # @return [Enumerable] + def items + [] + end + # @param items [Array] def change_items(items) - @items = items item_terms = items.map(&:ui_term) Yast::UI.ChangeWidget(Id(widget_id), :Items, item_terms) end diff --git a/library/cwm/src/lib/cwm/tree_pager.rb b/library/cwm/src/lib/cwm/tree_pager.rb index e9e3c5051..ec52c5c7a 100644 --- a/library/cwm/src/lib/cwm/tree_pager.rb +++ b/library/cwm/src/lib/cwm/tree_pager.rb @@ -27,10 +27,10 @@ def pages # A {Pager} that uses a {Tree} to select the {Page}s class TreePager < Pager - # @param items [Array] - def initialize(*items, label:) - @tree = Tree.new(items, label: label) - pages = items.flat_map(&:pages) + # @param tree [Tree] + def initialize(tree) + @tree = tree + pages = tree.items.flat_map(&:pages) super(*pages) end