aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lua_interface.c54
-rw-r--r--src/textadept.c11
-rw-r--r--src/textadept.h4
3 files changed, 45 insertions, 24 deletions
diff --git a/src/lua_interface.c b/src/lua_interface.c
index 34b6dbbd..15cd3d95 100644
--- a/src/lua_interface.c
+++ b/src/lua_interface.c
@@ -615,19 +615,32 @@ GtkWidget *l_create_gtkmenu(LS *lua, GCallback callback, bool submenu) {
} lua_pop(lua, 1); // title
lua_pushnil(lua);
while (lua_next(lua, -2)) {
- if (lua_type(lua, -2) == LUA_TNUMBER && lua_isstring(lua, -1)) {
- label = lua_tostring(lua, -1);
- if (g_str_has_prefix(label, "gtk-"))
- menu_item = gtk_image_menu_item_new_from_stock(label, NULL);
- else if (streq(label, "separator"))
- menu_item = gtk_separator_menu_item_new();
- else menu_item = gtk_menu_item_new_with_mnemonic(label);
- g_signal_connect(menu_item, "activate", callback, 0);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
- } else if (lua_istable(lua, -1))
- gtk_menu_shell_append(GTK_MENU_SHELL(menu),
- l_create_gtkmenu(lua, callback, true));
- lua_pop(lua, 1); // value
+ if (lua_istable(lua, -1)) {
+ lua_getfield(lua, -1, "title");
+ bool is_submenu = !lua_isnil(lua, -1);
+ lua_pop(lua, 1); // title
+ if (is_submenu)
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu),
+ l_create_gtkmenu(lua, callback, true));
+ else
+ if (lua_objlen(lua, -1) == 2) {
+ lua_rawgeti(lua, -1, 1);
+ lua_rawgeti(lua, -2, 2);
+ label = lua_tostring(lua, -2);
+ int menu_id = static_cast<int>(lua_tonumber(lua, -1));
+ lua_pop(lua, 2); // label and id
+ if (label) {
+ if (g_str_has_prefix(label, "gtk-"))
+ menu_item = gtk_image_menu_item_new_from_stock(label, NULL);
+ else if (streq(label, "separator"))
+ menu_item = gtk_separator_menu_item_new();
+ else menu_item = gtk_menu_item_new_with_mnemonic(label);
+ g_signal_connect(menu_item, "activate", callback,
+ reinterpret_cast<gpointer>(menu_id));
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
+ }
+ } else warn("gtkmenu: { 'menu label', id_number } expected.");
+ } lua_pop(lua, 1); // value
} return !submenu_root ? menu : submenu_root;
}
@@ -897,13 +910,16 @@ void l_pm_perform_action() {
* Manager.
* The full path table for the item is at the top of the Lua stack.
* @param menu_item The label text for the menu item clicked.
+ * @param menu_id The numeric ID for the menu item.
*/
-void l_pm_perform_menu_action(const char *menu_item) {
+void l_pm_perform_menu_action(const char *menu_item, int menu_id) {
if (!l_is_ta_table_function("pm", "perform_menu_action")) return;
l_insert(lua, -1); // shift full_path down
lua_pushstring(lua, menu_item);
l_insert(lua, -1); // shift full_path down
- l_call_function(2);
+ lua_pushnumber(lua, menu_id);
+ l_insert(lua, -1); // shift full_path down
+ l_call_function(3);
}
// Find/Replace
@@ -1382,10 +1398,14 @@ LF l_cf_view_goto_buffer(LS *lua) {
return 0;
}
-static void t_menu_activate(GtkWidget *menu_item, gpointer) {
+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));
- l_handle_event("menu_clicked", text);
+ 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);
}
LF l_cf_ta_gtkmenu(LS *lua) {
diff --git a/src/textadept.c b/src/textadept.c
index 136cd18b..4d08af59 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -53,7 +53,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);
+static void pm_menu_activate(GtkWidget *menu_item, gpointer menu_id);
// Find/Replace
GtkWidget *findbox, *find_entry, *replace_entry;
@@ -746,16 +746,17 @@ 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) {
+void pm_process_selected_menu_item(GtkWidget *menu_item, int menu_id) {
GtkWidget *label = gtk_bin_get_child(GTK_BIN(menu_item));
const char *text = gtk_label_get_text(GTK_LABEL(label));
GtkTreePath *path;
GtkTreeViewColumn *column;
gtk_tree_view_get_cursor(GTK_TREE_VIEW(pm_view), &path, &column);
l_pm_get_full_path(path);
- l_pm_perform_menu_action(text);
+ l_pm_perform_menu_action(text, menu_id);
}
/**
@@ -875,8 +876,8 @@ static gbool pm_popup_menu(GtkWidget *, gpointer) {
* Signal for a selected Project Manager menu item.
* @see pm_process_selected_menu_item
*/
-static void pm_menu_activate(GtkWidget *menu_item, gpointer) {
- pm_process_selected_menu_item(menu_item);
+static void pm_menu_activate(GtkWidget *menu_item, gpointer menu_id) {
+ pm_process_selected_menu_item(menu_item, reinterpret_cast<int>(menu_id));
}
// Find/Replace
diff --git a/src/textadept.h b/src/textadept.h
index bceb7f36..bbc49767 100644
--- a/src/textadept.h
+++ b/src/textadept.h
@@ -68,7 +68,7 @@ void pm_open_parent(GtkTreeIter *iter, GtkTreePath *path);
void pm_close_parent(GtkTreeIter *iter, GtkTreePath *path);
void pm_activate_selection();
void pm_popup_context_menu(GdkEventButton *event);
-void pm_process_selected_menu_item(GtkWidget *menu_item);
+void pm_process_selected_menu_item(GtkWidget *menu_item, int menu_id);
GtkWidget *find_create_ui();
void find_toggle_focus();
@@ -100,7 +100,7 @@ void l_pm_populate(GtkTreeIter *initial_iter);
void l_pm_get_full_path(GtkTreePath *path);
void l_pm_perform_action();
void l_pm_popup_context_menu(GdkEventButton *event, GCallback callback);
-void l_pm_perform_menu_action(const char *menu_item);
+void l_pm_perform_menu_action(const char *menu_item, int menu_id);
void l_find(const char *ftext, bool next);
void l_find_replace(const char *rtext);