Class: Yast::ValueBrowserClass

Inherits:
Module
  • Object
show all
Defined in:
library/general/src/modules/ValueBrowser.rb

Instance Method Summary collapse

Instance Method Details

#BrowseTree(variable) ⇒ Object

Shows tree with contents of variable.

Examples:

map a = $[
   "first" : 35,
   "second" : [ 1, 2, 3, 4, 5],
   "third" : $[ "a" : 15, `b: `VBox () ]
  ];
ValueBrowser::BrowseTree (a);

Parameters:

  • variable (Object)

    variable to show.



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'library/general/src/modules/ValueBrowser.rb', line 145

def BrowseTree(variable)
  variable = deep_copy(variable)
  items = BrowseTreeHelper(variable, "")
  UI.OpenDialog(
    Opt(:defaultsize),
    VBox(
      # translators: Tree header
      Tree(Opt(:hstretch, :vstretch), _("&Variable"), [items]),
      ButtonBox(
        PushButton(Id(:ok), Opt(:okButton, :key_F10), Label.OKButton)
      )
    )
  )
  UI.UserInput
  UI.CloseDialog

  nil
end

#BrowseTreeHelper(variable, indent) ⇒ Object

Creates tree with contents of variable. This function creates the tree items and returns them as term. This offers using the generated output in your behavior, such as data-structure browser with editor. Heavy recursion…

Parameters:

  • variable (Object)

    variable to show.

  • indent (String)

    string that is printed before each output.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'library/general/src/modules/ValueBrowser.rb', line 92

def BrowseTreeHelper(variable, indent)
  variable = deep_copy(variable)
  simple = FormatSimpleType(variable, indent)

  return Item(simple) unless simple.nil?

  if Ops.is_list?(variable)
    items = []
    Builtins.foreach(Convert.to_list(variable)) do |i|
      items = Builtins.add(items, BrowseTreeHelper(i, ""))
    end
    return Item(Builtins.sformat("%1 (list)", indent), items)
  elsif Ops.is_map?(variable)
    items = []
    Builtins.foreach(Convert.to_map(variable)) do |k, v|
      items = Builtins.add(
        items,
        BrowseTreeHelper(v, Builtins.sformat("%1: ", k))
      )
    end
    return Item(Builtins.sformat("%1 (map)", indent), items)
  elsif Ops.is_term?(variable)
    tvariable = Convert.to_term(variable)
    items = []
    len = Builtins.size(tvariable)
    i = 0
    while Ops.less_than(i, len)
      items = Builtins.add(
        items,
        BrowseTreeHelper(Ops.get(tvariable, i), "")
      )
      i = Ops.add(i, 1)
    end
    return Item(
      Builtins.sformat("%1%2 (term)", indent, Builtins.symbolof(tvariable)),
      items
    )
  end

  nil
end

#DebugBrowse(variable) ⇒ Object

Write contents of variable to log file.

Parameters:

  • variable (Object)

    variable to show.



202
203
204
205
206
207
# File 'library/general/src/modules/ValueBrowser.rb', line 202

def DebugBrowse(variable)
  variable = deep_copy(variable)
  DebugBrowseHelper(variable, "")

  nil
end

#DebugBrowseHelper(variable, indent) ⇒ Object

Write contents of variable to log file. This function does the job. Heavy recursion…

Parameters:

  • variable (Object)

    variable to show.

  • indent (String)

    string that is printed before each output.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'library/general/src/modules/ValueBrowser.rb', line 168

def DebugBrowseHelper(variable, indent)
  variable = deep_copy(variable)
  simple = FormatSimpleType(variable, indent)
  if !simple.nil?
    Builtins.y2debug("%1", simple)
  elsif Ops.is_list?(variable)
    Builtins.foreach(Convert.to_list(variable)) do |i|
      DebugBrowseHelper(i, Ops.add(indent, "  "))
    end
  elsif Ops.is_map?(variable)
    Builtins.foreach(Convert.to_map(variable)) do |k, v|
      Builtins.y2debug("%2%1 (map key)", k, indent)
      DebugBrowseHelper(v, Builtins.sformat("  %1", indent))
    end
  elsif Ops.is_term?(variable)
    tvariable = Convert.to_term(variable)
    items = []
    len = Builtins.size(tvariable)
    i = 0
    Builtins.y2debug("%1%2 (term)", indent, Builtins.symbolof(tvariable))
    while Ops.less_than(i, len)
      items = Builtins.add(
        items,
        DebugBrowseHelper(Ops.get(tvariable, i), "")
      )
      i = Ops.add(i, 1)
    end
  end

  nil
end

#escapestring(s) ⇒ String

Helper function that replaces all ocurences of “n” with “\n”, so items are not multiline :-)

Parameters:

  • s (String)

    string to escape

Returns:



47
48
49
# File 'library/general/src/modules/ValueBrowser.rb', line 47

def escapestring(s)
  Builtins.mergestring(Builtins.splitstring(s, "\n"), "\\n")
end

#FormatSimpleType(variable, indent) ⇒ Object

Shows tree with contents of variable. This function does the job. Heavy recursion…

Parameters:

  • variable (Object)

    variable to show.

  • indent (String)

    string that is printed before each output.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'library/general/src/modules/ValueBrowser.rb', line 54

def FormatSimpleType(variable, indent)
  variable = deep_copy(variable)
  if Ops.is_void?(variable)
    Builtins.sformat("%2%1 (void)", variable, indent)
  elsif Ops.is_boolean?(variable)
    Builtins.sformat("%2%1 (boolean)", variable, indent)
  elsif Ops.is_integer?(variable)
    Builtins.sformat(
      "%2%1, %3 (integer)",
      variable,
      indent,
      Builtins.tohexstring(Convert.to_integer(variable))
    )
  elsif Ops.is_float?(variable)
    Builtins.sformat("%2%1 (float)", variable, indent)
  elsif Ops.is_string?(variable)
    return Builtins.sformat(
      "%2%1 (string)",
      escapestring(Convert.to_string(variable)),
      indent
    )
  elsif Ops.is_locale?(variable)
    Builtins.sformat("%2%1 (locale)", variable, indent)
  elsif Ops.is_byteblock?(variable)
    Builtins.sformat("%2%1 (byteblock)", variable, indent)
  elsif Ops.is_symbol?(variable)
    Builtins.sformat("%2%1 (symbol)", variable, indent)
  elsif Ops.is_path?(variable)
    Builtins.sformat("%2%1 (path)", variable, indent)
  end
end

#mainObject



36
37
38
39
40
41
42
# File 'library/general/src/modules/ValueBrowser.rb', line 36

def main
  Yast.import "UI"

  textdomain "base"

  Yast.import "Label"
end