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
|
||||||
|
|
||||||
|
new_actions[old_idx] = a
|
||||||
|
end
|
||||||
|
|
||||||
-- Yes, it modifies `args`, this is legacy code, cloning the args
|
-- Yes, it modifies `args`, this is legacy code, cloning the args
|
||||||
-- just for this isn't worth it.
|
-- just for this isn't worth it.
|
||||||
actions[idx] = a
|
for old_idx, a in pairs(new_actions) do
|
||||||
|
actions[a.position] = a
|
||||||
|
actions[ old_idx ] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue