naughty: Use cleaner code to update the legacy actions.
The old code surprisingly worked, but reading this again, better make some changes.
This commit is contained in:
parent
8951b88095
commit
7bf1a276ef
|
@ -380,16 +380,18 @@ local function convert_actions(actions)
|
||||||
|
|
||||||
local naction = require("naughty.action")
|
local naction = require("naughty.action")
|
||||||
|
|
||||||
|
local new_actions = {}
|
||||||
|
|
||||||
-- Does not attempt to handle when there is a mix of strings and objects
|
-- Does not attempt to handle when there is a mix of strings and objects
|
||||||
for idx, name in pairs(actions) do
|
for idx, name in pairs(actions) do
|
||||||
local cb = nil
|
local cb, old_idx = nil, idx
|
||||||
|
|
||||||
if type(name) == "function" then
|
if type(name) == "function" then
|
||||||
cb = name
|
cb = name
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(idx) == "string" then
|
if type(idx) == "string" then
|
||||||
name, idx = idx, nil
|
name, idx = idx, #actions+1
|
||||||
end
|
end
|
||||||
|
|
||||||
local a = naction {
|
local a = naction {
|
||||||
|
@ -401,9 +403,14 @@ local function convert_actions(actions)
|
||||||
a:connect_signal("invoked", cb)
|
a:connect_signal("invoked", cb)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Yes, it modifies `args`, this is legacy code, cloning the args
|
new_actions[old_idx] = a
|
||||||
-- just for this isn't worth it.
|
end
|
||||||
actions[idx] = a
|
|
||||||
|
-- Yes, it modifies `args`, this is legacy code, cloning the args
|
||||||
|
-- just for this isn't worth it.
|
||||||
|
for old_idx, a in pairs(new_actions) do
|
||||||
|
actions[a.position] = a
|
||||||
|
actions[ old_idx ] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -497,7 +504,7 @@ local function create(args)
|
||||||
rawget(n, "preset") or {}
|
rawget(n, "preset") or {}
|
||||||
))
|
))
|
||||||
|
|
||||||
if is_old_action then
|
if is_old_action then
|
||||||
convert_actions(args.actions)
|
convert_actions(args.actions)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue