feat: menu pages dispatching
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
local gui_util = {}
|
||||
local gui_util = {
|
||||
local_dispatchers = {}
|
||||
}
|
||||
|
||||
--- Parse `pagename?arg1=value1&arg2=value2` queries
|
||||
--- @param query page query string
|
||||
@@ -25,6 +27,11 @@ end
|
||||
--- @return document_id
|
||||
function gui_util.load_page(query)
|
||||
local name, args = gui_util.parse_query(query)
|
||||
for i = #gui_util.local_dispatchers, 1, -1 do
|
||||
local newname, newargs = gui_util.local_dispatchers[i](name, args)
|
||||
name = newname or name
|
||||
args = newargs or args
|
||||
end
|
||||
local filename = file.find(string.format("layouts/pages/%s.xml", name))
|
||||
if filename then
|
||||
name = file.prefix(filename)..":pages/"..name
|
||||
@@ -33,4 +40,15 @@ function gui_util.load_page(query)
|
||||
end
|
||||
end
|
||||
|
||||
function gui_util.add_page_dispatcher(dispatcher)
|
||||
if type(dispatcher) ~= "function" then
|
||||
error("function expected")
|
||||
end
|
||||
table.insert(gui_util.local_dispatchers, dispatcher)
|
||||
end
|
||||
|
||||
function gui_util.reset_local()
|
||||
gui_util.local_dispatchers = {}
|
||||
end
|
||||
|
||||
return gui_util
|
||||
|
||||
Reference in New Issue
Block a user