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")
32 require("ffluci.config")
35 modelpath = ffluci.config.path .. "/model/menu/"
37 -- Menu definition extra scope
39 translate = ffluci.i18n.translate
42 -- Local menu database
45 -- The current pointer
48 -- Adds a menu category to the current menu and selects it
49 function add(cat, controller, title, order)
56 entry[".descr"] = title
57 entry[".order"] = order
58 entry[".contr"] = controller
63 for k,v in ipairs(menu[cat]) do
64 if v[".order"] > entry[".order"] then
69 table.insert(menu[cat], i+1, entry)
74 -- Adds an action to the current menu
75 function act(action, title)
76 table.insert(menuc, {action = action, descr = title})
80 -- Selects a menu category
81 function sel(cat, controller)
88 for k,v in ipairs(menuc) do
89 if v[".contr"] == controller then
99 -- Collect all menu information provided in the model dir
101 for k, menu in pairs(ffluci.fs.dir(modelpath)) do
102 if menu:sub(1, 1) ~= "." then
103 local f = loadfile(modelpath.."/"..menu)
104 local env = ffluci.util.clone(scope)
116 -- Returns the menu information