Revision 3677

Date:
2019-09-18 02:28:35
Author:
dsb
Revision Log:
Consolidate identical automatizer dialog methods into new utility method
ui_util.selDropdownByField().
Files:

Legend:

 
Added
 
Removed
 
Modified
  • tome2/trunk/dialogs/AutomatizerMakeClause.lua

     
    305 305 if orig_clause then
    306 306 if init_sel == 3 then
    307 307 if orig_clause.test ~= 'placeholder' then
    308 self:selDropdownByField('dd_simple', 'test', orig_clause.test)
    308 ui_util.selDropdownByField(self.dd_simple, 'test', orig_clause.test)
    309 309 if simple_by_test[orig_clause.test].has_arg then
    310 310 self.tb_simple_arg:setText(orig_clause[1])
    311 311 end
     
    313 313 end
    314 314 if init_sel == 4 then
    315 315 local val_sel = values_by_name[orig_clause[1].clause]
    316 self:selDropdownByField('dd_value', 'value', orig_clause[1].clause)
    317 self:selDropdownByField('dd_op', 'op', orig_clause.test)
    316 ui_util.selDropdownByField(self.dd_value, 'value', orig_clause[1].clause)
    317 ui_util.selDropdownByField(self.dd_op, 'op', orig_clause.test)
    318 318 if val_sel.has_arg then
    319 319 self.tb_value_arg:setText(orig_clause[1][1])
    320 320 end
     
    328 328 for i = 2, #orig_clause do self.oneof_list[i-1] = orig_clause[i] end
    329 329 self:updateOneOfDesc()
    330 330 elseif val_sel.grp_only then
    331 self:selDropdownByField('dd_grpsel', 'value', orig_clause[2])
    331 ui_util.selDropdownByField(self.dd_grpsel, 'value', orig_clause[2])
    332 332 elseif val_sel.group then
    333 333 self.tb_target_g:setText(orig_clause[2])
    334 334 elseif val_sel.valtype == 'number' then
     
    392 392 return self[tag].c_list.list[self[tag].c_list.sel]
    393 393 end
    394 394
    395 function _M:selDropdownByField(tag, k, v)
    396 local c_list = self[tag].c_list
    397 for i, item in ipairs(c_list.list) do
    398 if item[k] == v then
    399 c_list.sel = i
    400 if self[tag].fct then self[tag].fct(item) end
    401 break
    402 end
    403 end
    404 end
    405
    406 395 function _M:selectSimple(item, no_select)
    407 396 if not item then return end
    408 397 self:toggleDisplay(self.tb_simple_arg, item.has_arg)
  • tome2/trunk/dialogs/AutomatizerRules.lua

     
    236 236 self:setTestObject(nil)
    237 237 end
    238 238
    239 function _M:selDropdownByField(tag, k, v)
    240 local c_list = self[tag].c_list
    241 for i, item in ipairs(c_list.list) do
    242 if item[k] == v then
    243 c_list.sel = i
    244 if self[tag].fct then self[tag].fct(item) end
    245 break
    246 end
    247 end
    248 end
    249
    250 239 function _M:closeDialog()
    251 240 local ch = self:changeCount()
    252 241 if not ch then
     
    313 302 self:toggleDisplay(self.c_delete_rule, can_delete)
    314 303 self:updateRevertButton()
    315 304 if rule then
    316 self:selDropdownByField('c_action', 'action', rule.action)
    305 ui_util.selDropdownByField(self.c_action, 'action', rule.action)
    317 306 self.c_rule_name:setText(rule.name)
    318 307 self.c_global.checked = rule.global
    319 308 self:populateCardsFromRule(rule)
  • tome2/trunk/ui-util.lua

     
    24 24
    25 25 ui_util = {}
    26 26
    27 -- Change the selection of the provided Dropdown to the item in its list in
    28 -- which the specified field has the specified value.
    29 function ui_util.selDropdownByField(dd, k, v)
    30 for i, item in ipairs(dd.c_list.list) do
    31 if item[k] == v then
    32 dd.c_list.sel = i
    33 if dd.fct then dd.fct(item) end
    34 break
    35 end
    36 end
    37 end
    38
    27 39 -- A modified version of Dialog:listPopup() that computes its own height.
    28 40 -- It retains the original's usability with ActorTalents:talentDialog(), in
    29 41 -- particular assuming that the provided 'fct' method will be calling