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




commit 3e8323d09caa544963e246e3e61a682417943a80
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 4776fbe8c..dec9e7fe2 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -678,6 +678,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,
@@ -737,7 +754,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]