[recipes] Improve keynav in the search filter popover



commit 2e1fe0e3cfbfc42397ca178ef0765c7d3d145496
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Dec 25 19:02:46 2016 -0500

    Improve keynav in the search filter popover
    
    Alt-Down now opens the popover if the search bar is visible,
    and if the ingredients filter entry is unveiled in the popover,
    it will get focused upon key press.

 src/gr-query-editor.c  |   25 +++++++++++++++++++++++++
 src/gr-query-editor.h  |    3 +++
 src/gr-query-editor.ui |    2 +-
 src/gr-window.c        |    2 +-
 4 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/src/gr-query-editor.c b/src/gr-query-editor.c
index 289962c..448de5e 100644
--- a/src/gr-query-editor.c
+++ b/src/gr-query-editor.c
@@ -925,3 +925,28 @@ gr_query_editor_set_query (GrQueryEditor *editor,
 
         g_signal_emit_by_name (editor->entry, "search-changed", 0);
 }
+
+gboolean
+gr_query_editor_handle_event (GrQueryEditor *editor,
+                              GdkEvent      *event)
+{
+        if (gtk_widget_is_visible (editor->popover)) {
+                if (gtk_revealer_get_child_revealed (GTK_REVEALER (editor->ing_search_revealer))) {
+                        gtk_widget_grab_focus (editor->ing_filter_entry);
+
+                        return gtk_widget_event (editor->ing_filter_entry, event);
+                }
+
+                return GDK_EVENT_PROPAGATE;
+        }
+
+        if (event->type == GDK_KEY_PRESS) {
+                GdkEventKey *e = (GdkEventKey *) event;
+                if ((e->state & GDK_MOD1_MASK) > 0 && e->keyval == GDK_KEY_Down) {
+                        gtk_popover_popup (GTK_POPOVER (editor->popover));
+                        return GDK_EVENT_PROPAGATE;
+                }
+        }
+
+   return gtk_search_bar_handle_event (GTK_SEARCH_BAR (editor), event);
+}
diff --git a/src/gr-query-editor.h b/src/gr-query-editor.h
index 66a4115..0934c36 100644
--- a/src/gr-query-editor.h
+++ b/src/gr-query-editor.h
@@ -34,4 +34,7 @@ char *         gr_query_editor_get_query (GrQueryEditor *editor);
 void           gr_query_editor_set_query (GrQueryEditor *editor,
                                           const char    *query);
 
+gboolean       gr_query_editor_handle_event (GrQueryEditor *editor,
+                                             GdkEvent      *event);
+
 G_END_DECLS
diff --git a/src/gr-query-editor.ui b/src/gr-query-editor.ui
index 8f70a87..4222fb6 100644
--- a/src/gr-query-editor.ui
+++ b/src/gr-query-editor.ui
@@ -30,7 +30,7 @@
     </child>
   </template>
   <object class="GtkPopover" id="popover">
-    <property name="modal">0</property>
+    <property name="modal">1</property>
     <property name="position">bottom</property>
     <property name="width-request">250</property>
     <signal name="notify::visible" handler="search_popover_notify"/>
diff --git a/src/gr-window.c b/src/gr-window.c
index 7f64ca7..06cd780 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -296,7 +296,7 @@ window_keypress_handler (GtkWidget *widget,
                 }
         }
 
-        return gtk_search_bar_handle_event (GTK_SEARCH_BAR (window->search_bar), event);
+        return gr_query_editor_handle_event (GR_QUERY_EDITOR (window->search_bar), event);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]