Class: Yast::DialogTreeClass
- Inherits:
-
Module
- Object
- Module
- Yast::DialogTreeClass
- Defined in:
- library/cwm/src/modules/DialogTree.rb
Instance Method Summary collapse
-
#AdjustButtons(buttons) ⇒ Object
Adjust buttons at the bottom of the dialog.
-
#AdjustButtonsAny(buttons) ⇒ Object
Adjust buttons at the bottom of the dialog.
-
#DialogTreeHandle(_key, event) ⇒ Symbol
Handle function of virtual DialogTree widget.
-
#DialogTreeInit(_key) ⇒ Object
Init function of virtual DialogTree widget.
-
#DrawScreen(current_screen, widget_descr, extra_widget, set_focus) ⇒ Object
Draw the screen related to the particular tree item extra_widget a map of the additional widget to be added at the end of the list of widgets.
-
#GetVirtualDialogTreeWidget(ids) ⇒ Hash
Get the map of the virtal left tree widget.
- #main ⇒ Object
-
#RestoreSelectedDialog ⇒ Object
Restore the previously selected dialog after clicking another item not causing dialog change due to validation failed.
-
#Run(settings) ⇒ Symbol
Generic function to create dialog and handle it's events.
-
#RunAndHide(settings) ⇒ Symbol
Run the event loop over the dialog with the left tree.
-
#ShowAndRun(settings) ⇒ Symbol
Display the dialog and run its event loop
"ids_order" : list
of IDs in the same order as they are expected to be in the left menu. -
#ShowFlat(ids_order, screens) ⇒ Object
Draw the dialog with the flat tree (only single level of the tree entries).
-
#ShowTree(tree_handler) ⇒ Object
Draw the dialog with multi-level tree.
Instance Method Details
#AdjustButtons(buttons) ⇒ Object
Adjust buttons at the bottom of the dialog
180 181 182 183 184 185 186 187 188 189 190 |
# File 'library/cwm/src/modules/DialogTree.rb', line 180 def AdjustButtons() = deep_copy() CWM.AdjustButtons( Ops.get(, "next_button") { Label.NextButton }, Ops.get(, "back_button") { Label.BackButton }, Ops.get(, "abort_button") { Label.AbortButton }, Label.HelpButton ) nil end |
#AdjustButtonsAny(buttons) ⇒ Object
Adjust buttons at the bottom of the dialog
196 197 198 199 200 201 202 203 204 205 206 |
# File 'library/cwm/src/modules/DialogTree.rb', line 196 def AdjustButtonsAny() = deep_copy() = Convert.convert( Builtins.filter() { |k, _v| Builtins.issubstring(k, "_button") }, from: "map <string, any>", to: "map <string, string>" ) AdjustButtons() nil end |
#DialogTreeHandle(_key, event) ⇒ Symbol
Handle function of virtual DialogTree widget
82 83 84 85 86 87 88 89 90 |
# File 'library/cwm/src/modules/DialogTree.rb', line 82 def DialogTreeHandle(_key, event) event = deep_copy(event) ret = Ops.get(event, "ID") ret = Convert.to_string(UI.QueryWidget(Id(:wizardTree), :CurrentItem)) if ret == :wizardTree @previous_screen = @selected_screen @selected_screen = Convert.to_string(ret) :_cwm_internal_tree_handle end |
#DialogTreeInit(_key) ⇒ Object
Init function of virtual DialogTree widget
67 68 69 70 71 72 73 74 75 76 |
# File 'library/cwm/src/modules/DialogTree.rb', line 67 def DialogTreeInit(_key) if UI.WidgetExists(Id(:wizardTree)) UI.ChangeWidget(Id(:wizardTree), :CurrentItem, @selected_screen) UI.SetFocus(Id(:wizardTree)) else UI.WizardCommand(term(:SelectTreeItem, @selected_screen)) end nil end |
#DrawScreen(current_screen, widget_descr, extra_widget, set_focus) ⇒ Object
Draw the screen related to the particular tree item extra_widget a map of the additional widget to be added at the end of the list of widgets
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'library/cwm/src/modules/DialogTree.rb', line 118 def DrawScreen(current_screen, , , set_focus) current_screen = deep_copy(current_screen) = deep_copy() = deep_copy() = Ops.get_list(current_screen, "widget_names", []) contents = Ops.get_term(current_screen, "contents", VBox()) = Ops.get_string(current_screen, "caption", "") w = CWM.CreateWidgets(, ) help = CWM.MergeHelps(w) contents = CWM.PrepareDialog(contents, w) Wizard.SetContentsFocus(, contents, help, true, true, set_focus) # add virtual widget w = Builtins.add(w, ) # return widgets of the dialog for further usage deep_copy(w) end |
#GetVirtualDialogTreeWidget(ids) ⇒ Hash
Get the map of the virtal left tree widget
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'library/cwm/src/modules/DialogTree.rb', line 95 def GetVirtualDialogTreeWidget(ids) ids = deep_copy(ids) handle_events = deep_copy(ids) handle_events = Builtins.add(handle_events, :wizardTree) { "init" => fun_ref(method(:DialogTreeInit), "void (string)"), "handle_events" => handle_events, "handle" => fun_ref( method(:DialogTreeHandle), "symbol (string, map)" ) } end |
#main ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'library/cwm/src/modules/DialogTree.rb', line 33 def main Yast.import "UI" textdomain "base" Yast.import "CWM" Yast.import "Label" Yast.import "Wizard" # local data # Currently selected item in the tree @selected_screen = nil # Previously selected item in the tree @previous_screen = nil end |
#RestoreSelectedDialog ⇒ Object
Restore the previously selected dialog after clicking another item not causing dialog change due to validation failed
52 53 54 55 56 57 58 59 60 61 |
# File 'library/cwm/src/modules/DialogTree.rb', line 52 def RestoreSelectedDialog @selected_screen = @previous_screen if UI.WidgetExists(Id(:wizardTree)) UI.ChangeWidget(Id(:wizardTree), :CurrentItem, @selected_screen) else UI.WizardCommand(term(:SelectTreeItem, @selected_screen)) end nil end |
#Run(settings) ⇒ Symbol
Generic function to create dialog and handle it's events. Run the event loop over the dialog with the left tree.
"screens" : map<string,map<string,any>> of all screens
(key is screen ID, value is screen description map)
"widget_descr" : map<string,map<string,any>> description map of all widgets
"initial_screen" : string the id of the screen that should be displayed
as the first
"fallback" : map<any,any> initialize/save/handle fallbacks if not specified
with the widgets, to be passed to CWM
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'library/cwm/src/modules/DialogTree.rb', line 221 def Run(settings) settings = deep_copy(settings) screens = Ops.get_map(settings, "screens", {}) = Ops.get_map(settings, "widget_descr", {}) initial_screen = Ops.get_string(settings, "initial_screen", "") functions = Ops.get_map(settings, "functions", {}) initial_screen = "" if initial_screen.nil? if initial_screen == "" Builtins.foreach(screens) do |k, _v| initial_screen = k if initial_screen == "" end end @selected_screen = initial_screen ids = Builtins.maplist(screens) { |k, _v| k } = GetVirtualDialogTreeWidget(ids) w = DrawScreen( Ops.get(screens, @selected_screen, {}), , , true ) ret = nil while ret.nil? CWM.SetValidationFailedHandler( fun_ref(method(:RestoreSelectedDialog), "void ()") ) ret = CWM.Run(w, functions) CWM.SetValidationFailedHandler(nil) # switching scrren, dialog was validated and stored next if ret != :_cwm_internal_tree_handle toEval = Convert.convert( Ops.get(screens, [@selected_screen, "init"]), from: "any", to: "symbol (string)" ) tab_init = nil tab_init = toEval.call(@selected_screen) if !toEval.nil? if tab_init.nil? # everything OK w = DrawScreen( Ops.get(screens, @selected_screen, {}), , , false ) ret = nil elsif tab_init == :refuse_display # do not display this screen @selected_screen = @previous_screen ret = nil # exit dialog else ret = tab_init end end ret end |
#RunAndHide(settings) ⇒ Symbol
Run the event loop over the dialog with the left tree. After finished, run UI::CloseDialog
285 286 287 288 289 290 |
# File 'library/cwm/src/modules/DialogTree.rb', line 285 def RunAndHide(settings) settings = deep_copy(settings) Run(settings) ensure UI.CloseDialog end |
#ShowAndRun(settings) ⇒ Symbol
Display the dialog and run its event loop
"ids_order" : list<string> of IDs in the same order as they are expected
to be in the left menu. Not used if "tree_creator" is defined
"tree_creator" : list<map>() a callback to a function that creates
the tree using Wizard::AddTreeItem and returns the
resulting tree
"back_button" : string label of the back button (optional)
"next_button" : string label of the next button (optional)
"abort_button" : string label of the abort button (optional)
See @RunAndHide for other possible keys in the map
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'library/cwm/src/modules/DialogTree.rb', line 306 def ShowAndRun(settings) settings = deep_copy(settings) ids_order = Ops.get_list(settings, "ids_order", []) screens = Ops.get_map(settings, "screens", {}) tree_handler = Convert.convert( Ops.get(settings, "tree_creator"), from: "any", to: "list <map> ()" ) if tree_handler.nil? ShowFlat(ids_order, screens) if Ops.get_string(settings, "initial_screen", "") == "" Builtins.find(ids_order) do |s| Ops.set(settings, "initial_screen", s) true end end else ShowTree(tree_handler) end AdjustButtonsAny(settings) RunAndHide(settings) end |
#ShowFlat(ids_order, screens) ⇒ Object
Draw the dialog with the flat tree (only single level of the tree entries)
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'library/cwm/src/modules/DialogTree.rb', line 143 def ShowFlat(ids_order, screens) ids_order = deep_copy(ids_order) screens = deep_copy(screens) Wizard.OpenTreeNextBackDialog tree = [] Builtins.foreach(ids_order) do |i| tree = Wizard.AddTreeItem( tree, "", Ops.get_string( screens, [i, "tree_item_label"], Ops.get_string(screens, [i, "caption"], "") ), i ) end Wizard.CreateTree(tree, "") nil end |
#ShowTree(tree_handler) ⇒ Object
Draw the dialog with multi-level tree
168 169 170 171 172 173 174 175 |
# File 'library/cwm/src/modules/DialogTree.rb', line 168 def ShowTree(tree_handler) tree_handler = deep_copy(tree_handler) Wizard.OpenTreeNextBackDialog tree = tree_handler.call Wizard.CreateTree(tree, "") nil end |