diff options
Diffstat (limited to 'fiv-sidebar.c')
-rw-r--r-- | fiv-sidebar.c | 90 |
1 files changed, 46 insertions, 44 deletions
diff --git a/fiv-sidebar.c b/fiv-sidebar.c index fc63a99..900c8a8 100644 --- a/fiv-sidebar.c +++ b/fiv-sidebar.c @@ -25,7 +25,6 @@ struct _FivSidebar { GtkScrolledWindow parent_instance; GtkPlacesSidebar *places; - GtkWidget *toolbar; GtkWidget *listbox; FivIoModel *model; }; @@ -78,7 +77,7 @@ fiv_sidebar_class_init(FivSidebarClass *klass) // You're giving me no choice, Adwaita. // Your style is hardcoded to match against the class' CSS name. - // And I need replicate the internal widget structure. + // And I need to replicate the internal widget structure. gtk_widget_class_set_css_name(widget_class, "placessidebar"); // TODO(p): Consider a return value, and using it. @@ -313,28 +312,9 @@ on_update_task_done(GObject *source_object, G_GNUC_UNUSED GAsyncResult *res, } static void -update_location(FivSidebar *self) +reload_directories(FivSidebar *self) { GFile *location = fiv_io_model_get_location(self->model); - - 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) @@ -358,10 +338,10 @@ update_location(FivSidebar *self) gtk_container_add(GTK_CONTAINER(self->listbox), row); gsize len = 0; - const FivIoModelEntry *subdirs = + FivIoModelEntry *const *subdirs = fiv_io_model_get_subdirs(self->model, &len); for (gsize i = 0; i < len; i++) { - GFile *file = g_file_new_for_uri(subdirs[i].uri); + GFile *file = g_file_new_for_uri(subdirs[i]->uri); if ((row = create_row(self, file, "go-down-symbolic"))) gtk_container_add(GTK_CONTAINER(self->listbox), row); g_object_unref(file); @@ -369,6 +349,41 @@ update_location(FivSidebar *self) } static void +on_model_subdirectories_changed(G_GNUC_UNUSED FivIoModel *model, + FivIoModelEntry *old, FivIoModelEntry *new, gpointer user_data) +{ + FivSidebar *self = FIV_SIDEBAR(user_data); + // TODO(p): Optimize: there's no need to update parent directories. + if (!old || !new || strcmp(old->uri, new->uri)) + reload_directories(self); +} + +static void +update_location(FivSidebar *self) +{ + GFile *location = fiv_io_model_get_location(self->model); + 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); + reload_directories(self); +} + +static void on_open_breadcrumb( G_GNUC_UNUSED GtkListBox *listbox, GtkListBoxRow *row, gpointer user_data) { @@ -418,7 +433,10 @@ complete_path(GFile *location, GtkListStore *model) !info) break; - if (g_file_info_get_file_type(info) != G_FILE_TYPE_DIRECTORY || + if (g_file_info_get_file_type(info) != G_FILE_TYPE_DIRECTORY) + continue; + if (g_file_info_has_attribute(info, + G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) && g_file_info_get_is_hidden(info)) continue; @@ -583,12 +601,6 @@ fiv_sidebar_init(FivSidebar *self) gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self->places), GTK_POLICY_NEVER, GTK_POLICY_NEVER); - // None of GtkActionBar, GtkToolbar, .inline-toolbar is appropriate. - // It is either side-favouring borders or excess button padding. - self->toolbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12); - gtk_style_context_add_class( - gtk_widget_get_style_context(self->toolbar), GTK_STYLE_CLASS_TOOLBAR); - self->listbox = gtk_list_box_new(); gtk_list_box_set_selection_mode( GTK_LIST_BOX(self->listbox), GTK_SELECTION_NONE); @@ -603,10 +615,6 @@ fiv_sidebar_init(FivSidebar *self) gtk_container_add( GTK_CONTAINER(superbox), gtk_separator_new(GTK_ORIENTATION_VERTICAL)); gtk_container_add( - GTK_CONTAINER(superbox), self->toolbar); - gtk_container_add( - GTK_CONTAINER(superbox), gtk_separator_new(GTK_ORIENTATION_VERTICAL)); - gtk_container_add( GTK_CONTAINER(superbox), self->listbox); gtk_container_add(GTK_CONTAINER(self), superbox); @@ -634,10 +642,11 @@ fiv_sidebar_new(FivIoModel *model) gtk_container_set_focus_vadjustment(GTK_CONTAINER(sidebar_port), gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(self))); - // TODO(p): There should be an extra signal to watch location changes only. self->model = g_object_ref(model); - g_signal_connect_swapped(self->model, "subdirectories-changed", + g_signal_connect_swapped(self->model, "reloaded", G_CALLBACK(update_location), self); + g_signal_connect(self->model, "subdirectories-changed", + G_CALLBACK(on_model_subdirectories_changed), self); return GTK_WIDGET(self); } @@ -648,10 +657,3 @@ fiv_sidebar_show_enter_location(FivSidebar *self) g_return_if_fail(FIV_IS_SIDEBAR(self)); g_signal_emit_by_name(self->places, "show-enter-location"); } - -GtkBox * -fiv_sidebar_get_toolbar(FivSidebar *self) -{ - g_return_val_if_fail(FIV_IS_SIDEBAR(self), NULL); - return GTK_BOX(self->toolbar); -} |