[gnome-builder] GbSearchBox: select first row upon GDK_KEY_Down key-press-event
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] GbSearchBox: select first row upon GDK_KEY_Down key-press-event
- Date: Wed, 17 Dec 2014 10:48:18 +0000 (UTC)
commit 79dfebb2242dab8789503414a6d1e24cc066ed65
Author: Christian Hergert <christian hergert me>
Date: Mon Dec 15 17:06:43 2014 -0800
GbSearchBox: select first row upon GDK_KEY_Down key-press-event
src/search/gb-search-box.c | 24 ++++++++++++++++++------
src/search/gb-search-display.c | 27 +++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 6 deletions(-)
---
diff --git a/src/search/gb-search-box.c b/src/search/gb-search-box.c
index ce65649..8a4a87d 100644
--- a/src/search/gb-search-box.c
+++ b/src/search/gb-search-box.c
@@ -166,17 +166,29 @@ gb_search_box_entry_key_press_event (GbSearchBox *box,
g_return_val_if_fail (key, GDK_EVENT_PROPAGATE);
g_return_val_if_fail (GTK_IS_SEARCH_ENTRY (entry), GDK_EVENT_PROPAGATE);
- if (key->keyval == GDK_KEY_Escape)
+ switch (key->keyval)
{
- GtkWidget *toplevel;
+ case GDK_KEY_Escape:
+ {
+ GtkWidget *toplevel;
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (box->priv->button),
- FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (box->priv->button),
+ FALSE);
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
- gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
+ gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
+ return GDK_EVENT_STOP;
+ }
+ break;
+
+ case GDK_KEY_Down:
+ case GDK_KEY_KP_Down:
+ gtk_widget_grab_focus (GTK_WIDGET (box->priv->display));
return GDK_EVENT_STOP;
+
+ default:
+ break;
}
return GDK_EVENT_PROPAGATE;
diff --git a/src/search/gb-search-display.c b/src/search/gb-search-display.c
index d646b65..488e727 100644
--- a/src/search/gb-search-display.c
+++ b/src/search/gb-search-display.c
@@ -202,6 +202,31 @@ gb_search_display_row_activated (GbSearchDisplay *display,
}
static void
+gb_search_display_grab_focus (GtkWidget *widget)
+{
+ GbSearchDisplay *display = (GbSearchDisplay *)widget;
+ GtkListBoxRow *row;
+
+ g_return_if_fail (GB_IS_SEARCH_DISPLAY (display));
+
+ /*
+ * WORKAROUND:
+ *
+ * Getting the row at y of 0 does not work (returns NULL). And getting the
+ * row at index 0 does not take into account sort.
+ *
+ * https://bugzilla.gnome.org/show_bug.cgi?id=741208
+ */
+ row = gtk_list_box_get_row_at_y (display->priv->list_box, 1);
+
+ if (row)
+ {
+ gtk_list_box_select_row (display->priv->list_box, row);
+ gtk_widget_grab_focus (GTK_WIDGET (row));
+ }
+}
+
+static void
gb_search_display_constructed (GObject *object)
{
GbSearchDisplay *self = (GbSearchDisplay *)object;
@@ -276,6 +301,8 @@ gb_search_display_class_init (GbSearchDisplayClass *klass)
object_class->get_property = gb_search_display_get_property;
object_class->set_property = gb_search_display_set_property;
+ widget_class->grab_focus = gb_search_display_grab_focus;
+
gParamSpecs [PROP_CONTEXT] =
g_param_spec_object ("context",
_("Context"),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]