[nautilus/search-events-on-view] general: Redirect arrow up/down from search to the view



commit 2cc0f04ffc75bf678a10731ade66732510b5a8e2
Author: Carlos Soriano <csoriano redhat com>
Date:   Mon Oct 1 17:32:33 2018 +0200

    general: Redirect arrow up/down from search to the view
    
    So the user can perform selections.

 src/nautilus-files-view.c   | 18 ++++++++++++++++
 src/nautilus-files-view.h   |  3 +++
 src/nautilus-list-view.c    | 14 +++++++++++++
 src/nautilus-query-editor.c | 48 +++++++++++++++++++++++++++++++++++++++++++
 src/nautilus-view.c         | 16 +++++++++++++++
 src/nautilus-view.h         |  6 ++++++
 src/nautilus-window-slot.c  | 50 +++++++++++++++++++++++++++++++++++++++++++++
 src/nautilus-window.c       |  5 +++--
 8 files changed, 158 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index efec3e662..5df399631 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -1012,6 +1012,22 @@ nautilus_files_view_get_selection (NautilusView *view)
     return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_selection (NAUTILUS_FILES_VIEW (view));
 }
 
+static void
+nautilus_files_view_select_next (NautilusView *view)
+{
+    g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+
+    NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->select_next (NAUTILUS_FILES_VIEW (view));
+}
+
+static void
+nautilus_files_view_select_previous (NautilusView *view)
+{
+    g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+
+    NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->select_previous (NAUTILUS_FILES_VIEW (view));
+}
+
 typedef struct
 {
     NautilusFile *file;
@@ -9375,6 +9391,8 @@ nautilus_files_view_iface_init (NautilusViewInterface *iface)
     iface->set_templates_menu = nautilus_files_view_set_templates_menu;
     iface->get_extensions_background_menu = nautilus_files_view_get_extensions_background_menu;
     iface->set_extensions_background_menu = nautilus_files_view_set_extensions_background_menu;
+    iface->select_next = nautilus_files_view_select_next;
+    iface->select_previous = nautilus_files_view_select_previous;
 }
 
 static void
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index 954101bd6..7024e5982 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -142,6 +142,9 @@ struct _NautilusFilesViewClass {
         void     (* set_selection)           (NautilusFilesView *view,
                                               GList             *selection);
 
+        void           (* select_next)          (NautilusFilesView *view);
+        void           (* select_previous)          (NautilusFilesView *view);
+
         /* invert_selection is a function pointer that subclasses must
          * override to invert selection. */
 
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index b118c785a..1a160ea32 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -2974,6 +2974,18 @@ nautilus_list_view_get_selection_for_file_transfer (NautilusFilesView *view)
     return g_list_reverse (selection_data.list);
 }
 
