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




commit 99f3909631bd2113b8c4714891e96a292dab1f47
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-files-model-view.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
---
diff --git a/src/nautilus-files-model-view.c b/src/nautilus-files-model-view.c
index 2da90855d..82f2cefea 100644
--- a/src/nautilus-files-model-view.c
+++ b/src/nautilus-files-model-view.c
@@ -376,6 +376,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_item_models))
+    {
+        NautilusViewItemModel *item = g_queue_peek_head (selection_item_models);
+        GtkWidget *parent = gtk_widget_get_parent (nautilus_view_item_model_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]