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_contents, #cwm_definition, #find_ids, #ids_in_contents

Methods inherited from AbstractWidget

#cwm_definition, #disable, #displayed?, #enable, #enabled?, #focus, #fun_ref, #label, #my_event?, #opt, #refresh_help, widget_type=

Constructor Details

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

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

Parameters:

  • id (Object) (defaults to: "_placeholder")

    id of widget. Needed to redefine only if more than one

  • widget (CWM::AbstractWidget)

    initial widget in placeholder



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

def initialize(widget:, id: "_placeholder")
  super()

  self.handle_all_events = true
  self.widget_id = id
  @widget = widget
end

Instance Method Details

#cleanupObject

Passes to replace point content



73
74
75
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 73

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

#contentsUITerm

Returns:



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

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



53
54
55
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 53

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

#helpObject

Dynamic help, that compute help of current displayed widgets



58
59
60
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 58

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

#initObject

switches to initial widget



33
34
35
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 33

def init
  replace(@widget)
end

#replace(widget) ⇒ Object

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

Parameters:



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

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



68
69
70
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 68

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

#validateObject

Passes to replace point content



63
64
65
# File 'library/cwm/src/lib/cwm/replace_point.rb', line 63

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