Class: Yast::CWMTabClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/CWMTab.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) CleanUp(key)

Clean up function of the widget

Parameters:

  • key (String)

    the widget key (ignored)



235
236
237
238
239
240
241
# File '../../src/modules/CWMTab.rb', line 235

def CleanUp(key)
  TabCleanup(@current_tab_map)
  @last_tab_id = @current_tab_id
  Pop()

  nil
end

- (Hash) CreateWidget(settings)

Get the widget description map

Parameters:

  • tab_order

    a list of the IDs of the tabs

  • tabs

    a map of all tabs (key is tab ID, value is a map describing the tab

  • initial_tab

    string the tab tha will be displayed as the first

  • widget_descr

    description map of all widgets that are present in any of the tabs

  • tab_help

    strign general help to the tab widget

Returns:

  • (Hash)

    the widget description map



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File '../../src/modules/CWMTab.rb', line 337

def CreateWidget(settings)
  settings = deep_copy(settings)
  tab_order = Ops.get_list(settings, "tab_order", [])
  tabs = Ops.get_map(settings, "tabs", {})
  initial_tab = Ops.get_string(settings, "initial_tab", "")
  widget_descr = Ops.get_map(settings, "widget_descr", {})
  tab_help = Ops.get_string(settings, "tab_help", "")

  widget = nil
  rp = ReplacePoint(Id(:_cwm_tab_contents_rp), @empty_tab)

  # widget
  if UI.HasSpecialWidget(:DumbTab)
    panes = Builtins.maplist(tab_order) do |t|
      label = Ops.get_string(tabs, [t, "header"], @default_tab_header)
      Item(Id(t), label, t == initial_tab)
    end
    widget = DumbTab(Id(:_cwm_tab), panes, rp)
  else
    tabbar = HBox()
    Builtins.foreach(tab_order) do |t|
      label = Ops.get_string(tabs, [t, "header"], @default_tab_header)
      tabbar = Builtins.add(tabbar, PushButton(Id(t), label))
    end
    widget = VBox(Left(tabbar), Frame("", rp))
  end

  tabs = Builtins.mapmap(tabs) do |k, v|
    contents = Ops.get_term(v, "contents", VBox())
    widget_names = Convert.convert(
      Ops.get(v, "widget_names") { CWM.StringsOfTerm(contents) },
      :from => "any",
      :to   => "list <string>"
    )
    # second arg wins
    fallback = Builtins.union(
      Ops.get_map(settings, "fallback_functions", {}),
      Ops.get_map(v, "fallback_functions", {})
    )
    w = CWM.CreateWidgets(widget_names, widget_descr)
    w = CWM.mergeFunctions(w, fallback)
    help = CWM.MergeHelps(w)
    contents = CWM.PrepareDialog(contents, w)
    Ops.set(v, "widgets", w)
    Ops.set(v, "help", help)
    Ops.set(v, "contents", contents)
    { k => v }
  end

  {
    "widget"            => :custom,
    "custom_widget"     => widget,
    "init"              => fun_ref(method(:InitWrapper), "void (string)"),
    "store"             => fun_ref(method(:Store), "void (string, map)"),
    "clean_up"          => fun_ref(method(:CleanUp), "void (string)"),
    "handle"            => fun_ref(
      method(:HandleWrapper),
      "symbol (string, map)"
    ),
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:Validate),
      "boolean (string, map)"
    ),
    "initial_tab"       => initial_tab,
    "tabs"              => tabs,
    "tabs_list"         => tab_order,
    "tab_help"          => tab_help,
    "no_help"           => true
  }
end

- (String) CurrentTab

Get the ID of the currently displayed tab

Returns:

  • (String)

    the ID of the currently displayed tab



291
292
293
# File '../../src/modules/CWMTab.rb', line 291

def CurrentTab
  @current_tab_id
end

- (Symbol) Handle(widget, key, event)

Handle function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key

  • event (Hash)

    map event to be handled

Returns:

  • (Symbol)

    for wizard sequencer or nil



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File '../../src/modules/CWMTab.rb', line 248

def Handle(widget, key, event)
  widget = deep_copy(widget)
  event = deep_copy(event)
  all_tabs = Ops.get_list(widget, "tabs_list", [])
  h_ret = TabHandle(@current_tab_map, event)
  return h_ret if h_ret != nil
  ret = Ops.get(event, "ID")
  if Ops.is_string?(ret) &&
      Builtins.contains(all_tabs, Convert.to_string(ret)) &&
      # At initialization, qt thinks it has switched to the same tab
      # So prevent unnecessary double initialization
      ret != @current_tab_id
    if !TabValidate(@current_tab_map, event)
      MarkCurrentTab()
      return nil
    end
    TabStore(@current_tab_map, event)

    InitNewTab(Convert.to_string(ret), widget)
  end
  nil
end

- (Object) handleDebug

