Class: Yast::DialogTreeClass
- Inherits:
-
Module
- Object
- Module
- Yast::DialogTreeClass
- Defined in:
- ../../src/modules/DialogTree.rb
Instance Method Summary (collapse)
-
- (Object) AdjustButtons(buttons)
Adjust buttons at the bottom of the dialog.
-
- (Object) AdjustButtonsAny(buttons)
Adjust buttons at the bottom of the dialog.
-
- (Symbol) DialogTreeHandle(key, event)
Handle function of virtual DialogTree widget.
-
- (Object) DialogTreeInit(key)
Init function of virtual DialogTree widget.
-
- (Object) DrawScreen(current_screen, widget_descr, extra_widget, set_focus)
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.
-
- (Hash) GetVirtualDialogTreeWidget(ids)
Get the map of the virtal left tree widget.
- - (Object) main
-
- (Object) RestoreSelectedDialog
Restore the previously selected dialog after clicking another item not causing dialog change due to validation failed.
-
- (Symbol) Run(settings)
Generic function to create dialog and handle it's events.
-
- (Symbol) RunAndHide(settings)
Run the event loop over the dialog with the left tree.
-
- (Symbol) ShowAndRun(settings)
Display the dialog and run its event loop.
-
- (Object) ShowFlat(ids_order, screens)
Draw the dialog with the flat tree (only single level of the tree entries).
-
- (Object) ShowTree(tree_handler)
Draw the dialog with multi-level tree.
Instance Method Details
- (Object) AdjustButtons(buttons)
Adjust buttons at the bottom of the dialog
190 191 192 193 194 195 196 197 198 199 200 |
# File '../../src/modules/DialogTree.rb', line 190 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 |
- (Object) AdjustButtonsAny(buttons)
Adjust buttons at the bottom of the dialog
206 207 208 209 210 211 212 213 214 215 216 |
# File '../../src/modules/DialogTree.rb', line 206 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 |
- (Symbol) DialogTreeHandle(key, event)
Handle function of virtual DialogTree widget
85 86 87 88 89 90 91 92 93 94 95 |
# File '../../src/modules/DialogTree.rb', line 85 def DialogTreeHandle(key, event) event = deep_copy(event) ret = Ops.get(event, "ID") if ret == :wizardTree ret = Convert.to_string(UI.QueryWidget(Id(:wizardTree), :CurrentItem)) end @previous_screen = @selected_screen @selected_screen = Convert.to_string(ret) :_cwm_internal_tree_handle end |
- (Object) DialogTreeInit(key)
Init function of virtual DialogTree widget
70 71 72 73 74 75 76 77 78 79 |
# File '../../src/modules/DialogTree.rb', line 70 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 |
- (Object) DrawScreen(current_screen, widget_descr, extra_widget, set_focus)
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
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File '../../src/modules/DialogTree.rb', line 125 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()) caption = Ops.get_string(current_screen, "caption", "") w = CWM.CreateWidgets(, ) help = CWM.MergeHelps(w) contents = CWM.PrepareDialog(contents, w) Wizard.SetContentsFocus(caption, 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 |
- (Hash) GetVirtualDialogTreeWidget(ids)
Get the map of the virtal left tree widget
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File '../../src/modules/DialogTree.rb', line 100 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 |
- (Object) main
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File '../../src/modules/DialogTree.rb', line 35 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 |
- (Object) RestoreSelectedDialog
Restore the previously selected dialog after clicking another item not causing dialog change due to validation failed
55 56 57 58 59 60 61 62 63 64 |
# File '../../src/modules/DialogTree.rb', line 55 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 |
- (Symbol) Run(settings)
Generic function to create dialog and handle it's events. Run the event loop over the dialog with the left tree. <pre> "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 </pre>
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 280 281 282 283 284 285 286 287 |
# File '../../src/modules/DialogTree.rb', line 231 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 Builtins.foreach(screens) do |k, v| initial_screen = k if initial_screen == "" end if initial_screen == "" @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 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 end ret end |
- (Symbol) RunAndHide(settings)
Run the event loop over the dialog with the left tree. After finished, run UI::CloseDialog
293 294 295 296 297 298 |
# File '../../src/modules/DialogTree.rb', line 293 def RunAndHide(settings) settings = deep_copy(settings) ret = Run(settings) UI.CloseDialog ret end |
- (Symbol) ShowAndRun(settings)
Display the dialog and run its event loop <pre> "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 </pre>
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File '../../src/modules/DialogTree.rb', line 314 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 ShowTree(tree_handler) else 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 end AdjustButtonsAny(settings) RunAndHide(settings) end |
- (Object) ShowFlat(ids_order, screens)
Draw the dialog with the flat tree (only single level of the tree entries)
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File '../../src/modules/DialogTree.rb', line 153 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 |
- (Object) ShowTree(tree_handler)
Draw the dialog with multi-level tree
178 179 180 181 182 183 184 185 |
# File '../../src/modules/DialogTree.rb', line 178 def ShowTree(tree_handler) tree_handler = deep_copy(tree_handler) Wizard.OpenTreeNextBackDialog tree = tree_handler.call Wizard.CreateTree(tree, "") nil end |