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
This commit is contained in:
Matthias Clasen 2023-01-05 08:37:29 -05:00
parent 7c5c843b5b
commit fc1f1366b4

View File

@ -4913,18 +4913,32 @@ gtk_file_chooser_widget_get_shortcut_folders (GtkFileChooser *chooser)
/* Changes to the selected folder in the list view */ /* Changes to the selected folder in the list view */
static void static void
switch_to_selected_folder (GtkFileChooserWidget *impl) switch_to_selected_folder (GtkFileChooserWidget *impl)
{
GtkBitsetIter iter;
GtkBitset *bitset;
unsigned int i;
bitset = gtk_selection_model_get_selection (impl->selection_model);
for (gtk_bitset_iter_init_first (&iter, bitset, &i);
gtk_bitset_iter_is_valid (&iter);
gtk_bitset_iter_next (&iter, &i))
{ {
GFileInfo *info; GFileInfo *info;
info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), i);
if (_gtk_file_info_consider_as_directory (info))
{
GFile *file; GFile *file;
g_assert (!impl->select_multiple);
g_assert (GTK_IS_SINGLE_SELECTION (impl->selection_model));
info = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (impl->selection_model));
g_assert (info != NULL);
file = _gtk_file_info_get_file (info); file = _gtk_file_info_get_file (info);
change_folder_and_display_error (impl, file, FALSE); 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 /* Gets the display name of the selected file in the file list; assumes single