A hook to handle Alt-Ctrl-Shift-D



303
304
305
306
307
# File '../../src/modules/CWMTab.rb', line 303

def handleDebug
  Builtins.y2debug("Handling a debugging event")

  nil
end

- (Symbol) HandleWrapper(key, event)

Handle function of the widget

Parameters:

  • map

    widget a widget description map

  • key (String)

    strnig the widget key

  • event (Hash)

    map event to be handled

Returns:

  • (Symbol)

    for wizard sequencer or nil



314
315
316
317
318
# File '../../src/modules/CWMTab.rb', line 314

def HandleWrapper(key, event)
  event = deep_copy(event)
  handleDebug if Ops.get_string(event, "EventType", "") == "DebugEvent"
  Handle(CWM.GetProcessedWidget, key, event)
end

- (Object) Init(widget, key)

Init function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key



225
226
227
228
229
230
231
# File '../../src/modules/CWMTab.rb', line 225

def Init(widget, key)
  widget = deep_copy(widget)
  Push()
  InitNewTab(Ops.get_string(widget, "initial_tab", ""), widget)

  nil
end

- (Object) InitNewTab(new_tab_id, widget)

Switch to a new tab

Parameters:

  • new_tab_it

    id of the new tab

  • widget (Hash{String => Object})

    tab set description



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File '../../src/modules/CWMTab.rb', line 203

def InitNewTab(new_tab_id, widget)
  widget = deep_copy(widget)
  @previous_tab_id = @current_tab_id
  @previous_tab_map = deep_copy(@current_tab_map)
  @current_tab_id = new_tab_id
  @current_tab_map = Ops.get_map(widget, ["tabs", @current_tab_id], {})
  MarkCurrentTab()
  RedrawTab(@current_tab_map)
  RedrawHelp(widget, @current_tab_map)
  TabInit(@current_tab_map)
  # allow a handler to enabled/disable widgets before the first real
  # UserInput takes place
  UI.FakeUserInput({ "ID" => "_cwm_tab_wakeup" })

  nil
end

- (Object) InitWrapper(key)

Init function of the widget

Parameters:

  • key (String)

    strnig the widget key



283
284
285
286
287
# File '../../src/modules/CWMTab.rb', line 283

def InitWrapper(key)
  Init(CWM.GetProcessedWidget, key)

  nil
end

- (String) LastTab

Get the ID of the last displayed tab (after CWM::Run is done). It is needed because of bnc#134386.

Returns:

  • (String)

    the ID of the last displayed tab



298
299
300
# File '../../src/modules/CWMTab.rb', line 298

def LastTab
  @last_tab_id
end

- (Object) main



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File '../../src/modules/CWMTab.rb', line 35

def main
  Yast.import "UI"
  textdomain "base"

  Yast.import "CWM"
  Yast.import "Wizard"


  # local constants

  # Empty tab (just to be used as fallback constant)
  @empty_tab = VBox(VStretch(), HStretch())

  # Fallback label for a tab if no is defined
  @default_tab_header = _("Tab")

  # local variables - remember to add them to Push+Pop

  # ID of the currently displayed tab
  @current_tab_id = nil

  # ID of previously selected tab
  @previous_tab_id = nil

  # description map of the currently selected tab
  @current_tab_map = {}

  # description map of the currently selected tab
  @previous_tab_map = {}

  # this one is expressly excluded from Push+Pop
  @last_tab_id = nil

  # nesting stack, needed because of bnc#406138
  @stack = []
end

- (Object) MarkCurrentTab

Make the currently selected tab be displayed a separate way



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File '../../src/modules/CWMTab.rb', line 176

def MarkCurrentTab
  if UI.HasSpecialWidget(:DumbTab)
    UI.ChangeWidget(Id(:_cwm_tab), :CurrentItem, @current_tab_id)
  else
    if @previous_tab_id != nil
      UI.ChangeWidget(
        Id(@previous_tab_id),
        :Label,
        Ops.get_string(@previous_tab_map, "header", @default_tab_header)
      )
    end
    UI.ChangeWidget(
      Id(@current_tab_id),
      :Label,
      Ops.add(
        Ops.add(UI.Glyph(:BulletArrowRight), "  "),
        Ops.get_string(@current_tab_map, "header", @default_tab_header)
      )
    )
  end

  nil
end

- (Object) Pop



84
85
86
87
88
89
90
91
92
93
94
# File '../../src/modules/CWMTab.rb', line 84

def Pop
  tos = Ops.get(@stack, 0, {})
  @current_tab_id = Ops.get_string(tos, "cti", "")
  @previous_tab_id = Ops.get_string(tos, "pti", "")
  @current_tab_map = Ops.get_map(tos, "ctm", {})
  @previous_tab_map = Ops.get_map(tos, "ptm", {})
  Ops.set(@stack, 0, nil)
  @stack = Builtins.filter(@stack) { |m| m != nil }

  nil
