[nautilus/wip/corey/list-view: 21/21] list-base: Apply focus workaround to all item selection




commit 2ac420316bd9c8560fa2cdeba0e5f5b0092243b7
Author: Corey Berla <corey berla me>
Date:   Mon Aug 22 11:15:42 2022 -0700

    list-base: Apply focus workaround to all item selection
    
    We have a workaround to fix the focused item in certain circumstances
    and not others.  Abstract it out and apply to
    select_single_item_if_not_selected ().

 src/nautilus-list-base.c | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)
---
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c
index 54ac19473..568070d1b 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -235,6 +235,30 @@ nautilus_list_base_set_icon_size (NautilusListBase *self,
     }
 }
 
+static void
+set_focus_item (NautilusListBase *self,
+                NautilusViewItem *item)
+{
+    NautilusListBasePrivate *priv = nautilus_list_base_get_instance_private (self);
+    GtkWidget *item_widget = nautilus_view_item_get_item_ui (item);
+    GtkWidget *parent = gtk_widget_get_parent (item_widget);
+
+    if (!gtk_widget_grab_focus (parent))
+    {
+        /* In GtkColumnView, the parent is a cell; its parent is the row. */
+        gtk_widget_grab_focus (gtk_widget_get_parent (parent));
+    }
+
+    /* HACK: Grabbing focus is not enough for the listbase item tracker to
+     * acknowledge it. So, poke the internal actions to fix the bug reported
+     * in https://gitlab.gnome.org/GNOME/nautilus/-/issues/2294 */
+    gtk_widget_activate_action (item_widget,
+                                "list.select-item",
+                                "(ubb)",
+                                nautilus_view_model_get_index (priv->model, item),
+                                FALSE, FALSE);
+}
+
 /* GtkListBase changes selection only with the primary button, and only after
  * release. But we need to anticipate selection earlier if we are to activate it
  * or open its context menu. This helper should be used in these situations if
@@ -251,6 +275,7 @@ select_single_item_if_not_selected (NautilusListBase *self,
     if (!gtk_selection_model_is_selected (GTK_SELECTION_MODEL (model), position))
     {
         gtk_selection_model_select_item (GTK_SELECTION_MODEL (model), position, TRUE);
+        set_focus_item (self, item);
     }
 }
 
@@ -1136,23 +1161,7 @@ real_set_selection (NautilusFilesView *files_view,
     if (!g_queue_is_empty (selection_items))
     {
         NautilusViewItem *item = g_queue_peek_head (selection_items);
-        GtkWidget *item_widget = nautilus_view_item_get_item_ui (item);
-        GtkWidget *parent = gtk_widget_get_parent (item_widget);
-
-        if (!gtk_widget_grab_focus (parent))
-        {
-            /* In GtkColumnView, the parent is a cell; its parent is the row. */
-            gtk_widget_grab_focus (gtk_widget_get_parent (parent));
-        }
-
-        /* HACK: Grabbing focus is not enough for the listbase item tracker to
-         * acknowledge it. So, poke the internal actions to fix the bug reported
-         * in https://gitlab.gnome.org/GNOME/nautilus/-/issues/2294 */
-        gtk_widget_activate_action (item_widget,
-                                    "list.select-item",
-                                    "(ubb)",
-                                    nautilus_view_model_get_index (priv->model, item),
-                                    FALSE, FALSE);
+        set_focus_item (self, item);
     }
 
     gtk_bitset_union (update_set, selection_set);


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