Revision: 4558 http://geany.svn.sourceforge.net/geany/?rev=4558&view=rev Author: eht16 Date: 2010-01-25 21:15:39 +0000 (Mon, 25 Jan 2010)
Log Message: ----------- Backport from trunk: Fix updating main menu accelerators after changing keybindings (thanks to Lex Trotman).
Modified Paths: -------------- branches/geany-0.18.1/ChangeLog branches/geany-0.18.1/src/keybindings.c branches/geany-0.18.1/src/keybindings.h branches/geany-0.18.1/src/prefs.c
Modified: branches/geany-0.18.1/ChangeLog =================================================================== --- branches/geany-0.18.1/ChangeLog 2010-01-25 21:15:27 UTC (rev 4557) +++ branches/geany-0.18.1/ChangeLog 2010-01-25 21:15:39 UTC (rev 4558) @@ -2,6 +2,9 @@
* src/callbacks.c: Fix 'Open Selected File' for unsaved new documents. + * src/keybindings.c, src/keybindings.h, src/prefs.c: + Fix updating main menu accelerators after changing keybindings + (thanks to Lex Trotman).
2009-08-18 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: branches/geany-0.18.1/src/keybindings.c =================================================================== --- branches/geany-0.18.1/src/keybindings.c 2010-01-25 21:15:27 UTC (rev 4557) +++ branches/geany-0.18.1/src/keybindings.c 2010-01-25 21:15:39 UTC (rev 4558) @@ -107,12 +107,10 @@ static void cb_func_move_tab(guint key_id);
static void add_popup_menu_accels(void); -static void apply_kb_accel(GeanyKeyGroup *group, GeanyKeyBinding *kb, gpointer user_data);
-/* This is used to set default keybindings on startup but at this point we don't want to - * assign the keybinding to the menu_item (apply_kb_accel) otherwise it can't be overridden - * by user keybindings anymore */ +/* This is used to set default keybindings on startup. + * Menu accels are set in apply_kb_accel(). */ /** Simple convenience function to fill a GeanyKeyBinding struct item. * @param group Group. * @param key_id Keybinding index for the group. @@ -568,16 +566,6 @@ }
-static void apply_kb_accel(GeanyKeyGroup *group, GeanyKeyBinding *kb, gpointer user_data) -{ - if (kb->key != 0 && kb->menu_item) - { - gtk_widget_add_accelerator(kb->menu_item, "activate", kb_accel_group, - kb->key, kb->mods, GTK_ACCEL_VISIBLE); - } -} - - typedef void (*KBItemCallback) (GeanyKeyGroup *group, GeanyKeyBinding *kb, gpointer user_data);
static void keybindings_foreach(KBItemCallback cb, gpointer user_data) @@ -632,14 +620,22 @@ }
+static void apply_kb_accel(GeanyKeyGroup *group, GeanyKeyBinding *kb, gpointer user_data) +{ + if (kb->key != 0 && kb->menu_item) + { + gtk_widget_add_accelerator(kb->menu_item, "activate", kb_accel_group, + kb->key, kb->mods, GTK_ACCEL_VISIBLE); + } +} + + void keybindings_load_keyfile(void) { load_user_kb(); add_popup_menu_accels();
- /* set menu accels now, after user keybindings have been read and processed - * if we would set it before, user keybindings could not override menu item's default - * keybindings */ + /* set menu accels now, after user keybindings have been read */ keybindings_foreach(apply_kb_accel, NULL); }
@@ -2269,3 +2265,20 @@ } }
+ +/* update key combination */ +void keybindings_update_combo(GeanyKeyBinding *kb, guint key, GdkModifierType mods) +{ + GtkWidget *widget = kb->menu_item; + + if (widget && kb->key) + gtk_widget_remove_accelerator(widget, kb_accel_group, kb->key, kb->mods); + + kb->key = key; + kb->mods = mods; + + if (widget && kb->key) + gtk_widget_add_accelerator(widget, "activate", kb_accel_group, + kb->key, kb->mods, GTK_ACCEL_VISIBLE); +} +
Modified: branches/geany-0.18.1/src/keybindings.h =================================================================== --- branches/geany-0.18.1/src/keybindings.h 2010-01-25 21:15:27 UTC (rev 4557) +++ branches/geany-0.18.1/src/keybindings.h 2010-01-25 21:15:39 UTC (rev 4558) @@ -323,6 +323,8 @@ GeanyKeyCallback callback, guint key, GdkModifierType mod, gchar *name, gchar *label, GtkWidget *menu_item);
+void keybindings_update_combo(GeanyKeyBinding *kb, guint key, GdkModifierType mods); + void keybindings_send_command(guint group_id, guint key_id);
GeanyKeyBinding *keybindings_lookup_item(guint group_id, guint key_id);
Modified: branches/geany-0.18.1/src/prefs.c =================================================================== --- branches/geany-0.18.1/src/prefs.c 2010-01-25 21:15:27 UTC (rev 4557) +++ branches/geany-0.18.1/src/prefs.c 2010-01-25 21:15:39 UTC (rev 4558) @@ -1270,8 +1270,7 @@
/* set the values here, because of the above check, setting it in * gtk_accelerator_parse would return a wrong key combination if it is duplicate */ - kb->key = lkey; - kb->mods = lmods; + keybindings_update_combo(kb, lkey, lmods);
gtk_tree_store_set(store, &iter, KB_TREE_SHORTCUT, new_text, -1);
@@ -1316,8 +1315,7 @@
/* set the values here, because of the above check, setting it in * gtk_accelerator_parse would return a wrong key combination if it is duplicate */ - kb->key = lkey; - kb->mods = lmods; + keybindings_update_combo(kb, lkey, lmods);
gtk_tree_store_set(store, &g_iter, KB_TREE_SHORTCUT, gtk_label_get_text(GTK_LABEL(dialog_label)), -1); @@ -1400,8 +1398,7 @@ _("The combination '%s' is already used for "%s"."), action, kb->label)) { - kb->key = 0; - kb->mods = 0; + keybindings_update_combo(kb, 0, 0); kb_clear_tree_shortcut(g, i); continue; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.