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")
33 require("ffluci.model.ipkg")
36 modelpath = ffluci.config.path .. "/model/menu/"
38 -- Menu definition extra scope
40 translate = ffluci.i18n.translate,
41 loadtrans = ffluci.i18n.loadc,
42 isfile = ffluci.fs.mtime
45 -- Local menu database
48 -- The current pointer
51 -- Adds a menu category to the current menu and selects it
52 function add(cat, controller, title, order)
59 entry[".descr"] = title
60 entry[".order"] = order
61 entry[".contr"] = controller
66 for k,v in ipairs(menu[cat]) do
67 if v[".order"] > entry[".order"] then
72 table.insert(menu[cat], i+1, entry)
77 -- Adds an action to the current menu
78 function act(action, title)
79 table.insert(menuc, {action = action, descr = title})
83 -- Selects a menu category
84 function sel(cat, controller)
91 for k,v in ipairs(menuc) do
92 if v[".contr"] == controller then
102 -- Collect all menu information provided in the model dir
104 for k, menu in pairs(ffluci.fs.dir(modelpath)) do
105 if menu:sub(1, 1) ~= "." then
106 local f = loadfile(modelpath.."/"..menu)
107 local env = ffluci.util.clone(scope)
119 -- Returns the menu information