[nautilus/wip/antoniof/flow-box-preparation: 13/14] view-icon-controller: Open new tab with middle click




commit 5fca97cb1a1dd0db18e0467a30bb8fed2dc084e1
Author: António Fernandes <antoniof gnome org>
Date:   Thu Dec 9 18:47:33 2021 +0000

    view-icon-controller: Open new tab with middle click
    
    And also with double-click while holding SHIFT, matching old views.
    
    The GtkFlowBox::child-activated signal is no longer going to be used
    for activation on click, as it doesn't provide the event data we need,
    namely button, modifiers, and number of clicks.
    
    While we *can* get that information thanks to gtk_get_current_event(),
    this function is going away with GTK 4, so let's not increase our
    reliance on it any more.
    
    Instead, implement a new activation helper for usage with gestures.

 src/nautilus-view-icon-controller.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index a864c029a..6fa7c74f0 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -700,6 +700,23 @@ real_click_policy_changed (NautilusFilesView *files_view)
 {
 }
 
+static void
+activate_selection_on_click (NautilusViewIconController *self,
+                             gboolean                    open_in_new_tab)
+{
+    g_autolist (NautilusFile) selection = NULL;
+    NautilusWindowOpenFlags flags = 0;
+    NautilusFilesView *files_view = NAUTILUS_FILES_VIEW (self);
+
+    selection = nautilus_view_get_selection (NAUTILUS_VIEW (self));
+    if (open_in_new_tab)
+    {
+        flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
+        flags |= NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE;
+    }
+    nautilus_files_view_activate_files (files_view, selection, flags, TRUE);
+}
+
 static void
 on_button_press_event (GtkGestureMultiPress *gesture,
                        gint                  n_press,
@@ -759,7 +776,17 @@ on_button_press_event (GtkGestureMultiPress *gesture,
             }
         }
 
-        if (button == GDK_BUTTON_SECONDARY)
+        if (button == GDK_BUTTON_PRIMARY && n_press == 2)
+        {
+            activate_selection_on_click (self, modifiers & GDK_SHIFT_MASK);
+            gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
+        }
+        else if (button == GDK_BUTTON_MIDDLE && n_press == 1 && !selection_mode)
+        {
+            activate_selection_on_click (self, TRUE);
+            gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
+        }
+        else if (button == GDK_BUTTON_SECONDARY)
         {
             nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (self),
                                                                event);


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