end

- (Object) Push



72
73
74
75
76
77
78
79
80
81
82
# File '../../src/modules/CWMTab.rb', line 72

def Push
  tos = {
    "cti" => @current_tab_id,
    "pti" => @previous_tab_id,
    "ctm" => @current_tab_map,
    "ptm" => @previous_tab_map
  }
  @stack = Builtins.prepend(@stack, tos)

  nil
end

- (Object) RedrawHelp(widget, tab)

Redraw the part of the help related to the tab widget

Parameters:

  • widget (Hash{String => Object})

    a map of the tab widget

  • tab (Hash{String => Object})

    a map describing the tab



163
164
165
166
167
168
169
170
171
172
173
# File '../../src/modules/CWMTab.rb', line 163

def RedrawHelp(widget, tab)
  widget = deep_copy(widget)
  tab = deep_copy(tab)
  help = Ops.add(
    Ops.get_string(widget, "tab_help", ""),
    Ops.get_string(tab, "help", "")
  )
  CWM.ReplaceWidgetHelp(Ops.get_string(widget, "_cwm_key", ""), help)

  nil
end

- (Object) RedrawTab(tab)

Redraw the whole tab

Parameters:

  • tab (Hash{String => Object})

    a map describing the tab



152
153
154
155
156
157
158
# File '../../src/modules/CWMTab.rb', line 152

def RedrawTab(tab)
  tab = deep_copy(tab)
  contents = Ops.get_term(tab, "contents", @empty_tab)
  UI.ReplaceWidget(:_cwm_tab_contents_rp, contents)

  nil
end

- (Object) Store(key, event)

Store function of the widget

Parameters:

  • key (String)

    strnig the widget key

  • event (Hash)

    map that caused widget data storing



274
275
276
277
278
279
# File '../../src/modules/CWMTab.rb', line 274

def Store(key, event)
  event = deep_copy(event)
  TabStore(@current_tab_map, event)

  nil
end

- (Object) TabCleanup(tab)

Clean up the widgets in the tab

Parameters:

  • tab (Hash{String => Object})

    a map describing the tab



110
111
112
113
114
115
116
# File '../../src/modules/CWMTab.rb', line 110

def TabCleanup(tab)
  tab = deep_copy(tab)
  widgets = Ops.get_list(tab, "widgets", [])
  CWM.cleanupWidgets(widgets)

  nil
end

- (Symbol) TabHandle(tab, event)

Handle events on the widgets inside the tab

Parameters:

  • tab (Hash{String => Object})

    a map describing the tab

  • event (Hash)

    map event that caused the event handling

Returns:

  • (Symbol)

    for wizard sequencer or nil



122
123
124
125
126
127
# File '../../src/modules/CWMTab.rb', line 122

def TabHandle(tab, event)
  tab = deep_copy(tab)
  event = deep_copy(event)
  widgets = Ops.get_list(tab, "widgets", [])
  CWM.handleWidgets(widgets, event)
end

- (Object) TabInit(tab)

Initialize the widgets in the tab

Parameters:

  • tab (Hash{String => Object})

    a map describing the tab



100
101
102
103
104
105
106
# File '../../src/modules/CWMTab.rb', line 100

def TabInit(tab)
  tab = deep_copy(tab)
  widgets = Ops.get_list(tab, "widgets", [])
  CWM.initWidgets(widgets)

  nil
end

- (Object) TabStore(tab, event)

Store settings of all widgets inside the tab

Parameters:

  • tab (Hash{String => Object})

    a map describing the tab

  • event (Hash)

    map event that caused the saving process



132
133
134
135
136
137
# File '../../src/modules/CWMTab.rb', line 132

def TabStore(tab, event)
  tab = deep_copy(tab)
  event = deep_copy(event)
  widgets = Ops.get_list(tab, "widgets", [])
  CWM.saveWidgets(widgets, event)
end

- (Boolean) TabValidate(tab, event)

Validate settings of all widgets inside the tab

Parameters:

  • tab (Hash{String => Object})

    a map describing the tab

  • event (Hash)

    map event that caused the validation process

Returns:

  • (Boolean)

    true if validation succeeded



143
144
145
146
147
148
# File '../../src/modules/CWMTab.rb', line 143

def TabValidate(tab, event)
  tab = deep_copy(tab)
  event = deep_copy(event)
  widgets = Ops.get_list(tab, "widgets", [])
  CWM.validateWidgets(widgets, event)
end

- (Object) Validate(key, event)

Validate function of the widget

Parameters:

  • key (String)

    strnig the widget key

  • event (Hash)

    map that caused widget data storing



323
324
325
326
# File '../../src/modules/CWMTab.rb', line 323

def Validate(key, event)
  event = deep_copy(event)
  TabValidate(@current_tab_map, event)
end