[nautilus/wip/antoniof/gtk4-preparation-step-event-controllers: 27/46] list-view: Remove duplicate click selection code




commit 8727263ccee5d3254793c88cb148b7b52840dda1
Author: António Fernandes <antoniof gnome org>
Date:   Wed Aug 11 23:25:01 2021 +0100

    list-view: Remove duplicate click selection code
    
    Primary and secondary click have similar code for handling selection
    with modifiers, with some corner case inconsistencies.
    
    Unifying the code path resolves the inconsistencies and simplifies the
    code.

 src/nautilus-list-view.c | 57 ++++++++++--------------------------------------
 1 file changed, 11 insertions(+), 46 deletions(-)
---
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 4803f33a9..b7d72c559 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -687,9 +687,9 @@ on_tree_view_multi_press_gesture_pressed (GtkGestureMultiPress *gesture,
 
         gdk_event_get_state (event, &state);
 
-        if (button == GDK_BUTTON_SECONDARY)
+        if (path_selected)
         {
-            if (path_selected)
+            if ((state & GDK_SHIFT_MASK) == 0)
             {
                 /* We're going to filter out some situations where
                  * we can't let the default code run because all
@@ -699,7 +699,10 @@ on_tree_view_multi_press_gesture_pressed (GtkGestureMultiPress *gesture,
                  */
                 call_parent = FALSE;
             }
-            else if ((state & GDK_CONTROL_MASK) != 0)
+        }
+        else
+        {
+            if ((state & GDK_CONTROL_MASK) != 0)
             {
                 /* If CTRL is pressed, we don't allow the parent
                  * class to handle it, since GtkTreeView doesn't
@@ -738,7 +741,10 @@ on_tree_view_multi_press_gesture_pressed (GtkGestureMultiPress *gesture,
                 }
                 g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
             }
-            else if (on_expander)
+
+            if (button == GDK_BUTTON_SECONDARY &&
+                on_expander &&
+                !button_event_modifies_selection (event))
             {
                 /* If the right click happened on an expander, we should
                  * fully change the selection on that row solely.
@@ -747,48 +753,6 @@ on_tree_view_multi_press_gesture_pressed (GtkGestureMultiPress *gesture,
             }
         }
 
-        if ((button == GDK_BUTTON_PRIMARY || button == GDK_BUTTON_MIDDLE) &&
-            ((state & GDK_CONTROL_MASK) != 0 || (state & GDK_SHIFT_MASK) == 0))
-        {
-            view->details->row_selected_on_button_down = path_selected;
-
-            if (path_selected)
-            {
-                call_parent = on_expander;
-            }
-            else if ((state & GDK_CONTROL_MASK) != 0)
-            {
-                call_parent = FALSE;
-                if ((state & GDK_SHIFT_MASK) != 0)
-                {
-                    gtk_tree_view_get_cursor (tree_view, &cursor, NULL);
-                    if (cursor != NULL)
-                    {
-                        gtk_tree_selection_select_range (selection, cursor, path);
-                    }
-                    else
-                    {
-                        gtk_tree_selection_select_path (selection, path);
-                    }
-                }
-                else
-                {
-                    gtk_tree_selection_select_path (selection, path);
-                }
-                selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
-
-                /* This unselects everything */
-                gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
-
-                /* So select it again */
-                for (GList *l = selected_rows; l != NULL; l = l->next)
-                {
-                    gtk_tree_selection_select_path (selection, l->data);
-                }
-                g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
-            }
-        }
-
         if (is_simple_click && on_expander)
         {
             /* Need to let the event propagate down, since propagating up
@@ -817,6 +781,7 @@ on_tree_view_multi_press_gesture_pressed (GtkGestureMultiPress *gesture,
             view->details->drag_button = button;
             view->details->drag_x = bin_x;
             view->details->drag_y = bin_y;
+            view->details->row_selected_on_button_down = path_selected;
         }
 
         if (button == GDK_BUTTON_SECONDARY)


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