Module: Yast::AutoinstallTreeInclude

Defined in:
../../src/include/autoinstall/tree.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) createTreeNode(reference, name, children)

Wrapper function to create a new tree node

Parameters:

  • reference (String)

    Tree item id string (e.g. “part_2_0”)

  • name (String)

    Tree node name, displayed in widget

  • children (Array<Yast::Term>)

    list of child nodes



107
108
109
110
111
112
113
114
115
116
117
# File '../../src/include/autoinstall/tree.rb', line 107

def createTreeNode(reference, name, children)
  children = deep_copy(children)
  result = Empty()
  if 0 == Builtins.size(children)
    result = Item(Id(string2symbol(reference)), name)
  else
    result = Item(Id(string2symbol(reference)), name, true, children)
  end
  Builtins.y2milestone("new node: '%1'", result)
  deep_copy(result)
end

- (Object) currentTreeItem

Get the currently selected tree item id string.

Returns:

  • Item id string that is currently selected.



34
35
36
# File '../../src/include/autoinstall/tree.rb', line 34

def currentTreeItem
  symbol2string(Convert.to_symbol(UI.QueryWidget(@iTree, :Value)))
end

- (Object) initialize_autoinstall_tree(include_target)



11
12
13
14
15
16
17
18
19
# File '../../src/include/autoinstall/tree.rb', line 11

def initialize_autoinstall_tree(include_target)
  Yast.import "UI"
  Yast.include include_target, "autoinstall/common.rb"

  # name of tree widget to be displayed (in storage dialog)
  @sTree = :tree
  # common way to refer to the tree widget id
  @iTree = Id(@sTree)
end

- (Object) isContainedInTree(s, tree)



69
70
71
72
73
74
75
76
77
78
79
# File '../../src/include/autoinstall/tree.rb', line 69

def isContainedInTree(s, tree)
  tree = deep_copy(tree)
  found = false
  Builtins.foreach(tree) do |item|
    if termContains(item, s)
      found = true
      raise Break
    end
  end
  found
end

- (Object) selectTreeItem(newItem)

Select item 'newItem' in tree.

otherwise

Returns:

  • true if item exists in tree (and was selected), false



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File '../../src/include/autoinstall/tree.rb', line 85

def selectTreeItem(newItem)
  item = string2symbol(newItem)
  allItems = []
  allItems = Convert.convert(
    UI.QueryWidget(@iTree, :Items),
    :from => "any",
    :to   => "list <term>"
  )
  if isContainedInTree(item, allItems)
    UI.ChangeWidget(@iTree, :CurrentItem, item)
    return true
  end
  Builtins.y2warning("Item '%1' not found in tree", item)
  Builtins.y2debug("Tree was '%1'", allItems)
  false
end

- (Object) setTree(newTree)

Set tree widget to tree represented by newTree

Parameters:

  • newTree (Array<Yast::Term>)

    tree to display.



24
25
26
27
28
29
# File '../../src/include/autoinstall/tree.rb', line 24

def setTree(newTree)
  newTree = deep_copy(newTree)
  UI.ChangeWidget(@iTree, :Items, newTree)

  nil
end

- (Object) termContains(t, s)

Searches through term t recursively looking for an arg of type string which is equal to s. This function is neccessary due to the nature trees are stored/represented in the tree widget.

Parameters:

  • t (Yast::Term)

    The term to inspect.

  • s (Symbol)

    The symbol to look for.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File '../../src/include/autoinstall/tree.rb', line 45

def termContains(t, s)
  t = deep_copy(t)
  # if term itself is named like s -> yes, contains
  return true if s == Builtins.symbolof(t)
  # other wise inspect arguments
  args = Builtins.argsof(t)
  found = false
  Builtins.foreach(args) do |e|
    if Ops.is_term?(e)
      found = termContains(Convert.to_term(e), s)
      raise Break if found
    elsif Ops.is(e, "list <term>")
      found = isContainedInTree(
        s,
        Convert.convert(e, :from => "any", :to => "list <term>")
      )
      raise Break if found
    elsif Ops.is_symbol?(e) && s == Convert.to_symbol(e)
      found = true
      raise Break
    end
  end
  found
end