Class: CWM::ReplacePoint

Inherits:
CustomWidget show all
Defined in:
library/cwm/src/lib/cwm/replace_point.rb

Overview

Placeholder widget that is used to replace content on demand. The most important method is #replace which allows switching content

Instance Attribute Summary

Attributes inherited from AbstractWidget

#handle_all_events, #widget_id

Instance Method Summary collapse

Methods inherited from CustomWidget

#cwm_definition

Methods inherited from AbstractWidget

#cwm_definition, #disable, #enable, #enabled?, #label, #opt, widget_type=

Constructor Details

#initialize(id: "_placeholder", widget:) ⇒ ReplacePoint

placeholder needed to be in dialog. Parameter type is limited by component system



15
16
17
18
19
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 15

def initialize(id: "_placeholder", widget:)
  self.handle_all_events = true
  self.widget_id = id
  @widget = widget
end

Instance Method Details

#cleanupObject

Passes to replace point content



71
72
73
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 71

def cleanup
  Yast::CWM.cleanupWidgets(@widgets_hash)
end

#contentsUITerm



22
23
24
25
26
27
28
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 22

def contents
  # In `contents` we must use an Empty Term, otherwise CWMClass
  # would see an {AbstractWidget} and handle events itself,
  # which result in double calling of methods like {handle} or {store} for
  # initial widget.
  ReplacePoint(Id(widget_id), Empty(Id("___cwm_rp_empty")))
end

#handle(event) ⇒ Object

Passes to replace point content



51
52
53
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 51

def handle(event)
  Yast::CWM.handleWidgets(@widgets_hash, event)
end

#helpObject

Dynamic help, that compute help of current displayed widgets



56
57
58
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 56

def help
  Yast::CWM.MergeHelps(@widgets_hash)
end

#initObject

switches to initial widget



31
32
33
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 31

def init
  replace(@widget)
end

#replace(widget) ⇒ Object

Replaces content with different widget. All its events are properly handled.



38
39
40
41
42
43
44
45
46
47
48
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 38

def replace(widget)
  widgets = Yast::CWM.widgets_in_contents([widget])
  @widgets_hash = widgets.map { |w| Yast::CWM.prepareWidget(w.cwm_definition) }
  # VBox as CWM ignore top level term and process string inside it,
  # so non-container widgets have problem and its value is processed
  term = Yast::CWM.PrepareDialog(VBox(widget.widget_id), @widgets_hash)
  Yast::UI.ReplaceWidget(Id(widget_id), term)
  Yast::CWM.initWidgets(@widgets_hash)
  @widget = widget
  refresh_help
end

#storeObject

Passes to replace point content



66
67
68
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 66

def store
  Yast::CWM.saveWidgets(@widgets_hash, "ID" => widget_id)
end

#validateObject

Passes to replace point content



61
62
63
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 61

def validate
  Yast::CWM.validateWidgets(@widgets_hash, "ID" => widget_id)
end