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")
33 modelpath = ffluci.sys.libpath() .. "/model/menu/"
35 -- Menu definition extra scope
37 translate = function(...) return require("ffluci.i18n").translate(...) end,
38 loadtrans = function(...) return require("ffluci.i18n").loadc(...) end,
39 isfile = ffluci.fs.mtime
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 local generators = {}
103 for k, menu in pairs(ffluci.fs.dir(modelpath)) do
104 if menu:sub(1, 1) ~= "." then
105 local f = loadfile(modelpath.."/"..menu)
107 table.insert(generators, f)
115 -- Parse the collected information
116 function parse(generators)
118 for i, f in pairs(generators) do
119 local env = ffluci.util.clone(scope)
131 -- Returns the menu information
134 menu = parse(collect())