+static void
+nautilus_list_view_select_next (NautilusFilesView *view)
+{
+    gtk_widget_grab_focus (GTK_WIDGET (view));
+}
+
+static void
+nautilus_list_view_select_previous (NautilusFilesView *view)
+{
+    gtk_widget_grab_focus (GTK_WIDGET (view));
+}
+
 static gboolean
 nautilus_list_view_is_empty (NautilusFilesView *view)
 {
@@ -3985,6 +3997,8 @@ nautilus_list_view_class_init (NautilusListViewClass *class)
     nautilus_files_view_class->get_backing_uri = nautilus_list_view_get_backing_uri;
     nautilus_files_view_class->get_selection = nautilus_list_view_get_selection;
     nautilus_files_view_class->get_selection_for_file_transfer = 
nautilus_list_view_get_selection_for_file_transfer;
+    nautilus_files_view_class->select_next = nautilus_list_view_select_next;
+    nautilus_files_view_class->select_previous = nautilus_list_view_select_previous;
     nautilus_files_view_class->is_empty = nautilus_list_view_is_empty;
     nautilus_files_view_class->remove_file = nautilus_list_view_remove_file;
     nautilus_files_view_class->restore_standard_zoom_level = nautilus_list_view_restore_standard_zoom_level;
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index b95dbe5c8..187bb6da2 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -58,6 +58,8 @@ struct _NautilusQueryEditor
 enum
 {
     ACTIVATED,
+    SELECT_NEXT,
+    SELECT_PREVIOUS,
     CHANGED,
     CANCEL,
     LAST_SIGNAL
@@ -271,6 +273,24 @@ nautilus_query_editor_class_init (NautilusQueryEditorClass *class)
                       g_cclosure_marshal_VOID__VOID,
                       G_TYPE_NONE, 0);
 
+    signals[SELECT_NEXT] =
+        g_signal_new ("select-next",
+                      G_TYPE_FROM_CLASS (class),
+                      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                      0,
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__VOID,
+                      G_TYPE_NONE, 0);
+
+    signals[SELECT_PREVIOUS] =
+        g_signal_new ("select-previous",
+                      G_TYPE_FROM_CLASS (class),
+                      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                      0,
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__VOID,
+                      G_TYPE_NONE, 0);
+
     /**
      * NautilusQueryEditor::location:
      *
@@ -727,8 +747,36 @@ gboolean
 nautilus_query_editor_handle_event (NautilusQueryEditor *self,
                                     GdkEvent            *event)
 {
+    guint keyval;
+    GdkModifierType state;
+
     g_return_val_if_fail (NAUTILUS_IS_QUERY_EDITOR (self), GDK_EVENT_PROPAGATE);
     g_return_val_if_fail (event != NULL, GDK_EVENT_PROPAGATE);
 
+    if (G_UNLIKELY (!gdk_event_get_keyval (event, &keyval)))
+    {
+        g_return_val_if_reached (GDK_EVENT_PROPAGATE);
+    }
+
+    gdk_event_get_state (event, &state);
+
+    /* In the case of key up/down we want to move the focus to the view, since
+     * the user is probably trying to navigate the files
+     */
+    if (gtk_widget_has_focus (GTK_WIDGET (self->entry)))
+    {
+        if (keyval == GDK_KEY_Down)
+        {
+            g_signal_emit (self, signals[SELECT_NEXT], 0);
+            return GDK_EVENT_STOP;
+        }
+
+        if (keyval == GDK_KEY_Up)
+        {
+            g_signal_emit (self, signals[SELECT_PREVIOUS], 0);
+            return GDK_EVENT_STOP;
+        }
+    }
+
     return gtk_search_entry_handle_event (GTK_SEARCH_ENTRY (self->entry), event);
 }
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index e9213e769..de4015698 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -341,3 +341,19 @@ nautilus_view_is_searching (NautilusView *view)
 
     return NAUTILUS_VIEW_GET_IFACE (view)->is_searching (view);
 }
+
+void
+nautilus_view_select_next (NautilusView *view)
+{
+    g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->select_next);
+
+    NAUTILUS_VIEW_GET_IFACE (view)->select_next (view);
+}
+
+void
+nautilus_view_select_previous (NautilusView *view)
+{
+    g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->select_previous);
+
+    NAUTILUS_VIEW_GET_IFACE (view)->select_previous (view);
+}
diff --git a/src/nautilus-view.h b/src/nautilus-view.h
index 16bd471d2..d4c203c2e 100644
--- a/src/nautilus-view.h
+++ b/src/nautilus-view.h
@@ -84,6 +84,9 @@ struct _NautilusViewInterface
 
         /* Whether the current view is searching or not */
         gboolean                        (*is_searching)              (NautilusView         *view);
+
+        void                            (*select_next)               (NautilusView         *view);
+        void                            (*select_previous)           (NautilusView         *view);
 };
 
 GIcon *                        nautilus_view_get_icon                  (guint                 view_id);
