From 701846ab398371de5a921b1a561bcc1601cd8297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Thu, 28 Jul 2022 00:37:36 +0200 Subject: Support opening collections of files Implement a process-local VFS to enable grouping together arbitrary URIs passed via program arguments, DnD, or the file open dialog. This VFS contains FivCollectionFile objects, which act as "simple" proxies over arbitrary GFiles. Their true URIs may be retrieved through the "standard::target-uri" attribute, in a similar way to GVfs's "recent" and "trash" backends. (The main reason we proxy rather than just hackishly return foreign GFiles from the VFS is that loading them would switch the current directory, and break iteration as a result. We could also keep the collection outside of GVfs, but that would result in considerable special-casing, and the author wouldn't gain intimate knowledge of GIO.) There is no perceived need to keep old collections when opening new ones, so we simply change and reload the contents when needed. Similarly, there is no intention to make the VFS writeable. The process-locality of this and other URI schemes has proven to be rather annoying when passing files to other applications, however most of the resulting complexity appears to be essential rather than accidental. Note that the GTK+ file chooser widget is retarded, and doesn't recognize URIs that lack the authority part in the location bar. --- fiv-sidebar.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'fiv-sidebar.c') diff --git a/fiv-sidebar.c b/fiv-sidebar.c index bc83649..fc63a99 100644 --- a/fiv-sidebar.c +++ b/fiv-sidebar.c @@ -17,6 +17,7 @@ #include +#include "fiv-collection.h" #include "fiv-context-menu.h" #include "fiv-io.h" #include "fiv-sidebar.h" @@ -295,16 +296,49 @@ create_row(FivSidebar *self, GFile *file, const char *icon_name) return row; } +static void +on_update_task(GTask *task, G_GNUC_UNUSED gpointer source_object, + G_GNUC_UNUSED gpointer task_data, G_GNUC_UNUSED GCancellable *cancellable) +{ + g_task_return_boolean(task, TRUE); +} + +static void +on_update_task_done(GObject *source_object, G_GNUC_UNUSED GAsyncResult *res, + G_GNUC_UNUSED gpointer user_data) +{ + FivSidebar *self = FIV_SIDEBAR(source_object); + gtk_places_sidebar_set_location( + self->places, fiv_io_model_get_location(self->model)); +} + static void update_location(FivSidebar *self) { GFile *location = fiv_io_model_get_location(self->model); - if (!location) - return; + + GFile *collection = g_file_new_for_uri(FIV_COLLECTION_SCHEME ":/"); + gtk_places_sidebar_remove_shortcut(self->places, collection); + if (location && g_file_has_uri_scheme(location, FIV_COLLECTION_SCHEME)) { + // add_shortcut() asynchronously requests GFileInfo, and only fills in + // the new row's "uri" data field once that's finished, resulting in + // the immediate set_location() call below failing to find it. + gtk_places_sidebar_add_shortcut(self->places, collection); + + // Queue up a callback using the same mechanism that GFile uses. + GTask *task = g_task_new(self, NULL, on_update_task_done, NULL); + g_task_set_name(task, __func__); + g_task_set_priority(task, G_PRIORITY_LOW); + g_task_run_in_thread(task, on_update_task); + g_object_unref(task); + } + g_object_unref(collection); gtk_places_sidebar_set_location(self->places, location); gtk_container_foreach(GTK_CONTAINER(self->listbox), (GtkCallback) gtk_widget_destroy, NULL); + if (!location) + return; GFile *iter = g_object_ref(location); GtkWidget *row = NULL; -- cgit v1.2.3