[nautilus/wip/antoniof/new-list-view-without-expanders: 10/10] files-view-model: Focus selection when setting it




commit 51755ccea80e0ea9cad87326d9d5926c99b283b5
Author: António Fernandes <antoniof gnome org>
Date:   Fri Jun 3 10:53:13 2022 +0100

    files-view-model: Focus selection when setting it
    
    In all cases when we set selection, we also want to set focus.
    Otherwise, moving the focus is going to disrupt user workflow.
    
    Solution based on Corey Berla's review suggestion.
    
    Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/2087

 src/nautilus-list-base.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
---
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c
index 58315d0aa..355961e94 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -673,6 +673,19 @@ real_set_selection (NautilusFilesView *files_view,
                         nautilus_view_model_get_index (priv->model, l->data));
     }
 
+    /* Set focus on the first selected row. */
+    if (!g_queue_is_empty (selection_items))
+    {
+        NautilusViewItem *item = g_queue_peek_head (selection_items);
+        GtkWidget *parent = gtk_widget_get_parent (nautilus_view_item_get_item_ui (item));
+
+        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));
+        }
+    }
+
     gtk_bitset_union (update_set, selection_set);
     gtk_selection_model_set_selection (GTK_SELECTION_MODEL (priv->model),
                                        selection_set,


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