diff options
author | 2009-01-26 22:43:08 -0500 | |
---|---|---|
committer | 2009-01-26 22:43:08 -0500 | |
commit | 5644dd27197711b3a69d0dd05e6a1b82c404f027 (patch) | |
tree | 6aa561f7ac8edd7aeda19fecc913c7b9cbde08c9 | |
parent | 6cd7f0016da3b5c138fa797cc8aaa9f8671b1419 (diff) | |
download | textadept-5644dd27197711b3a69d0dd05e6a1b82c404f027.tar.gz textadept-5644dd27197711b3a69d0dd05e6a1b82c404f027.zip |
Menu label text is irrelevant for menu actions due to l10n; focus on menu_id.
-rw-r--r-- | core/.browser.lua | 2 | ||||
-rw-r--r-- | core/events.lua | 8 | ||||
-rw-r--r-- | core/ext/menu.lua | 16 | ||||
-rw-r--r-- | src/lua_interface.c | 12 | ||||
-rw-r--r-- | src/textadept.c | 5 |
5 files changed, 25 insertions, 18 deletions
diff --git a/core/.browser.lua b/core/.browser.lua index a9ba1272..a9bb2ac1 100644 --- a/core/.browser.lua +++ b/core/.browser.lua @@ -63,7 +63,7 @@ function get_context_menu(selected_item) -- @param menu_id The numeric ID of the menu item. -- @param selected_item Identical to 'full_path' in pm.get_contents_for. -- @see pm.get_contents_for -function perform_menu_action(menu_item, selected_item) +function perform_menu_action(menu_id, selected_item) --- -- Toggles the width of the project manager. diff --git a/core/events.lua b/core/events.lua index fec8d4b9..8a2f86b8 100644 --- a/core/events.lua +++ b/core/events.lua @@ -65,8 +65,7 @@ module('textadept.events', package.seeall) -- shift: flag indicating whether or not shift is pressed. -- control: flag indicating whether or not control is pressed. -- alt: flag indicating whether or not alt is pressed. --- menu_clicked(menu_item, menu_id) --- menu_item: text of the menu item clicked. +-- menu_clicked(menu_id) -- menu_id: the numeric ID of the menu item. local events = textadept.events @@ -138,9 +137,8 @@ end function keypress(code, shift, control, alt) return handle('keypress', code, shift, control, alt) end -function menu_clicked(menu_item) - local text, menu_id = menu_item:match('^(.+)|(%d+)$') - return handle('menu_clicked', text, tonumber(menu_id)) +function menu_clicked(menu_id_str) + return handle('menu_clicked', tonumber(menu_id_str)) end -- Scintilla notifications. diff --git a/core/ext/menu.lua b/core/ext/menu.lua index 9124f748..cc1ae5c6 100644 --- a/core/ext/menu.lua +++ b/core/ext/menu.lua @@ -559,12 +559,24 @@ local actions = { [ID.SHOW_PM_MODULES] = { pm_activate, 'modules' }, } +-- lexers here MUST be in the same order as in the menu +local lexers = { + 'actionscript', 'ada', 'antlr', 'apdl', 'applescript', 'asp', 'awk', 'batch', + 'boo', 'container', 'cpp', 'csharp', 'css', 'd', 'diff', 'django', 'eiffel', + 'erlang', 'errorlist', 'forth', 'fortran', 'gap', 'gettext', 'gnuplot', + 'groovy', 'haskell', 'html', 'idl', 'ini', 'io', 'java', 'javascript', + 'latex', 'lisp', 'lua', 'makefile', 'mysql', 'objective__c', 'ocaml', + 'pascal', 'perl', 'php', 'pike', 'postscript', 'props', 'python', 'r', + 'ragel', 'rebol', 'rexx', 'rhtml', 'ruby', 'scheme', 'shellscript', + 'smalltalk', 'tcl', 'vala', 'verilog', 'vhdl', 'visualbasic', 'xml' +} + -- Most of this handling code comes from keys.lua. t.events.add_handler('menu_clicked', - function(menu_item, menu_id) + function(menu_id) local active_table = actions[menu_id] if menu_id >= ID.LEXER_ACTIONSCRIPT and menu_id <= ID.LEXER_XML then - active_table = { set_lexer_language, menu_item } + active_table = { set_lexer_language, lexers[menu_id - 800] } end local f, args if active_table and #active_table > 0 then diff --git a/src/lua_interface.c b/src/lua_interface.c index 023bd7c0..dc54488a 100644 --- a/src/lua_interface.c +++ b/src/lua_interface.c @@ -1491,14 +1491,12 @@ static int l_cf_view_goto_buffer(lua_State *lua) { return 0; } -static void t_menu_activate(GtkWidget *menu_item, gpointer menu_id) { - GtkWidget *label = gtk_bin_get_child(GTK_BIN(menu_item)); - const char *text = gtk_label_get_text(GTK_LABEL(label)); +static void t_menu_activate(GtkWidget *, gpointer menu_id) { int id = reinterpret_cast<int>(menu_id); - char *param = static_cast<char*>(malloc(sizeof(char) * (strlen(text) + 12))); - sprintf(param, "%s|%i\0", text, id); - l_handle_event("menu_clicked", param); - g_free(param); + char *menu_id_str = static_cast<char*>(malloc(sizeof(char) * 12)); + sprintf(menu_id_str, "%i", id); + l_handle_event("menu_clicked", menu_id_str); + g_free(menu_id_str); } static int l_cf_ta_gtkmenu(lua_State *lua) { diff --git a/src/textadept.c b/src/textadept.c index de24626e..ebc0d6d2 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -56,7 +56,7 @@ static void pm_row_activated(GtkTreeView *, GtkTreePath *, GtkTreeViewColumn *, gpointer); static gbool pm_button_press(GtkTreeView *, GdkEventButton *event, gpointer); static gbool pm_popup_menu(GtkWidget *, gpointer); -static void pm_menu_activate(GtkWidget *menu_item, gpointer menu_id); +static void pm_menu_activate(GtkWidget *, gpointer menu_id); // Find/Replace GtkWidget *findbox, *find_entry, *replace_entry, *fnext_button, *fprev_button, @@ -770,11 +770,10 @@ void pm_popup_context_menu(GdkEventButton *event) { /** * Performs a Lua action for a selected Project Manager menu item. - * @param menu_item The menu item. * @param menu_id The numeric ID for the menu item. * @see l_pm_perform_menu_action */ -void pm_process_selected_menu_item(GtkWidget *menu_item, int menu_id) { +void pm_process_selected_menu_item(GtkWidget *, int menu_id) { GtkTreePath *path; GtkTreeViewColumn *column; gtk_tree_view_get_cursor(GTK_TREE_VIEW(pm_view), &path, &column); |