filechooser: Don't automatically select a file
authorrobxnano <91250-robxnano@users.noreply.gitlab.gnome.org>
Tue, 28 Feb 2023 22:50:56 +0000 (22:50 +0000)
committerrobxnano <91250-robxnano@users.noreply.gitlab.gnome.org>
Wed, 1 Mar 2023 13:56:52 +0000 (13:56 +0000)
When the folder changes, do not select the first item in the list,
so if the user enters a folder and then clicks the accept button,
the current folder is returned instead of the selected one.
To maintain consistency with the previous implementation, when a
folder in the path bar is clicked the previously-entered folder is
selected, and when the file chooser is in open file mode the first
item is always selected.

See #5438

gtk/gtkfilechooserwidget.c

index 70276967e577457ee684c2231ce17448b845396c..5653ae7a3d0e5b988312532de3e34eb8f837a640 100644 (file)
@@ -2571,7 +2571,11 @@ set_select_multiple (GtkFileChooserWidget *impl,
   if (select_multiple)
     impl->selection_model = GTK_SELECTION_MODEL (gtk_multi_selection_new (model));
   else
-    impl->selection_model = GTK_SELECTION_MODEL (gtk_single_selection_new (model));
+    {
+      impl->selection_model = GTK_SELECTION_MODEL (gtk_single_selection_new (model));
+      gtk_single_selection_set_can_unselect (GTK_SINGLE_SELECTION (impl->selection_model), TRUE);
+      gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (impl->selection_model), FALSE);
+    }
 
   g_signal_connect (impl->selection_model, "selection-changed",
                     G_CALLBACK (list_selection_changed), impl);
@@ -7289,6 +7293,9 @@ gtk_file_chooser_widget_init (GtkFileChooserWidget *impl)
                     G_CALLBACK (list_items_changed), impl);
 
   gtk_single_selection_set_model (GTK_SINGLE_SELECTION (impl->selection_model), G_LIST_MODEL (impl->sort_model));
+  gtk_single_selection_set_can_unselect (GTK_SINGLE_SELECTION (impl->selection_model), TRUE);
+  gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (impl->selection_model), FALSE);
+
   gtk_sort_list_model_set_model (impl->sort_model, G_LIST_MODEL (impl->filter_model));
 
   gtk_column_view_set_model (GTK_COLUMN_VIEW (impl->browse_files_column_view), impl->selection_model);