menubar: Fix entry use count for categories

Fix #999
This commit is contained in:
modk 2016-07-17 12:11:10 +02:00 committed by Emmanuel Lepage Vallee
parent 7a4bdca9c2
commit 1a40333b9e
1 changed files with 41 additions and 14 deletions

View File

@ -231,6 +231,14 @@ local function menulist_update(query, scr)
-- beginning to the table shownitems, and the ones that contain -- beginning to the table shownitems, and the ones that contain
-- command in the middle to the table match_inside. -- command in the middle to the table match_inside.
local count_table = load_count_table()
local command_list = {}
local PRIO_NONE = 0
local PRIO_HIG = 3
local PRIO_LOW = 1
local PRIO_NORMAL = 2
-- Add the categories -- Add the categories
if menubar.show_categories then if menubar.show_categories then
for _, v in pairs(menubar.menu_gen.all_categories) do for _, v in pairs(menubar.menu_gen.all_categories) do
@ -238,40 +246,59 @@ local function menulist_update(query, scr)
if not current_category and v.use then if not current_category and v.use then
if string.match(v.name, pattern) then if string.match(v.name, pattern) then
if string.match(v.name, "^" .. pattern) then if string.match(v.name, "^" .. pattern) then
table.insert(shownitems, v) v.count = PRIO_NONE
else v.prio = PRIO_NORMAL
table.insert(match_inside, v)
-- use count from count_table if present
if string.len(pattern) > 0 and count_table[v.name] ~= nil then
v.count = tonumber(count_table[v.name])
end
if string.match(v.name, "^" .. pattern)
or string.match(v.cmdline, "^" .. pattern) then
v.prio = PRIO_HIGH
else
v.prio = PRIO_NORMAL
end
table.insert (command_list, v)
end end
end end
end end
end end
end end
local count_table = load_count_table()
local command_list = {}
-- Add the applications according to their name and cmdline -- Add the applications according to their name and cmdline
for _, v in ipairs(menubar.menu_entries) do for _, v in ipairs(menubar.menu_entries) do
v.focused = false v.focused = false
if not current_category or v.category == current_category then if not current_category or v.category == current_category then
if string.match(v.name, pattern) if string.match(v.name, pattern)
or string.match(v.cmdline, pattern) then or string.match(v.cmdline, pattern) then
v.count = 0
v.prio = PRIO_NONE
-- use count from count_table if present
if string.len(pattern) > 0 and count_table[v.name] ~= nil then
v.count = tonumber(count_table[v.name])
end
if string.match(v.name, "^" .. pattern) if string.match(v.name, "^" .. pattern)
or string.match(v.cmdline, "^" .. pattern) then or string.match(v.cmdline, "^" .. pattern) then
v.prio = PRIO_LOW
v.count = 0 else
-- use count from count_table if present v.prio = PRIO_NONE
if string.len(pattern) > 0 and count_table[v.name] ~= nil then
v.count = tonumber(count_table[v.name])
end
table.insert (command_list, v)
end end
table.insert (command_list, v)
end end
end end
end end
local function compare_counts(a,b) local function compare_counts(a,b)
if a.count == b.count then
return a.prio > b.prio
end
return a.count > b.count return a.count > b.count
end end