aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/textadept/menu.lua54
1 files changed, 23 insertions, 31 deletions
diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua
index 20737b51..e45992f3 100644
--- a/modules/textadept/menu.lua
+++ b/modules/textadept/menu.lua
@@ -269,6 +269,27 @@ local function read_menu_table(menu, contextmenu)
return gtkmenu
end
+local items, commands
+
+-- Builds the item and commands tables for the filteredlist dialog.
+-- @param menu The menu to read from.
+-- @param title The title of the menu.
+-- @param items The current list of items.
+-- @param commands The current list of commands.
+local function build_command_tables(menu, title, items, commands)
+ for _, menuitem in ipairs(menu) do
+ if menuitem.title then
+ build_command_tables(menuitem, menuitem.title, items, commands)
+ elseif menuitem[1] ~= '' then
+ local label, f = menuitem[1], menuitem[2]
+ if title then label = title..': '..label end
+ items[#items + 1] = label:gsub('_([^_])', '%1')
+ items[#items + 1] = key_shortcuts[get_id(f)] or ''
+ commands[#commands + 1] = f
+ end
+ end
+end
+
---
-- Sets `gui.menubar` from the given table of menus.
-- @param menubar The table of menus to create the menubar from.
@@ -285,6 +306,8 @@ function M.set_menubar(menubar)
_menubar[#_menubar + 1] = gui.menu(read_menu_table(menubar[i]))
end
gui.menubar = _menubar
+ items, commands = {}, {}
+ build_command_tables(M.menubar, nil, items, commands)
end
M.set_menubar(M.menubar)
@@ -300,27 +323,6 @@ function M.set_contextmenu(menu_table)
end
if not NCURSES then M.set_contextmenu(M.context_menu) end
-local items, commands
-
--- Builds the item and commands tables for the filteredlist dialog.
--- @param menu The menu to read from.
--- @param title The title of the menu.
--- @param items The current list of items.
--- @param commands The current list of commands.
-local function build_command_tables(menu, title, items, commands)
- for _, menuitem in ipairs(menu) do
- if menuitem.title then
- build_command_tables(menuitem, menuitem.title, items, commands)
- elseif menuitem[1] ~= '' then
- local label, f = menuitem[1], menuitem[2]
- if title then label = title..': '..label end
- items[#items + 1] = label:gsub('_([^_])', '%1')
- items[#items + 1] = key_shortcuts[get_id(f)] or ''
- commands[#commands + 1] = f
- end
- end
-end
-
local columns = { _L['Command'], _L['Key Command'] }
---
-- Prompts the user with a filteredlist to run menu commands.
@@ -331,16 +333,6 @@ function M.select_command()
if i then keys.run_command(commands[i + 1], type(commands[i + 1])) end
end
----
--- Rebuilds the tables used by `select_command()`.
--- This should be called every time `set_menubar()` is called.
--- @name rebuild_command_tables
-function M.rebuild_command_tables()
- items, commands = {}, {}
- build_command_tables(M.menubar, nil, items, commands)
-end
-M.rebuild_command_tables()
-
local events, events_connect = events, events.connect
events_connect(events.MENU_CLICKED, function(menu_id)