[nautilus/search-events-on-the-view] Handle selection events from the search on the view



commit fcbd86df0fd3e7f08213339883cc430b48c7bc70
Author: Carlos Soriano <csoriano redhat com>
Date:   Thu Sep 27 17:32:32 2018 +0200

    Handle selection events from the search on the view

 src/nautilus-files-view.c   | 29 ++++++++++++++++++++++++++
 src/nautilus-files-view.h   |  3 +++
 src/nautilus-list-view.c    |  9 ++++++++
 src/nautilus-query-editor.c | 41 ++++++++++++++++++++++++++++++++++++
 src/nautilus-view.c         | 16 ++++++++++++++
 src/nautilus-view.h         |  6 ++++++
 src/nautilus-window-slot.c  | 51 +++++++++++++++++++++++++++++++++++++++++++++
 src/nautilus-window.c       | 18 ++++++++++++++--
 8 files changed, 171 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index efec3e662..5fc9aa7dd 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -973,6 +973,18 @@ nautilus_files_view_is_searching (NautilusView *view)
     return NAUTILUS_IS_SEARCH_DIRECTORY (priv->model);
 }
 
+gboolean
+nautilus_files_view_handle_event (NautilusView *view,
+                                  GdkEvent     *event)
+{
+    NautilusFilesView *files_view;
+    NautilusFilesViewPrivate *priv;
+
+    files_view = NAUTILUS_FILES_VIEW (view);
+    priv = nautilus_files_view_get_instance_private (files_view);
+
+}
+
 guint
 nautilus_files_view_get_view_id (NautilusView *view)
 {
@@ -1012,6 +1024,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 +9403,7 @@ 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->handle_event = nautilus_files_view_handle_event;
 }
 
 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..0a1203dc3 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -907,6 +907,7 @@ key_press_callback (GtkWidget *widget,
     NAUTILUS_LIST_VIEW (view)->details->last_event_button_x = -1;
     NAUTILUS_LIST_VIEW (view)->details->last_event_button_y = -1;
 
+    g_print ("handling event in list view\n");
     if (G_UNLIKELY (!gdk_event_get_keyval (event, &keyval)))
     {
         g_return_val_if_reached (GDK_EVENT_PROPAGATE);
@@ -2974,6 +2975,12 @@ 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)
+{
+
+}
+
 static gboolean
 nautilus_list_view_is_empty (NautilusFilesView *view)
 {
@@ -3985,6 +3992,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..21d2b5b9f 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -58,6 +58,8 @@ struct _NautilusQueryEditor
 enum
 {
     ACTIVATED,
+    SELECT_NEXT_PRESSED,
+    SELECT_PREVIOUS_PRESSED,
     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_PRESSED] =
+        g_signal_new ("select-next-pressed",
+                      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_PRESSED] =
+        g_signal_new ("select-previous-pressed",
+                      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,29 @@ 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);
+
+    if (keyval == GDK_KEY_Down)
+    {
+        g_signal_emit (self, signals[SELECT_NEXT_PRESSED], 0);
+        return GDK_EVENT_STOP;
+    }
+
+    if (keyval == GDK_KEY_Up)
+    {
+        g_signal_emit (self, signals[SELECT_PREVIOUS_PRESSED], 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..fb69f04ee 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);
+
+    return 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);
+
+    return NAUTILUS_VIEW_GET_IFACE (view)->select_previous (view);
+}
diff --git a/src/nautilus-view.h b/src/nautilus-view.h
index 16bd471d2..1ef52a5a2 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);
+
+        gboolean                        (*select_next)               (NautilusView         *view);
+        gboolean                        (*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);
 
+gboolean                       nautilus_view_select_next               (NautilusView        *view);
+gboolean                       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..5cf85b380 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_previous_next (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
@@ -646,6 +696,7 @@ nautilus_window_slot_handle_event (NautilusWindowSlot *self,
         g_return_val_if_reached (GDK_EVENT_PROPAGATE);
     }
 
+    g_print("###handle event slot inside\n");
     if (keyval == GDK_KEY_Escape)
     {
         g_autoptr (GVariant) state = NULL;
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 0d1234f15..e7bd8f8fd 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -37,6 +37,8 @@
 #include <math.h>
 #include <sys/time.h>
 
+#include <libgd/gd.h>
+
 #define DEBUG_FLAG NAUTILUS_DEBUG_WINDOW
 #include "nautilus-debug.h"
 
@@ -2462,17 +2464,26 @@ nautilus_window_key_press_event (GtkWidget   *widget,
         g_return_val_if_reached (GDK_EVENT_PROPAGATE);
     }
 
+    g_print ("window key press event\n");
+
     focus_widget = gtk_window_get_focus (GTK_WINDOW (window));
     if (focus_widget != NULL && GTK_IS_EDITABLE (focus_widget))
     {
         /* if we have input focus on a GtkEditable (e.g. a GtkEntry), forward
          * the event to it before activating accelerator bindings too.
          */
+    g_print ("is editable\n");
         if (gtk_window_propagate_key_event (GTK_WINDOW (window),
                                             (GdkEventKey *) event))
         {
+    g_print ("is propagated window key event\n");
             return GDK_EVENT_STOP;
         }
+
+        if (GD_IS_TAGGED_ENTRY (focus_widget))
+        {
+            g_print("is tagged entry\n");
+        }
     }
 
     for (int i = 0; i < G_N_ELEMENTS (extra_window_keybindings); i++)
@@ -2494,13 +2505,16 @@ 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))
     {
+        g_print("handling it in the slot\n");
         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))
     {
+        g_print ("handling key event in key_press_event class\n");
         return GDK_EVENT_STOP;
     }
 


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