From fc1f1366b45d43062e8646717c25fbefd31f4150 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 5 Jan 2023 08:37:29 -0500 Subject: [PATCH] filechooser: Don't assert for possible cases switch_to_selected_folder can be called when the selection contains more than one item. Handle it like it used to be handled: switch to the first folder we find. Fixes: #5494 --- gtk/gtkfilechooserwidget.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index ca1aa426b4..5152e090de 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -4914,17 +4914,31 @@ gtk_file_chooser_widget_get_shortcut_folders (GtkFileChooser *chooser) static void switch_to_selected_folder (GtkFileChooserWidget *impl) { - GFileInfo *info; - GFile *file; + GtkBitsetIter iter; + GtkBitset *bitset; + unsigned int i; - g_assert (!impl->select_multiple); - g_assert (GTK_IS_SINGLE_SELECTION (impl->selection_model)); + bitset = gtk_selection_model_get_selection (impl->selection_model); - info = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (impl->selection_model)); - g_assert (info != NULL); + for (gtk_bitset_iter_init_first (&iter, bitset, &i); + gtk_bitset_iter_is_valid (&iter); + gtk_bitset_iter_next (&iter, &i)) + { + GFileInfo *info; - file = _gtk_file_info_get_file (info); - change_folder_and_display_error (impl, file, FALSE); + info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i); + if (_gtk_file_info_consider_as_directory (info)) + { + GFile *file; + + file = _gtk_file_info_get_file (info); + change_folder_and_display_error (impl, file, FALSE); + g_object_unref (info); + return; + } + + g_clear_object (&info); + } } /* Gets the display name of the selected file in the file list; assumes single