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




commit e78e78dd7efd73abdc08648d630174d9bcb033d6
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 2e26247dc..fd77e2702 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -688,9 +688,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
@@ -700,7 +700,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
@@ -739,7 +742,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.
@@ -748,48 +754,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
@@ -818,6 +782,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]