SF.net SVN: geany:[4105] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Tue Aug 18 13:57:08 UTC 2009


Revision: 4105
          http://geany.svn.sourceforge.net/geany/?rev=4105&view=rev
Author:   ntrel
Date:     2009-08-18 13:57:07 +0000 (Tue, 18 Aug 2009)

Log Message:
-----------
Fix updating main menu accelerators after changing keybindings
(thanks to Lex Trotman).

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/keybindings.c
    trunk/src/keybindings.h
    trunk/src/prefs.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-08-18 13:47:29 UTC (rev 4104)
+++ trunk/ChangeLog	2009-08-18 13:57:07 UTC (rev 4105)
@@ -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: trunk/src/keybindings.c
===================================================================
--- trunk/src/keybindings.c	2009-08-18 13:47:29 UTC (rev 4104)
+++ trunk/src/keybindings.c	2009-08-18 13:57:07 UTC (rev 4105)
@@ -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: trunk/src/keybindings.h
===================================================================
--- trunk/src/keybindings.h	2009-08-18 13:47:29 UTC (rev 4104)
+++ trunk/src/keybindings.h	2009-08-18 13:57:07 UTC (rev 4105)
@@ -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: trunk/src/prefs.c
===================================================================
--- trunk/src/prefs.c	2009-08-18 13:47:29 UTC (rev 4104)
+++ trunk/src/prefs.c	2009-08-18 13:57:07 UTC (rev 4105)
@@ -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.



More information about the Commits mailing list