awful.menu: store active child

This fix the menu when they are multiple submenu entries.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-11-10 19:09:20 +01:00
parent ca38f96625
commit 0cddba4d82
1 changed files with 20 additions and 14 deletions

View File

@ -56,16 +56,17 @@ end
--- Hide a menu popup. --- Hide a menu popup.
-- @param menu The menu to hide. -- @param menu The menu to hide.
function hide(menu) function hide(menu)
if menu then -- Remove items from screen
-- Remove items from screen for i = 1, #menu.items do
for i = 1, #menu.items do -- Call mouse_leave to clear menu entry
-- Call mouse_leave to clear menu entry for k, w in pairs(menu.items[i].widgets) do
for k, w in pairs(menu.items[i].widgets) do w.mouse_leave()
w.mouse_leave()
end
menu.items[i].screen = nil
end end
hide(menu.child) menu.items[i].screen = nil
end
if menu.active_child then
menu.active_child:hide()
active_child = nil
end end
end end
@ -80,15 +81,19 @@ end
local function exec(data, action, num) local function exec(data, action, num)
if type(action[2]) == "table" then if type(action[2]) == "table" then
if not data.child then if not data.child[num] then
data.child = new({ items=action[2] }, data, num) data.child[num] = new({ items = action[2] }, data, num)
end end
data.child:show() if data.active_child then
data.active_child:hide()
end
data.active_child = data.child[num]
data.active_child:show()
elseif type(action[2]) == "string" then elseif type(action[2]) == "string" then
hide(get_parents(data)) get_parents(data):hide()
util.spawn(action[2]) util.spawn(action[2])
elseif type(action[2]) == "function" then elseif type(action[2]) == "function" then
hide(get_parents(data)) get_parents(data):hide()
action[2]() action[2]()
end end
end end
@ -250,6 +255,7 @@ function new(menu, parent, num)
data.num = num or 1 data.num = num or 1
data.theme = parent and parent.theme or load_theme(menu) data.theme = parent and parent.theme or load_theme(menu)
data.parent = parent data.parent = parent
data.child = {}
data.h = parent and parent.h or data.theme.menu_height data.h = parent and parent.h or data.theme.menu_height
data.w = parent and parent.w or data.theme.menu_width data.w = parent and parent.w or data.theme.menu_width