changeset 1658:d7e07c7fa31b

test if an accelerator can be stored gtk_accel_map_change_entry can't change accelerators to keys like arrows. Test this and show the keys in the list only if they can be really changed. https://sourceforge.net/tracker/?func=detail&aid=2805139&group_id=222125&atid=1054680
author nadvornik
date Wed, 24 Jun 2009 20:31:30 +0000
parents 376b63fd9434
children ae9441cb4409
files src/preferences.c
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/preferences.c	Tue Jun 23 19:20:48 2009 +0000
+++ b/src/preferences.c	Wed Jun 24 20:31:30 2009 +0000
@@ -993,11 +993,24 @@
 	GtkTreeModel *model = (GtkTreeModel *)accel_store;
 	GtkTreeIter iter;
 	gchar *acc;
+	gchar *accel_path;
+	GtkAccelKey old_key, key;
 	GtkTreePath *path = gtk_tree_path_new_from_string(path_string);
 
 	gtk_tree_model_get_iter(model, &iter, path);
-	acc = gtk_accelerator_name(accel_key, accel_mods);
+	gtk_tree_model_get(model, &iter, AE_ACCEL, &accel_path, -1);
+
+	/* test if the accelerator can be stored without conflicts*/
+	gtk_accel_map_lookup_entry(accel_path, &old_key);
 
+	/* change the key and read it back (change may fail on keys hardcoded in gtk)*/
+	gtk_accel_map_change_entry(accel_path, accel_key, accel_mods, TRUE); 
+	gtk_accel_map_lookup_entry(accel_path, &key);
+
+	/* restore the original for now, the key will be really changed when the changes are confirmed */
+	gtk_accel_map_change_entry(accel_path, old_key.accel_key, old_key.accel_mods, TRUE); 
+
+	acc = gtk_accelerator_name(key.accel_key, key.accel_mods);
 	gtk_tree_model_foreach(GTK_TREE_MODEL(accel_store), accel_remove_key_cb, acc);
 
 	gtk_tree_store_set(accel_store, &iter, AE_KEY, acc, -1);