2014-10-12 11:01:16 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Harvey Mittens
|
|
|
|
-- @copyright 2014 Harvey Mittens
|
|
|
|
-- @email teknocratdefunct@riseup.net
|
|
|
|
-- @release v3.5.5
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2015-07-03 12:17:54 +02:00
|
|
|
local menu_gen = require("menubar.menu_gen")
|
2014-10-12 11:01:16 +02:00
|
|
|
local menu_utils = require("menubar.utils")
|
2015-07-03 12:17:54 +02:00
|
|
|
local pairs = pairs
|
|
|
|
local ipairs = ipairs
|
|
|
|
local table = table
|
|
|
|
local string = string
|
|
|
|
local next = next
|
2014-10-12 11:01:16 +02:00
|
|
|
|
|
|
|
module("menugen")
|
|
|
|
|
2015-07-03 12:17:54 +02:00
|
|
|
-- Built in menubar should be checking local applications directory
|
2014-10-12 11:01:16 +02:00
|
|
|
menu_gen.all_menu_dirs = { '/usr/share/applications/', '/usr/local/share/applications/', '~/.local/share/applications' }
|
|
|
|
|
2015-07-03 12:17:54 +02:00
|
|
|
-- Expecting an wm_name of awesome omits too many applications and tools
|
2014-10-12 11:01:16 +02:00
|
|
|
menu_utils.wm_name = ""
|
|
|
|
|
|
|
|
-- Use MenuBar Parsing Utils to build StartMenu for Awesome
|
|
|
|
-- @return awful.menu compliant menu items tree
|
|
|
|
function build_menu()
|
|
|
|
local result = {}
|
|
|
|
local menulist = menu_gen.generate()
|
|
|
|
|
|
|
|
for k,v in pairs(menu_gen.all_categories) do
|
|
|
|
table.insert(result, {k, {}, v["icon"] } )
|
|
|
|
end
|
2015-07-03 12:17:54 +02:00
|
|
|
|
2014-10-12 11:01:16 +02:00
|
|
|
for k, v in ipairs(menulist) do
|
|
|
|
for _, cat in ipairs(result) do
|
|
|
|
if cat[1] == v["category"] then
|
|
|
|
table.insert( cat[2] , { v["name"], v["cmdline"], v["icon"] } )
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-07-03 12:17:54 +02:00
|
|
|
|
2014-10-12 11:01:16 +02:00
|
|
|
-- Cleanup Things a Bit
|
|
|
|
for k,v in ipairs(result) do
|
|
|
|
-- Remove Unused Categories
|
|
|
|
if not next(v[2]) then
|
|
|
|
table.remove(result, k)
|
|
|
|
else
|
|
|
|
--Sort entries Alphabetically (by Name)
|
|
|
|
table.sort(v[2], function (a,b) return string.byte(a[1]) < string.byte(b[1]) end)
|
|
|
|
-- Replace Catagory Name with nice name
|
|
|
|
v[1] = menu_gen.all_categories[v[1]].name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-03 12:17:54 +02:00
|
|
|
-- Sort Categories Alphabetically Also
|
2014-10-12 11:01:16 +02:00
|
|
|
table.sort(result, function(a,b) return string.byte(a[1]) < string.byte(b[1]) end)
|
|
|
|
|
|
|
|
return result
|
|
|
|
end
|