widget.common: Allow buttons to be replaced later.

So far, they could only be set in the constructor.
This commit is contained in:
Emmanuel Lepage Vallee 2021-10-13 20:43:16 -07:00
parent 9c042fcb79
commit 1d5af8e8ad
1 changed files with 6 additions and 0 deletions

View File

@ -125,6 +125,11 @@ function common.list_update(w, buttons, label, data, objects, args)
for i, o in ipairs(objects) do
local cache = data[o]
-- Allow the buttons to be replaced.
if cache and cache._buttons ~= buttons then
cache = nil
end
if not cache then
cache = (args and args.widget_template) and
custom_template(args) or default_template()
@ -139,6 +144,7 @@ function common.list_update(w, buttons, label, data, objects, args)
args.create_callback(cache.primary, o, i, objects)
end
cache._buttons = buttons
data[o] = cache
elseif cache.update_callback then
cache.update_callback(cache.primary, o, i, objects)