diff options
-rw-r--r-- | core/gui.lua | 21 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 17 | ||||
-rw-r--r-- | src/textadept.c | 18 |
3 files changed, 20 insertions, 36 deletions
diff --git a/core/gui.lua b/core/gui.lua index bc6f034a..a81877b0 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -468,18 +468,17 @@ local get_split_table local goto_view --- --- Creates a GTK menu, returning the userdata. +-- Creates a menu, returning the userdata. -- @param menu_table A table defining the menu. It is an ordered list of tables --- with a string menu item, integer menu ID, and optional keycode and modifier --- mask. The latter two are used to display key shortcuts in the menu. The --- string menu item is handled as follows: --- `'gtk-*'` - a stock menu item is created based on the GTK stock-id. --- `'separator'` - a menu separator item is created. --- Otherwise a regular menu item with a mnemonic is created. --- Submenus are just nested menu-structure tables. Their title text is defined --- with a `title` key. +-- with a string menu item, integer menu ID, and optional GDK keycode and +-- modifier mask. The latter two are used to display key shortcuts in the +-- menu. `_` characters are treated as a menu mnemonics. If the menu item is +-- empty, a menu separator item is created. Submenus are just nested +-- menu-structure tables. Their title text is defined with a `title` key. +-- @usage gui.menu{ { '_New', 1 }, { '_Open', 2 }, { '' }, { '_Quit', 4 } } +-- @usage gui.menu{ { '_New', 1, keys.get_gdk_key('cn') } } -- @see keys.get_gdk_key -- @class function --- @name gtkmenu -local gtkmenu +-- @name menu +local menu ]] diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index cf9f0d7e..1bdcbd41 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -27,7 +27,7 @@ local _L, io, gui, gui_find, buffer, view = _L, io, gui, gui.find, buffer, view local m_textadept, m_editing = _M.textadept, _M.textadept.editing local m_bookmarks, Msnippets = m_textadept.bookmarks, m_textadept.snippets local utils = m_textadept.keys.utils -local SEPARATOR, c = { 'separator' }, _SCINTILLA.constants +local SEPARATOR, c = { '' }, _SCINTILLA.constants --- -- Contains the main menubar. @@ -271,15 +271,8 @@ end --- -- Sets `gui.menubar` from the given table of menus. --- @param menubar The table of menus to create the menubar from. Each table --- entry is another table that corresponds to a particular menu. A menu can --- have a `title` key with string value. Each menu item is either a submenu --- (another menu table) or a table consisting of two items: string menu text --- and a function or action table just like in `keys`. The table can --- optionally contain 2 more number values: a GDK keycode and modifier mask --- for setting a menu accelerator. If the menu text is `'separator'`, a menu --- separator is created and no action table is required. --- @see keys.get_gdk_key +-- @param menubar The table of menus to create the menubar from. +-- @see gui.menu -- @see rebuild_command_tables -- @name set_menubar function M.set_menubar(menubar) @@ -317,10 +310,10 @@ 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] ~= 'separator' then + elseif menuitem[1] ~= '' then local label, f = menuitem[1], menuitem[2] if title then label = title..': '..label end - items[#items + 1] = label:gsub('_([^_])', '%1'):gsub('^gtk%-', '') + items[#items + 1] = label:gsub('_([^_])', '%1') items[#items + 1] = key_shortcuts[get_id(f)] or '' commands[#commands + 1] = f end diff --git a/src/textadept.c b/src/textadept.c index 84317db3..f693b0dc 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -122,6 +122,7 @@ static char *statusbar_text = NULL; static int tVOID = 0, tINT = 1, tLENGTH = 2, /*tPOSITION = 3, tCOLOUR = 4,*/ tBOOL = 5, tKEYMOD = 6, tSTRING = 7, tSTRINGRESULT = 8; static int lL_init(lua_State *, int, char **, int); +LUALIB_API int luaopen_lpeg(lua_State *), luaopen_lfs(lua_State *); #define l_setglobalview(l, v) (l_pushview(l, v), lua_setglobal(l, "view")) #define l_setglobaldoc(l, d) (l_pushdoc(l, d), lua_setglobal(l, "buffer")) @@ -134,9 +135,6 @@ static int lL_init(lua_State *, int, char **, int); } \ lua_setmetatable(l, (n > 0) ? n : n - 1); \ } -LUALIB_API int (luaopen_lpeg) (lua_State *); -LUALIB_API int (luaopen_lfs) (lua_State *); - #if LUAJIT #define LUA_OK 0 #define lua_rawlen lua_objlen @@ -838,18 +836,12 @@ static void l_pushmenu(lua_State *L, int index, void (*callback)(void), (GtkWidget *)lua_touserdata(L, -1)); lua_pop(L, 1); // menu } else if (lua_rawlen(L, -1) == 2 || lua_rawlen(L, -1) == 4) { - lua_rawgeti(L, -1, 1); - label = lua_tostring(L, -1); - lua_pop(L, 1); // label + lua_rawgeti(L, -1, 1), label = lua_tostring(L, -1), lua_pop(L, 1); int menu_id = l_rawgetiint(L, -1, 2); int key = l_rawgetiint(L, -1, 3), modifiers = l_rawgetiint(L, -1, 4); if (label) { - if (g_str_has_prefix(label, "gtk-")) - menu_item = gtk_image_menu_item_new_from_stock(label, NULL); - else if (strcmp(label, "separator") == 0) - menu_item = gtk_separator_menu_item_new(); - else - menu_item = gtk_menu_item_new_with_mnemonic(label); + menu_item = (*label) ? gtk_menu_item_new_with_mnemonic(label) + : gtk_separator_menu_item_new(); if (key || modifiers) gtk_widget_add_accelerator(menu_item, "activate", accel, key, modifiers, GTK_ACCEL_VISIBLE); @@ -2120,7 +2112,7 @@ static int cc_matchselected(GtkEntryCompletion*_, GtkTreeModel *model, g_signal_emit_by_name(G_OBJECT(command_entry), "backspace", 0); // for undo gtk_tree_model_get(model, iter, 0, &match, -1); g_signal_emit_by_name(G_OBJECT(command_entry), "insert-at-cursor", match, 0); - g_free(match); + g_free((char *)match); gtk_list_store_clear(cc_store); return TRUE; } |