Skip to content

Commit

Permalink
Made CWM::Tree abstract; CWM::TreePager.new wants a Tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed May 25, 2017
1 parent fc081ca commit e092938
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
22 changes: 10 additions & 12 deletions library/cwm/src/lib/cwm/tree.rb
Expand Up @@ -34,17 +34,6 @@ def ui_term

# A tree of nested {TreeItem}s
class Tree < CustomWidget
# @return [Enumerable<TreeItem>]
attr_reader :items
attr_reader :label

# @param label [String]
# @param items [Array<TreeItem>]
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)
Expand All @@ -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<TreeItem>]
def items
[]
end

# @param items [Array<TreeItem>]
def change_items(items)
@items = items
item_terms = items.map(&:ui_term)
Yast::UI.ChangeWidget(Id(widget_id), :Items, item_terms)
end
Expand Down
8 changes: 4 additions & 4 deletions library/cwm/src/lib/cwm/tree_pager.rb
Expand Up @@ -27,10 +27,10 @@ def pages

# A {Pager} that uses a {Tree} to select the {Page}s
class TreePager < Pager
# @param items [Array<PagerTreeItem>]
def initialize(*items, label:)
@tree = Tree.new(items, label: label)
pages = items.flat_map(&:pages)
# @param tree [Tree<PagerTreeItem>]
def initialize(tree)
@tree = tree
pages = tree.items.flat_map(&:pages)
super(*pages)
end

Expand Down

0 comments on commit e092938

Please sign in to comment.