5 Collects menu building information from controllers
11 Copyright 2008 Steven Barth <steven@midlink.org>
13 Licensed under the Apache License, Version 2.0 (the "License");
14 you may not use this file except in compliance with the License.
15 You may obtain a copy of the License at
17 http://www.apache.org/licenses/LICENSE-2.0
19 Unless required by applicable law or agreed to in writing, software
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
26 module("ffluci.menu", package.seeall)
29 require("ffluci.util")
30 require("ffluci.template")
31 require("ffluci.i18n")
34 modelpath = ffluci.fs.dirname(ffluci.util.__file__()) .. "/model/menu/"
36 -- Menu definition extra scope
38 translate = ffluci.i18n.translate
41 -- Local menu database
44 -- The current pointer
47 -- Adds a menu category to the current menu and selects it
48 function add(cat, controller, title, order)
55 entry[".descr"] = title
56 entry[".order"] = order
57 entry[".contr"] = controller
62 for k,v in ipairs(menu[cat]) do
63 if v[".order"] > entry[".order"] then
68 table.insert(menu[cat], i+1, entry)
73 -- Adds an action to the current menu
74 function act(action, title)
75 table.insert(menuc, {action = action, descr = title})
79 -- Selects a menu category
80 function sel(cat, controller)
87 for k,v in ipairs(menuc) do
88 if v[".contr"] == controller then
98 -- Collect all menu information provided in the model dir
100 for k, menu in pairs(ffluci.fs.dir(modelpath)) do
101 if menu:sub(1, 1) ~= "." then
102 local f = loadfile(modelpath.."/"..menu)
103 local env = ffluci.util.clone(scope)
115 -- Returns the menu information