SF.net SVN: geany:[5225] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Mon Sep 13 15:37:46 UTC 2010


Revision: 5225
          http://geany.svn.sourceforge.net/geany/?rev=5225&view=rev
Author:   ntrel
Date:     2010-09-13 15:37:46 +0000 (Mon, 13 Sep 2010)

Log Message:
-----------
Simplify keybindings_check_event().

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

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2010-09-13 15:03:18 UTC (rev 5224)
+++ trunk/ChangeLog	2010-09-13 15:37:46 UTC (rev 5225)
@@ -8,6 +8,8 @@
  * src/tools.c, src/search.c, tagmanager/python.c:
    Fix some 'possible' NULL pointer dereferences (based on patch by
    Erik de Castro Lopo).
+ * src/keybindings.c, src/keybindings.h, src/prefs.c:
+   Simplify keybindings_check_event().
 
 
 2010-09-09  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>

Modified: trunk/src/keybindings.c
===================================================================
--- trunk/src/keybindings.c	2010-09-13 15:03:18 UTC (rev 5224)
+++ trunk/src/keybindings.c	2010-09-13 15:37:46 UTC (rev 5225)
@@ -1137,17 +1137,10 @@
 }
 
 
-/* Stripped down version of the main keypress event handler which can be used
- * to process foreign events. Instead of executing the keybinding, a pointer to the
- * keybinding structure is returned.
- * Additionally, the group_id and binding_id are filled with the appropriate indexes
- * if non-NULL. */
-const GeanyKeyBinding *keybindings_check_event(GdkEventKey *ev, gint *group_id, gint *binding_id)
+/* Check if event keypress matches keybinding combo */
+gboolean keybindings_check_event(GdkEventKey *ev, GeanyKeyBinding *kb)
 {
 	guint state, keyval;
-	gsize g, i;
-	GeanyKeyGroup *group;
-	GeanyKeyBinding *kb;
 
 	if (ev->keyval == 0)
 		return FALSE;
@@ -1162,21 +1155,7 @@
 	if (keyval >= GDK_KP_Space && keyval < GDK_KP_Equal)
 		keyval = key_kp_translate(keyval);
 
-	foreach_ptr_array(group, g, keybinding_groups)
-	{
-		foreach_ptr_array(kb, i, group->key_items)
-		{
-			if (keyval == kb->key && state == kb->mods)
-			{
-				if (group_id != NULL)
-					*group_id = g;
-				if (binding_id != NULL)
-					*binding_id = kb->id;
-				return kb;
-			}
-		}
-	}
-	return NULL;
+	return (keyval == kb->key && state == kb->mods);
 }
 
 

Modified: trunk/src/keybindings.h
===================================================================
--- trunk/src/keybindings.h	2010-09-13 15:03:18 UTC (rev 5224)
+++ trunk/src/keybindings.h	2010-09-13 15:37:46 UTC (rev 5225)
@@ -270,7 +270,7 @@
 
 void keybindings_show_shortcuts(void);
 
-const GeanyKeyBinding *keybindings_check_event(GdkEventKey *ev, gint *group_id, gint *binding_id);
+gboolean keybindings_check_event(GdkEventKey *ev, GeanyKeyBinding *kb);
 
 #endif
 

Modified: trunk/src/prefs.c
===================================================================
--- trunk/src/prefs.c	2010-09-13 15:03:18 UTC (rev 5224)
+++ trunk/src/prefs.c	2010-09-13 15:37:46 UTC (rev 5225)
@@ -1535,15 +1535,12 @@
 static gboolean prefs_dialog_key_press_response_cb(GtkWidget *dialog, GdkEventKey *event,
 												   gpointer data)
 {
-	gint group, keybinding;
+	GeanyKeyBinding *kb = keybindings_lookup_item(GEANY_KEY_GROUP_HELP, GEANY_KEYS_HELP_HELP);
 
-	if (keybindings_check_event(event, &group, &keybinding) != NULL)
+	if (keybindings_check_event(event, kb))
 	{
-		if (group == GEANY_KEY_GROUP_HELP && keybinding == GEANY_KEYS_HELP_HELP)
-		{
-			open_preferences_help();
-			return TRUE;
-		}
+		open_preferences_help();
+		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