diff options
author | Ted Trask <ttrask01@yahoo.com> | 2009-12-24 16:45:47 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2009-12-24 16:45:47 +0000 |
commit | bd7a0266eb07cb8859fa7518f0000ef0240923d6 (patch) | |
tree | f57b20a90767de53086a79ee402661369173d7ef /lib/menubuilder.lua | |
parent | 17ecdf3680593a739bf32186e8ca1a0dcaf9ea10 (diff) | |
download | acf-core-bd7a0266eb07cb8859fa7518f0000ef0240923d6.tar.bz2 acf-core-bd7a0266eb07cb8859fa7518f0000ef0240923d6.tar.xz |
Added code to split menu group is multiple controllers add same tab to same group.
This will help for multiple instances of same service.
Diffstat (limited to 'lib/menubuilder.lua')
-rw-r--r-- | lib/menubuilder.lua | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/menubuilder.lua b/lib/menubuilder.lua index 3922129..8c93795 100644 --- a/lib/menubuilder.lua +++ b/lib/menubuilder.lua @@ -88,6 +88,7 @@ get_menuitems = function (startdir) table.insert ( cat.groups, { name = result.group, controllers = {}, + reversetabs = {}, tabs = {} } ) cat.reversegroups[result.group] = #cat.groups end @@ -101,6 +102,13 @@ get_menuitems = function (startdir) prefix = prefix, action = result.action } table.insert(group.tabs, tab) + if group.reversetabs[tab.name] then + -- Flag for two tabs of same name + group.flag = tab.name + table.insert(group.reversetabs[tab.name], #group.tabs) + else + group.reversetabs[tab.name] = {#group.tabs} + end end end end @@ -113,6 +121,58 @@ get_menuitems = function (startdir) -- Then groups for x, cat in ipairs(cats) do + -- Let's check for bad groups (multiple tabs with same name) + for y,group in ipairs(cat.groups) do + if group.flag then + -- determine the difference between prefix/controller combos (start and stop chars) + local start=0 + local done = false + local first = "" + for con in pairs(group.controllers) do + first = con + break + end + while not done and start<first:len() do + start = start+1 + for con in pairs(group.controllers) do + if con:sub(start,start) ~= first:sub(start,start) then + done = true + break + end + end + end + local stop=0 + done = false + while not done and stop+first:len()>0 do + stop = stop-1 + for con in pairs(group.controllers) do + if con:sub(stop,stop) ~= first:sub(stop,stop) then + done = true + break + end + end + end + + -- create new groups for each prefix/controller + for con in pairs(group.controllers) do + table.insert ( cat.groups, + { name = group.name..string.sub(con,start,stop), + controllers = {}, + priority = group.priority, + reversetabs = {}, + tabs = {} } ) + cat.groups[#cat.groups].controllers[con] = true + cat.reversegroups[group.name..con] = #cat.groups + end + -- move the tabs into appropriate groups + for z,tab in ipairs(group.tabs) do + table.insert(cat.groups[cat.reversegroups[group.name..tab.prefix..tab.controller]].tabs, tab) + end + -- remove the group + group.tabs = {} + end + group.reversetabs = nil -- don't need reverse table anymore + end cat.reversegroups = nil -- don't need reverse table anymore table.sort(cat.groups, prio_compare) end |