filechooserwidget: Load recent files in bulk

We add recent files one at a time which is incredibly wasteful.
This is most obvious when the action is SAVE or OPEN_FOLDER because
we aren't limiting the number of recent files (as we are with OPEN),
so for me it took about 5 seconds to open a file dialog with OPEN_FOLDER
since the default location is recents.
This commit is contained in:
Corey Berla 2024-02-06 11:24:27 -08:00
parent c76fd1548e
commit 7823e8120d

View File

@ -5924,6 +5924,7 @@ recent_start_loading (GtkFileChooserWidget *impl)
{
const int limit = DEFAULT_RECENT_FILES_LIMIT;
const char *app_name = g_get_application_name ();
GList *files = NULL;
GList *l;
int n;
@ -5941,31 +5942,30 @@ recent_start_loading (GtkFileChooserWidget *impl)
!gtk_recent_info_has_application (info, app_name))
continue;
file = g_file_new_for_uri (gtk_recent_info_get_uri (info));
_gtk_file_system_model_add_and_query_file (impl->recent_model,
file,
MODEL_ATTRIBUTES);
g_object_unref (file);
files = g_list_prepend (files, file);
n++;
if (limit != -1 && n >= limit)
break;
}
files = g_list_reverse (files);
_gtk_file_system_model_add_and_query_files (impl->recent_model,
files,
MODEL_ATTRIBUTES);
g_list_free_full (files, g_object_unref);
g_set_object (&impl->model_for_search, impl->recent_model);
}
else
{
GList *folders;
GList *l;
folders = _gtk_file_chooser_extract_recent_folders (items);
for (l = folders; l; l = l->next)
_gtk_file_system_model_add_and_query_file (impl->recent_model,
G_FILE (l->data),
MODEL_ATTRIBUTES);
_gtk_file_system_model_add_and_query_files (impl->recent_model,
folders,
MODEL_ATTRIBUTES);
g_list_free_full (folders, g_object_unref);
}