@@ -118,4 +121,7 @@ void                           nautilus_view_set_extensions_background_menu (Nau
                                                                              GMenu        *menu);
 GMenu*                         nautilus_view_get_extensions_background_menu (NautilusView *view);
 
+void                           nautilus_view_select_next               (NautilusView        *view);
+void                           nautilus_view_select_previous           (NautilusView        *view);
+
 G_END_DECLS
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index b3a7bc211..4fa80e50d 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -102,6 +102,8 @@ typedef struct
     gulong qe_changed_id;
     gulong qe_cancel_id;
     gulong qe_activated_id;
+    gulong qe_select_next_id;
+    gulong qe_select_previous_id;
 
     GtkLabel *search_info_label;
     GtkRevealer *search_info_label_revealer;
@@ -438,6 +440,32 @@ query_editor_activated_callback (NautilusQueryEditor *editor,
     }
 }
 
+static void
+query_editor_select_next_callback (NautilusQueryEditor *editor,
+                                   NautilusWindowSlot  *self)
+{
+    NautilusWindowSlotPrivate *priv;
+
+    priv = nautilus_window_slot_get_instance_private (self);
+    if (priv->content_view != NULL)
+    {
+        nautilus_view_select_next (NAUTILUS_VIEW (priv->content_view));
+    }
+}
+
+static void
+query_editor_select_previous_callback (NautilusQueryEditor *editor,
+                                       NautilusWindowSlot  *self)
+{
+    NautilusWindowSlotPrivate *priv;
+
+    priv = nautilus_window_slot_get_instance_private (self);
+    if (priv->content_view != NULL)
+    {
+        nautilus_view_select_previous (NAUTILUS_VIEW (priv->content_view));
+    }
+}
+
 static void
 query_editor_changed_callback (NautilusQueryEditor *editor,
                                NautilusQuery       *query,
@@ -476,6 +504,16 @@ hide_query_editor (NautilusWindowSlot *self)
         g_signal_handler_disconnect (priv->query_editor, priv->qe_activated_id);
         priv->qe_activated_id = 0;
     }
+    if (priv->qe_select_next_id > 0)
+    {
+        g_signal_handler_disconnect (priv->query_editor, priv->qe_select_next_id);
+        priv->qe_select_next_id = 0;
+    }
+    if (priv->qe_select_previous_id > 0)
+    {
+        g_signal_handler_disconnect (priv->query_editor, priv->qe_select_previous_id);
+        priv->qe_select_previous_id = 0;
+    }
 
     nautilus_query_editor_set_query (priv->query_editor, NULL);
 
@@ -562,6 +600,18 @@ show_query_editor (NautilusWindowSlot *self)
             g_signal_connect (priv->query_editor, "activated",
                               G_CALLBACK (query_editor_activated_callback), self);
     }
+    if (priv->qe_select_next_id == 0)
+    {
+        priv->qe_select_next_id =
+            g_signal_connect (priv->query_editor, "select-next",
+                              G_CALLBACK (query_editor_select_next_callback), self);
+    }
+    if (priv->qe_select_previous_id == 0)
+    {
+        priv->qe_select_previous_id =
+            g_signal_connect (priv->query_editor, "select-previous",
+                              G_CALLBACK (query_editor_select_previous_callback), self);
+    }
 }
 
 static void
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 0d1234f15..9b3380de6 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -2494,12 +2494,13 @@ nautilus_window_key_press_event (GtkWidget   *widget,
         }
     }
 
-    if (GTK_WIDGET_CLASS (nautilus_window_parent_class)->key_press_event (widget, event))
+    if (nautilus_window_slot_handle_event (window->active_slot, (GdkEvent *) event))
     {
         return GDK_EVENT_STOP;
     }
 
-    if (nautilus_window_slot_handle_event (window->active_slot, (GdkEvent *) event))
+
+    if (GTK_WIDGET_CLASS (nautilus_window_parent_class)->key_press_event (widget, event))
     {
         return GDK_EVENT_STOP;
     }


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