--
-- ion/ioncore/ioncore_menudb.lua -- Routines for defining menus.
--
--- Copyright (c) Tuomo Valkonen 2004-2006.
+-- Copyright (c) Tuomo Valkonen 2004-2007.
--
-- Ion is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License as published by
ioncore.warn(TR("Unable to append to non-table menu"))
return
else
- table.append(menus[name], tab)
+ for k, v in ipairs(tab) do
+ table.insert(menus[name], v)
+ end
end
else
menus[name]=tab
-- Workspace and window lists {{{
-local function makelist(list)
- local function mkentry(tgt)
- return menuentry(tgt:name(), function() tgt:goto() end)
+local function addto(list)
+ return function(tgt, attr)
+ local e=menuentry(tgt:name(), function() tgt:goto() end)
+ e.attr=attr;
+ table.insert(list, e)
+ return true
end
- local entries=table.map(mkentry, list)
+end
+
+local function sort(entries)
table.sort(entries, function(a, b) return a.name < b.name end)
return entries
end
function menus.windowlist()
- return makelist(ioncore.clientwin_list())
+ local entries={}
+ ioncore.clientwin_i(addto(entries))
+ return sort(entries)
end
function menus.workspacelist()
- return makelist(ioncore.region_list("WGenWS"))
+ local entries={}
+ local iter_=addto(entries)
+
+ local function iter(obj)
+ return (not obj_is(obj, "WGroupWS")
+ or iter_(obj))
+ end
+
+ ioncore.region_i(iter)
+
+ return sort(entries)
+end
+
+local function focuslist(do_act)
+ local entries={}
+ local seen={}
+ local iter_=addto(entries)
+
+ local function iter(obj, attr)
+ if obj_is(obj, "WClientWin") then
+ iter_(obj, attr)
+ seen[obj]=true
+ end
+ return true
+ end
+
+ local function iter_act(obj)
+ return iter(obj, "activity")
+ end
+
+ local function iter_foc(obj)
+ return (seen[obj] or iter(obj))
+ end
+
+ if do_act then
+ ioncore.activity_i(iter_act)
+ end
+
+ ioncore.focushistory_i(iter_foc)
+
+ return entries
end
+menus.focuslist=function() return focuslist(true) end
+menus.focuslist_=function() return focuslist(false) end
+
-- }}}