Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

Commit

Permalink
Creating menu inside a function.
Browse files Browse the repository at this point in the history
This way users can first require all the needed modules, then set all
their options and only after that actually create the menu.

Thanks to Sergey (Сергей Миронов) for the idea and initial patch.
  • Loading branch information
terceiro committed Mar 13, 2009
1 parent aa6d127 commit 56b22fa
Showing 1 changed file with 60 additions and 47 deletions.
107 changes: 60 additions & 47 deletions freedesktop/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,70 @@ local os = os

module("freedesktop.menu", package.seeall)

-- the categories and their synonims where shamelessly copied from lxpanel
-- source code.

programs = {}
programs['AudioVideo'] = {}
programs['Audio'] = {}
programs['Video'] = {}
programs['Development'] = {}
programs['Education'] = {}
programs['Game'] = {}
programs['Graphics'] = {}
programs['Network'] = {}
programs['Office'] = {}
programs['Settings'] = {}
programs['System'] = {}
programs['Utility'] = {}
programs['Other'] = {}

for i, program in ipairs(utils.parse_desktop_files({ dir = '/usr/share/applications/' })) do

-- check whether to include in the menu
if program.show and program.Name and program.cmdline then
local target_category = nil
if program.categories then
for _, category in ipairs(program.categories) do
if programs[category] then
target_category = category
break
function new()
-- the categories and their synonyms where shamelessly copied from lxpanel
-- source code.
local programs = {}

programs['AudioVideo'] = {}
programs['Development'] = {}
programs['Education'] = {}
programs['Game'] = {}
programs['Graphics'] = {}
programs['Network'] = {}
programs['Office'] = {}
programs['Settings'] = {}
programs['System'] = {}
programs['Utility'] = {}
programs['Other'] = {}

for i, program in ipairs(utils.parse_desktop_files({ dir ='/usr/share/applications/' })) do

-- check whether to include in the menu
if program.show and program.Name and program.cmdline then
local target_category = nil
if program.categories then
for _, category in ipairs(program.categories) do
if programs[category] then
target_category = category
break
end
end
end
else
target_category = 'Other'
end
if target_category then
table.insert(programs[target_category], { program.Name, program.cmdline, program.icon_path })
if not target_category then
target_category = 'Other'
end
if target_category then
table.insert(programs[target_category], { program.Name, program.cmdline, program.icon_path })
end
end

end

end
local menu = {
{ "Accessories", programs["Utility"], utils.lookup_icon({ icon = 'applications-accessories.png' }) },
{ "Development", programs["Development"], utils.lookup_icon({ icon = 'applications-development.png' }) },
{ "Education", programs["Education"], utils.lookup_icon({ icon = 'applications-science.png' }) },
{ "Games", programs["Game"], utils.lookup_icon({ icon = 'applications-games.png' }) },
{ "Graphics", programs["Graphics"], utils.lookup_icon({ icon = 'applications-graphics.png' }) },
{ "Internet", programs["Network"], utils.lookup_icon({ icon = 'applications-internet.png' }) },
{ "Multimedia", programs["AudioVideo"], utils.lookup_icon({ icon = 'applications-multimedia.png' }) },
{ "Office", programs["Office"], utils.lookup_icon({ icon = 'applications-office.png' }) },
{ "Other", programs["Other"], utils.lookup_icon({ icon = 'applications-other.png' }) },
{ "Settings", programs["Settings"], utils.lookup_icon({ icon = 'applications-utilities.png' }) },
{ "System Tools", programs["System"], utils.lookup_icon({ icon = 'applications-system.png' }) },
}

applications_menu = {
{ "Accessories", programs["Utility"], utils.lookup_icon({ icon = 'applications-accessories.png' }) },
{ "Development", programs["Development"], utils.lookup_icon({ icon = 'applications-development.png' }) },
{ "Education", programs["Education"], utils.lookup_icon({ icon = 'applications-science.png' }) },
{ "Games", programs["Game"], utils.lookup_icon({ icon = 'applications-games.png' }) },
{ "Graphics", programs["Graphics"], utils.lookup_icon({ icon = 'applications-graphics.png' }) },
{ "Internet", programs["Network"], utils.lookup_icon({ icon = 'applications-internet.png' }) },
{ "Multimedia", programs["AudioVideo"], utils.lookup_icon({ icon = 'applications-multimedia.png' }) },
{ "Office", programs["Office"], utils.lookup_icon({ icon = 'applications-office.png' }) },
{ "Other", programs["Other"], utils.lookup_icon({ icon = 'applications-other.png' }) },
{ "Settings", programs["Settings"], utils.lookup_icon({ icon = 'applications-utilities.png' }) },
{ "System Tools", programs["System"], utils.lookup_icon({ icon = 'applications-system.png' }) },
}
-- Removing empty entries from menu
local bad_indexes = {}
for index , item in ipairs(menu) do
if not item[2] then
table.insert(bad_indexes, index)
end
end
for _, index in ipairs(bad_indexes) do
table.remove(menu, index)
end

return menu
end

0 comments on commit 56b22fa

Please sign in to comment.