Revision 3676

Date:
2019-09-18 02:20:36
Author:
dsb
Revision Log:
Urgh, spectacularly sloppy:
- Update rule config and inscription when we change the corresponding
UI bits.
- Update selected action and card UI bits when we select a rule.
- Clean up any leftover inscription or config{} fields on the way out.
Files:

Legend:

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

     
    115 115 chars = 30,
    116 116 max_len = 99,
    117 117 fct = function() end,
    118 on_change = function(text) self:updateInscription(text) end,
    118 119 }
    119 120
    120 121 self.config_cbs = {
    121 122 ask_destroy = Checkbox.new {
    122 123 title = 'Ask before destroying',
    123 124 default = false,
    125 on_change = function() self:updateConfig() end,
    124 126 },
    125 127 ask_drop = Checkbox.new {
    126 128 title = 'Ask before dropping',
    127 129 default = false,
    130 on_change = function() self:updateConfig() end,
    128 131 },
    129 132 ask_wear = Checkbox.new {
    130 133 title = 'Ask before wearing',
    131 134 default = false,
    135 on_change = function() self:updateConfig() end,
    132 136 },
    133 137 ask_use = Checkbox.new {
    134 138 title = 'Ask before using',
    135 139 default = false,
    140 on_change = function() self:updateConfig() end,
    136 141 },
    137 142 notify_recharge = Checkbox.new {
    138 143 title = 'Notify on recharge',
    139 144 default = false,
    145 on_change = function() self:updateConfig() end,
    140 146 },
    141 147 }
    142 148
     
    230 236 self:setTestObject(nil)
    231 237 end
    232 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
    233 250 function _M:closeDialog()
    234 251 local ch = self:changeCount()
    235 252 if not ch then
     
    264 281 local ret = {}
    265 282 for _, rule in ipairs(rules) do
    266 283 local rr = table.clone(rule, true, {orig_name=true})
    284 if rr.action ~= 'inscribe' then rr.inscription = nil end
    285 if rr.action ~= 'configure' then rr.config = nil end
    267 286 ret[#ret+1] = rr
    268 287 ret[rr.name] = rr
    269 288 end
     
    274 293 self:toggleDisplay(self.c_revert_1, self.cur_rule and self:ruleChanged(self.cur_rule))
    275 294 end
    276 295
    296 function _M:populateCardsFromRule(rule)
    297 if not rule then return end
    298 if rule.action == 'inscribe' then
    299 self.c_inscription:setText(rule.inscription or '')
    300 elseif rule.action == 'configure' then
    301 for _, tag in ipairs(ObjectData.config_types) do
    302 self.config_cbs[tag].checked = rule.config and rule.config[tag] and true or false
    303 end
    304 end
    305 end
    306
    277 307 function _M:setCurrentRule(rule)
    278 308 local show = rule and true or false
    279 309 local can_delete = rule and rule.auto and true or false
     
    282 312 self:toggleDisplay(self.c_test_rule, show)
    283 313 self:toggleDisplay(self.c_delete_rule, can_delete)
    284 314 self:updateRevertButton()
    315 if rule then
    316 self:selDropdownByField('c_action', 'action', rule.action)
    317 self.c_rule_name:setText(rule.name)
    318 self.c_global.checked = rule.global
    319 self:populateCardsFromRule(rule)
    320 end
    285 321 end
    286 322
    287 323 function _M:ruleChanged(rule, ignore_name_change)
     
    425 461 Dialog:yesnoPopup('Automatizer: Revert', text, cb, 'Do not revert', 'Revert', true)
    426 462 end
    427 463
    464 function _M:updateConfig()
    465 if self.cur_rule and self.cur_rule.action == 'configure' then
    466 self.cur_rule.config = self.cur_rule.config or {}
    467 for _, tag in ipairs(ObjectData.config_types) do
    468 self.cur_rule.config[tag] = self.config_cbs[tag].checked
    469 end
    470 end
    471 end
    472
    473 function _M:updateInscription(text)
    474 if self.cur_rule and self.cur_rule.action == 'inscribe' then
    475 self.cur_rule.inscription = text
    476 end
    477 end
    478
    428 479 function _M:selectAction(item)
    429 480 if not item or not item.action then return end
    430 if self.cur_rule then self.cur_rule.action = item.action end
    431 481 self.cards:show_card(item.action, self)
    482 if self.cur_rule then
    483 self.cur_rule.action = item.action
    484 self:populateCardsFromRule(self.cur_rule)
    485 end
    432 486 self:updateRevertButton()
    433 487 end
    434 488
     
    455 509 self.c_rules:select(self.list_idx_by_name[rule_name])
    456 510 end
    457 511 self:setCurrentRule(sel_rule)
    458 self.c_rule_name:setText(self.cur_rule.name)
    459 self.c_global.checked = self.cur_rule.global
    460 512 self:setTestObject(o)
    461 513 self:rebuildRuleTree()
    462 514 end
     
    487 539 match = { test='placeholder' },
    488 540 }
    489 541 if action == 'inscribe' then
    490 rule.inscription = self.c_inscription.text
    542 rule.inscription = self.c_inscription.text or ''
    491 543 end
    492 544 if action == 'configure' then
    493 545 rule.config = {}