SF.net SVN: geany: [380] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Tue May 30 19:19:11 UTC 2006


Revision: 380
Author:   eht16
Date:     2006-05-30 12:19:05 -0700 (Tue, 30 May 2006)
ViewCVS:  http://svn.sourceforge.net/geany/?rev=380&view=rev

Log Message:
-----------
Detect duplicate shortcuts and prevent saving them.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/prefs.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-05-30 18:03:19 UTC (rev 379)
+++ trunk/ChangeLog	2006-05-30 19:19:05 UTC (rev 380)
@@ -14,6 +14,7 @@
                 improved utils_replace_tabs().
  * src/keybindings.c: Added shortcut for Replace Tabs by Space,
                       extend usage of GEANY_ADD_ACCEL macro.
+ * src/prefs.c: Detect duplicate shortcuts and prevent saving them.
 
 
 2006-05-29  Enrico Troeger  <enrico.troeger at uvena.de>

Modified: trunk/src/prefs.c
===================================================================
--- trunk/src/prefs.c	2006-05-30 18:03:19 UTC (rev 379)
+++ trunk/src/prefs.c	2006-05-30 19:19:05 UTC (rev 380)
@@ -27,6 +27,7 @@
 
 #include "prefs.h"
 #include "support.h"
+#include "dialogs.h"
 #include "utils.h"
 #include "msgwindow.h"
 #include "sciwrappers.h"
@@ -51,6 +52,7 @@
 static void on_cell_edited(GtkCellRendererText *cellrenderertext, gchar *path, gchar *new_text, gpointer user_data);
 static gboolean on_keytype_dialog_response(GtkWidget *dialog, GdkEventKey *event, gpointer user_data);
 static void on_dialog_response(GtkWidget *dialog, gint response, gpointer user_data);
+static gboolean find_duplicate(guint idx, guint key, GdkModifierType mods, const gchar *action);
 
 
 void prefs_init_dialog(void)
@@ -198,6 +200,12 @@
 		column = gtk_tree_view_column_new_with_attributes(_("Shortcut"), renderer, "text", 1, NULL);
 		gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
 
+		// set policy settings for the scollwedwindow around the treeview again, because glade
+		// doesn't keep the settings
+		gtk_scrolled_window_set_policy(
+				GTK_SCROLLED_WINDOW(lookup_widget(app->prefs_dialog, "scrolledwindow8")),
+				GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
 		g_signal_connect(G_OBJECT(renderer), "edited", G_CALLBACK(on_cell_edited), NULL);
 		g_signal_connect(G_OBJECT(tree), "button-press-event",
 					G_CALLBACK(on_prefs_tree_view_button_press_event), NULL);
@@ -587,6 +595,8 @@
 	if (path != NULL && new_text != NULL)
 	{
 		guint idx;
+		guint lkey;
+		GdkModifierType lmods;
 		gchar *test;
 		GtkTreeIter iter;
 
@@ -594,8 +604,15 @@
 		idx = strtol(path, &test, 10);
 		if (test == path) return;
 
-		gtk_accelerator_parse(new_text, &(keys[idx]->key), &(keys[idx]->mods));
+		gtk_accelerator_parse(new_text, &lkey, &lmods);
 
+		if (find_duplicate(idx, lkey, lmods, new_text)) return;
+
+		// 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
+		keys[idx]->key = lkey;
+		keys[idx]->mods = lmods;
+
 		gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter, path);
 		gtk_list_store_set(store, &iter, 1, new_text, -1);
 
@@ -604,7 +621,6 @@
 }
 
 
-
 static gboolean on_keytype_dialog_response(GtkWidget *dialog, GdkEventKey *event, gpointer user_data)
 {
 	gchar *str;
@@ -627,6 +643,8 @@
 	{
 		GtkTreeIter iter;
 		guint idx;
+		guint lkey;
+		GdkModifierType lmods;
 		gchar path[3];
 
 		for (idx = 0; idx < GEANY_MAX_KEYS; idx++)
@@ -634,15 +652,49 @@
 			if (utils_strcmp(dialog_key_name, keys[idx]->name)) break;
 		}
 
-		gtk_accelerator_parse(gtk_label_get_text(GTK_LABEL(dialog_label)), &(keys[idx]->key), &(keys[idx]->mods));
+		gtk_accelerator_parse(gtk_label_get_text(GTK_LABEL(dialog_label)), &lkey, &lmods);
 
+		if (find_duplicate(idx, lkey, lmods, gtk_label_get_text(GTK_LABEL(dialog_label)))) return;
+
+		// 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
+		keys[idx]->key = lkey;
+		keys[idx]->mods = lmods;
+
 		// generate the path, it is exactly the index
 		g_snprintf(path, 3, "%d", idx);
 		gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter, path);
 		gtk_list_store_set(store, &iter, 1, gtk_label_get_text(GTK_LABEL(dialog_label)), -1);
 		g_free(dialog_key_name);
+		dialog_key_name = NULL;
 
 		edited = TRUE;
 	}
 	gtk_widget_destroy(dialog);
 }
+
+
+// test if the entered key combination is already used
+static gboolean find_duplicate(guint idx, guint key, GdkModifierType mods, const gchar *action)
+{
+	guint i;
+
+	// allow duplicate if there is no key combination
+	if (key == 0 && mods == 0) return FALSE;
+
+	for (i = 0; i < GEANY_MAX_KEYS; i++)
+	{
+		// search another item with the same key, but take not the key we are searching for(-> idx)
+		if (keys[i]->key == key && keys[i]->mods == mods
+			&& ! (keys[i]->key == keys[idx]->key && keys[i]->mods == keys[idx]->mods))
+		{
+			dialogs_show_error(
+				_("The combination '%s' is already used for \"%s\". Please choose another one."),
+				action, keys[i]->name);
+			return TRUE;
+		}
+	}
+	return FALSE;
+}
+
+


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