Module: Yast::MailWjInclude
- Defined in:
- ../../src/include/mail/wj.rb
Instance Method Summary (collapse)
-
- (Object) EditTable(action, data, keys, editEntryP, table_widget)
A generic handler for editing tables.
-
- (Object) evaluate_fp(fp)
Evaluate a function pointer, working around interpreter limitations.
- - (Object) initialize_mail_wj(include_target)
-
- (Object) makeItems(data, keys)
An item list.
-
- (Object) RadioButtonVBox(g_id, rbs)
Make a RadioButtonGroup containing Left aligned widgets in a VBox that has VSpacing (0.2) as top/bottom padding.
-
- (Object) WJ_GetWidget(id)
Changes widget value using “get” (useful for widgets with choices).
-
- (Object) WJ_MakeHelp(items)
Make a help string by concatenating individual widget helps and other strings.
-
- (Object) WJ_MakeWidget(id)
Constructs a widget term.
-
- (Object) WJ_Set(widgets)
Call the “set” functions for a list of widgets to commit the UI values to a module.
-
- (Object) WJ_Set_Missing(id)
Set a variable acording to widget value This is an error reporting fallback if the real function was not defined.
-
- (Object) WJ_Validate(widgets)
Call the validation functions for a list of widgets.
-
- (Object) WJ_Validate_True(id)
A helper for WJ_Validate.
Instance Method Details
- (Object) EditTable(action, data, keys, editEntryP, table_widget)
A generic handler for editing tables. The current item of table_widget makeItems (new_data, keys) is used to fill table_widget
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File '../../src/include/mail/wj.rb', line 66 def EditTable(action, data, keys, editEntryP, ) data = deep_copy(data) keys = deep_copy(keys) editEntryP = deep_copy(editEntryP) = deep_copy() new_data = nil entryno = Convert.to_integer( UI.QueryWidget(Id(), :CurrentItem) ) touched = false editEntry = deep_copy(editEntryP) #FIXME if action == :add entry = editEntry.call({}, data) if Ops.greater_than(Builtins.size(entry), 0) new_data = Builtins.add(data, entry) touched = true else new_data = deep_copy(data) end elsif action == :edit # edit known fields, preserve unknown fields old_entry = Ops.get(data, entryno, {}) entry = editEntry.call(old_entry, Builtins.remove(data, entryno)) if Ops.greater_than(Builtins.size(entry), 0) i = 0 new_data = Builtins.maplist(data) do |e| i = Ops.add(i, 1) Ops.subtract(i, 1) == entryno ? Builtins.union(old_entry, entry) : e end touched = true else new_data = deep_copy(data) end elsif action == :delete new_data = Builtins.remove(data, entryno) touched = true else Builtins.y2error("Unknown EditTable action %1.", action) new_data = deep_copy(data) # be nice end if touched UI.ChangeWidget(Id(), :Items, makeItems(new_data, keys)) @edit_touched = true end deep_copy(new_data) end |
- (Object) evaluate_fp(fp)
Evaluate a function pointer, working around interpreter limitations
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File '../../src/include/mail/wj.rb', line 122 def evaluate_fp(fp) fp = deep_copy(fp) if Ops.is(fp, "boolean ()") boolean_fp = Convert.convert(fp, :from => "any", :to => "boolean ()") return boolean_fp.call end if Ops.is(fp, "list ()") list_fp = Convert.convert(fp, :from => "any", :to => "list ()") return list_fp.call end if Ops.is(fp, "string ()") string_fp = Convert.convert(fp, :from => "any", :to => "string ()") return string_fp.call end if Ops.is(fp, "symbol ()") symbol_fp = Convert.convert(fp, :from => "any", :to => "symbol ()") return symbol_fp.call end # report as the caller Builtins.y2error(1, "evaluate_fp: Unexpected function pointer: %1", fp) nil end |
- (Object) initialize_mail_wj(include_target)
23 24 25 26 27 28 29 30 31 |
# File '../../src/include/mail/wj.rb', line 23 def initialize_mail_wj(include_target) Yast.import "UI" textdomain "mail" # shoudn't be necessary Yast.include include_target, "mail/widgets.rb" @edit_touched = false end |
- (Object) makeItems(data, keys)
Returns an item list
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File '../../src/include/mail/wj.rb', line 38 def makeItems(data, keys) data = deep_copy(data) keys = deep_copy(keys) i = 0 Builtins.maplist(data) do |d| t = Item(Id(i)) i = Ops.add(i, 1) Builtins.foreach(keys) do |k| t = Builtins.add(t, Ops.get_string(d, k, "")) end deep_copy(t) end end |
- (Object) RadioButtonVBox(g_id, rbs)
Make a RadioButtonGroup containing Left aligned widgets in a VBox that has VSpacing (0.2) as top/bottom padding.
308 309 310 311 312 313 314 315 316 317 318 319 |
# File '../../src/include/mail/wj.rb', line 308 def RadioButtonVBox(g_id, rbs) rbs = deep_copy(rbs) spacing = VSpacing(0.2) rb_vbox = VBox(spacing) Builtins.foreach(rbs) do |rb| left_rb = Left(rb) rb_vbox = Builtins.add(rb_vbox, left_rb) end rb_vbox = Builtins.add(rb_vbox, spacing) RadioButtonGroup(Id(g_id), rb_vbox) end |
- (Object) WJ_GetWidget(id)
Changes widget value using “get” (useful for widgets with choices). Uses a global Widgets map. #widget_def
189 190 191 192 193 194 195 |
# File '../../src/include/mail/wj.rb', line 189 def WJ_GetWidget(id) # "get" returns string or boolean: e = evaluate_fp(Ops.get(@Widgets, [id, "get"])) UI.ChangeWidget(Id(id), :Value, e) nil end |
- (Object) WJ_MakeHelp(items)
Make a help string by concatenating individual widget helps and other strings. Uses a global Widgets map. #widget_def
204 205 206 207 208 209 210 211 212 213 214 |
# File '../../src/include/mail/wj.rb', line 204 def WJ_MakeHelp(items) items = deep_copy(items) ret = "" Builtins.foreach(items) do |item| if !Ops.is_string?(item) item = Ops.get_string(@Widgets, [item, "help"], "") end ret = Ops.add(ret, Convert.to_string(item)) end ret end |
- (Object) WJ_MakeWidget(id)
Constructs a widget term. Uses a global Widgets map. Keys are symbols (ids), values are
Structure:
widget_def
`foo: $[
"widget": `TextEntry (),
"opt": `opt (`notify), // optional
"label": "&Foo",
// if there are choices, they are used to construct the widget,
// otherwise get is used
"choices": Choices_foo // list ()
"help": _("<p>Foo!</p>"), // used by WJ_MakeHelp, optional
"get": Get_foo, // gets value from module to widget
"set": Set_foo, // sets value from widget to module
// popups an error and returns false if invalid
"validate": ``(Validate_foo ()),// optional
],
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File '../../src/include/mail/wj.rb', line 167 def WJ_MakeWidget(id) w_def = Ops.get_map(@Widgets, id, {}) = Ops.get_term(w_def, "widget", CheckBox()) return nil if == nil = Builtins.add(, Id(id)) if Builtins.haskey(w_def, "opt") = Builtins.add(, Ops.get_term(w_def, "opt", Empty())) end = Builtins.add(, Ops.get_string(w_def, "label", "LABEL")) # if choices are defined (combo boxes ...), use them # otherwise set the value directly # TODO: verified only for TextEntry. Password, CheckBox, ComboBox # "choices" returns list, "get" returns string, symbol or boolean init = evaluate_fp(Ops.get(w_def, "choices", Ops.get(w_def, "get"))) return Builtins.add(, init) if init != nil deep_copy() end |
- (Object) WJ_Set(widgets)
Call the “set” functions for a list of widgets to commit the UI values to a module. Uses a global Widgets map. #widget_def
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File '../../src/include/mail/wj.rb', line 276 def WJ_Set() = deep_copy() Builtins.foreach() do |id| if Ops.is_symbol?(id) id_sym = Convert.to_symbol(id) set_it = Convert.convert( Ops.get( @Widgets, [id_sym, "set"], fun_ref(method(:WJ_Set_Missing), "void (symbol)") ), :from => "any", :to => "void (symbol)" ) set_it.call(id_sym) end end nil end |
- (Object) WJ_Set_Missing(id)
Set a variable acording to widget value This is an error reporting fallback if the real function was not defined
265 266 267 268 269 270 |
# File '../../src/include/mail/wj.rb', line 265 def WJ_Set_Missing(id) # report as the caller Builtins.y2error(1, "WJ: Missing Set definition for %1", id) nil end |
- (Object) WJ_Validate(widgets)
Call the validation functions for a list of widgets. Widgets with an unspecified function are assumed to be valid. Uses a global Widgets map. #widget_def
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 |
# File '../../src/include/mail/wj.rb', line 228 def WJ_Validate() = deep_copy() ok = true Builtins.foreach() do |id| if ok if Ops.is_symbol?(id) id_sym = Convert.to_symbol(id) w_def = Ops.get_map(@Widgets, id) if w_def == nil # report as the caller Builtins.y2error(1, "WJ: Missing widget definition for %1", id) ok = false else validate = Convert.convert( Ops.get( w_def, "validate", fun_ref(method(:WJ_Validate_True), "boolean (symbol)") ), :from => "any", :to => "boolean (symbol)" ) ok = validate.call(id_sym) end else ok = false end else next #break end end ok end |
- (Object) WJ_Validate_True(id)
A helper for WJ_Validate.
219 220 221 |
# File '../../src/include/mail/wj.rb', line 219 def WJ_Validate_True(id) true end |