changeset 30194:6943aec8cf61

Allow rebinding the key to show the dropdown menu for comboboxes.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 15 Jun 2010 17:12:48 +0000
parents b3c4f33643a6
children d78a3f06b7a0
files ChangeLog doc/finch.1.in finch/libgnt/gntcombobox.c
diffstat 3 files changed, 30 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Jun 15 17:11:15 2010 +0000
+++ b/ChangeLog	Tue Jun 15 17:12:48 2010 +0000
@@ -8,8 +8,10 @@
 	* Re-focus the input area after clicking the attention toolbar button.
 
 	Finch:
-	* Rebindable suggest-next-page and suggest-prev-page actions for
+	* Rebindable 'suggest-next-page' and 'suggest-prev-page' actions for
 	  textboxes (GntEntry) to scroll through list of suggestions.
+	* Rebindable 'dropdown' action for comboboxes (GntComboBox) to show the
+	  dropdown list of options.
 
 	XMPP:
 	* Allow connecting to servers that only advertise GSSAPI and expect
--- a/doc/finch.1.in	Tue Jun 15 17:11:15 2010 +0000
+++ b/doc/finch.1.in	Tue Jun 15 17:12:48 2010 +0000
@@ -305,6 +305,13 @@
 left = focus-prev
 
 .br
+[GntComboBox::binding]
+.br
+down = dropdown
+.br
+up = dropdown
+
+.br
 [GntEntry::binding]
 .br
 c-a = cursor-home
--- a/finch/libgnt/gntcombobox.c	Tue Jun 15 17:11:15 2010 +0000
+++ b/finch/libgnt/gntcombobox.c	Tue Jun 15 17:12:48 2010 +0000
@@ -25,6 +25,7 @@
 #include "gntcombobox.h"
 #include "gnttree.h"
 #include "gntmarshal.h"
+#include "gntstyle.h"
 #include "gntutils.h"
 
 #include <string.h>
@@ -168,18 +169,6 @@
 		if (gnt_widget_key_pressed(box->dropdown, text))
 			return TRUE;
 	}
-	else
-	{
-		if (text[0] == 27)
-		{
-			if (strcmp(text, GNT_KEY_UP) == 0 ||
-					strcmp(text, GNT_KEY_DOWN) == 0)
-			{
-				popup_dropdown(box);
-				return TRUE;
-			}
-		}
-	}
 
 	return FALSE;
 }
@@ -229,9 +218,20 @@
 	gnt_widget_set_size(box->dropdown, widget->priv.width - 1, box->dropdown->priv.height);
 }
 
+static gboolean
+dropdown_menu(GntBindable *b, GList *null)
+{
+	if (GNT_WIDGET_IS_FLAG_SET(GNT_COMBO_BOX(b)->dropdown->parent, GNT_WIDGET_MAPPED))
+		return FALSE;
+	popup_dropdown(GNT_COMBO_BOX(b));
+	return TRUE;
+}
+
 static void
 gnt_combo_box_class_init(GntComboBoxClass *klass)
 {
+	GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
+
 	parent_class = GNT_WIDGET_CLASS(klass);
 
 	parent_class->destroy = gnt_combo_box_destroy;
@@ -245,7 +245,7 @@
 	widget_lost_focus = parent_class->lost_focus;
 	parent_class->lost_focus = gnt_combo_box_lost_focus;
 
-	signals[SIG_SELECTION_CHANGED] = 
+	signals[SIG_SELECTION_CHANGED] =
 		g_signal_new("selection-changed",
 					 G_TYPE_FROM_CLASS(klass),
 					 G_SIGNAL_RUN_LAST,
@@ -254,6 +254,12 @@
 					 gnt_closure_marshal_VOID__POINTER_POINTER,
 					 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER);
 
+	gnt_bindable_class_register_action(bindable, "dropdown", dropdown_menu,
+			GNT_KEY_DOWN, NULL);
+	gnt_bindable_register_binding(bindable, "dropdown", GNT_KEY_UP, NULL);
+
+	gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable);
+
 	GNTDEBUG;
 }
 
@@ -272,7 +278,7 @@
 	GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER | GNT_WIDGET_TRANSIENT);
 	gnt_box_set_pad(GNT_BOX(box), 0);
 	gnt_box_add_widget(GNT_BOX(box), combo->dropdown);
-	
+
 	widget->priv.minw = 4;
 	widget->priv.minh = 3;
 	GNTDEBUG;