From 67d6562f203ad1d46969c36be70606fee0b73096 Mon Sep 17 00:00:00 2001 From: Forkest Date: Sun, 5 Feb 2017 02:15:22 +0200 Subject: [PATCH 1/2] Fix cut and copy actions in non-Latin keyboard layouts Mark the associated menu items sensitive when the menu is hidden, so that GTK's accelerator handling can trigger them. This works around incorrect handling in Geany's code of keybindings coming from multiple layouts for cut/copy/delete actions. Partial workaround for #998, #1286 and #1368. --- data/geany.glade | 1 + src/callbacks.c | 10 ++++++++++ src/ui_utils.c | 15 +++++++++++---- src/ui_utils.h | 2 ++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/data/geany.glade b/data/geany.glade index 1c5a86a9..1196777d 100644 --- a/data/geany.glade +++ b/data/geany.glade @@ -6321,6 +6321,7 @@ True False + True diff --git a/src/callbacks.c b/src/callbacks.c index 1177925a..e9f4d050 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -200,6 +200,16 @@ static void on_edit1_activate(GtkMenuItem *menuitem, gpointer user_data) } +static void on_menubar1_deactivate(GtkMenuShell *menushell, gpointer user_data) +{ + /* we re-enable items that were disabled in on_edit1_activate() on menu popdown to + * workaround mutli-layout keyboard issues in our keybinding handling code, so that + * GTK's accelerator handling can catch them. + * See https://github.com/geany/geany/issues/1368#issuecomment-273678207 */ + ui_menu_copy_items_set_sensitive(TRUE); +} + + void on_undo1_activate(GtkMenuItem *menuitem, gpointer user_data) { GeanyDocument *doc = document_get_current(); diff --git a/src/ui_utils.c b/src/ui_utils.c index 702a3453..43c5c49f 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -512,10 +512,19 @@ void ui_update_popup_goto_items(gboolean enable) } +void ui_menu_copy_items_set_sensitive(gboolean sensitive) +{ + guint i, len; + + len = G_N_ELEMENTS(widgets.menu_copy_items); + for (i = 0; i < len; i++) + ui_widget_set_sensitive(widgets.menu_copy_items[i], sensitive); +} + + void ui_update_menu_copy_items(GeanyDocument *doc) { gboolean enable = FALSE; - guint i, len; GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window)); g_return_if_fail(doc == NULL || doc->is_valid); @@ -533,9 +542,7 @@ void ui_update_menu_copy_items(GeanyDocument *doc) enable = gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL); } - len = G_N_ELEMENTS(widgets.menu_copy_items); - for (i = 0; i < len; i++) - ui_widget_set_sensitive(widgets.menu_copy_items[i], enable); + ui_menu_copy_items_set_sensitive(enable); } diff --git a/src/ui_utils.h b/src/ui_utils.h index b260d0be..e94e5153 100644 --- a/src/ui_utils.h +++ b/src/ui_utils.h @@ -297,6 +297,8 @@ void ui_update_popup_copy_items(GeanyDocument *doc); void ui_update_popup_goto_items(gboolean enable); +void ui_menu_copy_items_set_sensitive(gboolean sensitive); + void ui_update_menu_copy_items(GeanyDocument *doc); void ui_update_insert_include_item(GeanyDocument *doc, gint item); From 2c1a71ad2bbe7bc73abb37cb94f065c0137f84c7 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Sun, 5 Feb 2017 15:34:24 +0100 Subject: [PATCH 2/2] Use :select/:deselect signals for consistency Instead of having a handler on 2 separate objects, use :select and :deselect on the same one. Those signals are appropriate, as the documentation mentions that submenus are popped up on :select. --- data/geany.glade | 4 ++-- src/callbacks.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/data/geany.glade b/data/geany.glade index 1196777d..d0f49bd2 100644 --- a/data/geany.glade +++ b/data/geany.glade @@ -6321,7 +6321,6 @@ True False - True @@ -6563,7 +6562,8 @@ False _Edit True - + + False diff --git a/src/callbacks.c b/src/callbacks.c index e9f4d050..649072c0 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -183,7 +183,7 @@ static void on_file1_activate(GtkMenuItem *menuitem, gpointer user_data) /* edit actions, c&p & co, from menu bar and from popup menu */ -static void on_edit1_activate(GtkMenuItem *menuitem, gpointer user_data) +static void on_edit1_select(GtkMenuItem *menuitem, gpointer user_data) { GtkWidget *item; GeanyDocument *doc = document_get_current(); @@ -200,9 +200,9 @@ static void on_edit1_activate(GtkMenuItem *menuitem, gpointer user_data) } -static void on_menubar1_deactivate(GtkMenuShell *menushell, gpointer user_data) +static void on_edit1_deselect(GtkMenuShell *menushell, gpointer user_data) { - /* we re-enable items that were disabled in on_edit1_activate() on menu popdown to + /* we re-enable items that were disabled in on_edit1_select() on menu popdown to * workaround mutli-layout keyboard issues in our keybinding handling code, so that * GTK's accelerator handling can catch them. * See https://github.com/geany/geany/issues/1368#issuecomment-273678207 */