pidgin: 391fafa6: Allow rebinding keys to change the focus...

sadrul at pidgin.im sadrul at pidgin.im
Tue Jan 13 18:17:24 EST 2009


-----------------------------------------------------------------
Revision: 391fafa6e18ef27d4b95b4ba37421c35e08caa25
Ancestor: dd0cadddab583bee3376839f4ebac42f28f5fc1a
Author: sadrul at pidgin.im
Date: 2009-01-13T23:13:32
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/391fafa6e18ef27d4b95b4ba37421c35e08caa25

Modified files:
        ChangeLog doc/finch.1.in finch/libgnt/gntbox.c

ChangeLog: 

Allow rebinding keys to change the focused widget.

-------------- next part --------------
============================================================
--- ChangeLog	85d5f64a1282d214ae1a24c150d9423b70feca32
+++ ChangeLog	1ccf818568a6da6d2a969a75a2fcafc28ee86cf2
@@ -1,5 +1,10 @@ Pidgin and Finch: The Pimpin' Penguin IM
 Pidgin and Finch: The Pimpin' Penguin IM Clients That're Good for the Soul
 
+version 2.5.5 (??/??/????):
+	Finch:
+	* Allow rebinding keys to change the focused widget (details in the
+	  man-page, look for GntBox::binding)
+
 version 2.5.4 (01/12/2009):
 	libpurple:
 	* Fix a connection timeout with empty Gadu-Gady buddy lists. (Martin
============================================================
--- doc/finch.1.in	b12643c7d316235a1993f35bb6f1abd861b0bfde
+++ doc/finch.1.in	ed5f32a225d699f813664da25e5f86471abdd7bf
@@ -296,6 +296,15 @@ You can specifiy key-bindings for specif
 \fI~/.gntrc\fR correspond to the default keybindings for the actions:
 
 .br
+[GntBox::binding]
+.br
+tab = focus-next
+.br
+right = focus-next
+.br
+left = focus-prev
+
+.br
 [GntEntry::binding]
 .br
 c-a = cursor-home
============================================================
--- finch/libgnt/gntbox.c	90cc33e4d8c0c5ace1ecccd74a908441df3531ce
+++ finch/libgnt/gntbox.c	4530ea159e8499872d4f07760efaaa439ec7d8f7
@@ -21,6 +21,7 @@
  */
 
 #include "gntbox.h"
+#include "gntstyle.h"
 #include "gntutils.h"
 
 #include <string.h>
@@ -304,38 +305,38 @@ gnt_box_key_pressed(GntWidget *widget, c
 gnt_box_key_pressed(GntWidget *widget, const char *text)
 {
 	GntBox *box = GNT_BOX(widget);
-	GntWidget *now;
+	gboolean ret;
 
+	if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_DISABLE_ACTIONS))
+		return FALSE;
+
 	if (box->active == NULL && !find_focusable_widget(box))
 		return FALSE;
 
 	if (gnt_widget_key_pressed(box->active, text))
 		return TRUE;
-	
+
+	/* This dance is necessary to make sure that the child widgets get a chance
+	   to trigger their bindings first */
+	GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_DISABLE_ACTIONS);
+	ret = gnt_widget_key_pressed(widget, text);
+	GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_DISABLE_ACTIONS);
+	return ret;
+}
+
+static gboolean
+box_focus_change(GntBox *box, gboolean next)
+{
+	GntWidget *now;
 	now = box->active;
 
-	if (text[0] == 27)
-	{
-		if (strcmp(text, GNT_KEY_LEFT) == 0)
-		{
-			find_prev_focus(box);
-		}
-		else if (strcmp(text, GNT_KEY_RIGHT) == 0)
-		{
-			find_next_focus(box);
-		}
-		else if (strcmp(text, GNT_KEY_BACK_TAB) == 0)
-		{
-			find_prev_focus(box);
-		}
-	}
-	else if (text[0] == '\t')
-	{
+	if (next) {
 		find_next_focus(box);
+	} else {
+		find_prev_focus(box);
 	}
 
-	if (now && now != box->active)
-	{
+	if (now && now != box->active) {
 		gnt_widget_set_focus(now, FALSE);
 		gnt_widget_set_focus(box->active, TRUE);
 		return TRUE;
@@ -344,6 +345,18 @@ gnt_box_key_pressed(GntWidget *widget, c
 	return FALSE;
 }
 
+static gboolean
+action_focus_next(GntBindable *bindable, GList *null)
+{
+	return box_focus_change(GNT_BOX(bindable), TRUE);
+}
+
+static gboolean
+action_focus_prev(GntBindable *bindable, GList *null)
+{
+	return box_focus_change(GNT_BOX(bindable), FALSE);
+}
+
 static void
 gnt_box_lost_focus(GntWidget *widget)
 {
@@ -556,6 +569,7 @@ gnt_box_class_init(GntBoxClass *klass)
 static void
 gnt_box_class_init(GntBoxClass *klass)
 {
+	GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
 	GObjectClass *gclass = G_OBJECT_CLASS(klass);
 	parent_class = GNT_WIDGET_CLASS(klass);
 	parent_class->destroy = gnt_box_destroy;
@@ -589,6 +603,15 @@ gnt_box_class_init(GntBoxClass *klass)
 				G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
 			)
 		);
+
+	gnt_bindable_class_register_action(bindable, "focus-next", action_focus_next,
+			"\t", NULL);
+	gnt_bindable_register_binding(bindable, "focus-next", GNT_KEY_RIGHT, NULL);
+	gnt_bindable_class_register_action(bindable, "focus-prev", action_focus_prev,
+			GNT_KEY_BACK_TAB, NULL);
+	gnt_bindable_register_binding(bindable, "focus-prev", GNT_KEY_LEFT, NULL);
+
+	gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable);
 }
 
 static void
@@ -599,7 +622,7 @@ gnt_box_init(GTypeInstance *instance, gp
 	/* Initially make both the height and width resizable.
 	 * Update the flags as necessary when widgets are added to it. */
 	GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y);
-	GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS);
+	GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_DISABLE_ACTIONS);
 	GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
 	box->pad = 1;
 	box->fill = TRUE;


More information about the Commits mailing list