diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c index c3a870fa342ccd1d9c3976c79a94ed0ec373c650..887c9d5bafe942f3d195ca8f4fd1d3785d4f2c9a 100644 --- a/src/nautilus-properties-window.c +++ b/src/nautilus-properties-window.c @@ -90,7 +90,8 @@ struct _NautilusPropertiesWindow GtkWidget *icon_image; GtkWidget *icon_button; GtkWidget *icon_button_image; - GtkWidget *icon_chooser; + AdwBin *reset_folder_image_bin; + GtkFileDialog *icon_dialog; GtkWidget *star_button; @@ -459,6 +460,7 @@ static void remove_pending (StartupData *data, gboolean cancel_timed_wait); static void refresh_extension_model_pages (NautilusPropertiesWindow *self); static gboolean is_root_directory (NautilusFile *file); +static gboolean is_custom_icon_folder_image (NautilusPropertiesWindow *self); G_DEFINE_TYPE (NautilusPropertiesWindow, nautilus_properties_window, ADW_TYPE_WINDOW); @@ -811,10 +813,14 @@ setup_image_widget (NautilusPropertiesWindow *self, g_signal_connect (self->icon_button, "clicked", G_CALLBACK (select_image_button_callback), self); gtk_stack_set_visible_child (self->icon_stack, self->icon_button); + + gtk_widget_set_visible (GTK_WIDGET (self->reset_folder_image_bin), + is_custom_icon_folder_image (self)); } else { gtk_stack_set_visible_child (self->icon_stack, self->icon_image); + gtk_widget_set_visible (GTK_WIDGET (self->reset_folder_image_bin), FALSE); } } @@ -2695,7 +2701,7 @@ setup_basic_page (NautilusPropertiesWindow *self) setup_image_widget (self, should_show_custom_icon_buttons (self)); - self->icon_chooser = NULL; + self->icon_dialog = NULL; if (!is_multi_file_window (self)) { @@ -4201,84 +4207,101 @@ set_icon (const char *icon_uri, } } -static void -custom_icon_file_chooser_response_cb (GtkDialog *dialog, - gint response, - NautilusPropertiesWindow *self) +static gboolean +is_custom_icon_folder_image (NautilusPropertiesWindow *self) { - switch (response) + NautilusFile *file; + g_autofree gchar *image_path = NULL; + gboolean is_custom_icon = FALSE; + GList *l; + + for (l = self->original_files; l != NULL; l = l->next) { - case GTK_RESPONSE_NO: + file = NAUTILUS_FILE (l->data); + image_path = nautilus_file_get_metadata (file, + NAUTILUS_METADATA_KEY_CUSTOM_ICON, + NULL); + is_custom_icon = (image_path != NULL); + if (is_custom_icon) { - reset_icon (self); + break; } - break; + } - case GTK_RESPONSE_OK: - { - g_autoptr (GFile) location = NULL; - g_autofree gchar *uri = NULL; + return is_custom_icon; +} - location = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog)); - if (location != NULL) - { - uri = g_file_get_uri (location); - set_icon (uri, self); - } - else - { - reset_icon (self); - } - } - break; +static void +reset_folder_image_cb (NautilusPropertiesWindow *self) +{ + reset_icon (self); - default: - { - } - break; + gtk_widget_set_visible (GTK_WIDGET (self->reset_folder_image_bin), FALSE); +} + +static void +custom_icon_file_dialog_response_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + NautilusPropertiesWindow *self = (user_data); + GtkFileDialog *file_dialog = GTK_FILE_DIALOG (source_object); + g_autoptr (GError) error = NULL; + g_autoptr (GFile) file = NULL; + g_autofree gchar *uri = NULL; + + file = gtk_file_dialog_open_finish (file_dialog, result, &error); + + if (error != NULL) + { + g_warning ("Failed to pick folder image: %s", error->message); + return; } - gtk_window_destroy (GTK_WINDOW (dialog)); + uri = g_file_get_uri (file); + set_icon (uri, self); + + gtk_widget_set_visible (GTK_WIDGET (self->reset_folder_image_bin), TRUE); } static void select_image_button_callback (GtkWidget *widget, NautilusPropertiesWindow *self) { - GtkWidget *dialog; + GtkFileDialog *file_dialog; + GtkWindow *toplevel; GtkFileFilter *filter; GList *l; + GListStore *filters; NautilusFile *file; gboolean revert_is_sensitive; g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (self)); - dialog = self->icon_chooser; + file_dialog = self->icon_dialog; + toplevel = GTK_WINDOW (self); - if (dialog == NULL) + if (file_dialog == NULL) { g_autoptr (GFile) pictures_location = NULL; - dialog = gtk_file_chooser_dialog_new (_("Select Custom Icon"), GTK_WINDOW (self), - GTK_FILE_CHOOSER_ACTION_OPEN, - _("_Revert"), GTK_RESPONSE_NO, - _("_Cancel"), GTK_RESPONSE_CANCEL, - _("_Open"), GTK_RESPONSE_OK, - NULL); - pictures_location = g_file_new_for_path (g_get_user_special_dir (G_USER_DIRECTORY_PICTURES)); - gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), - pictures_location, - NULL); - gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + file_dialog = gtk_file_dialog_new (); + gtk_file_dialog_set_title (file_dialog, _("Select Custom Icon")); + gtk_file_dialog_set_modal (file_dialog, TRUE); filter = gtk_file_filter_new (); gtk_file_filter_add_pixbuf_formats (filter); - gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter); - self->icon_chooser = dialog; + filters = g_list_store_new (GTK_TYPE_FILE_FILTER); + g_list_store_append (filters, filter); + gtk_file_dialog_set_filters (file_dialog, G_LIST_MODEL (filters)); + + pictures_location = g_file_new_for_path (g_get_user_special_dir (G_USER_DIRECTORY_PICTURES)); + gtk_file_dialog_set_initial_folder (file_dialog, pictures_location); - g_object_add_weak_pointer (G_OBJECT (dialog), - (gpointer *) &self->icon_chooser); + self->icon_dialog = file_dialog; + + g_object_add_weak_pointer (G_OBJECT (file_dialog), + (gpointer *) &self->icon_dialog); } /* it's likely that the user wants to pick an icon that is inside a local directory */ @@ -4294,9 +4317,8 @@ select_image_button_callback (GtkWidget *widget, if (image_location != NULL) { - gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), - image_location, - NULL); + gtk_file_dialog_set_initial_folder (GTK_FILE_DIALOG (file_dialog), + image_location); } } } @@ -4315,11 +4337,12 @@ select_image_button_callback (GtkWidget *widget, break; } } - gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_NO, revert_is_sensitive); - g_signal_connect (dialog, "response", - G_CALLBACK (custom_icon_file_chooser_response_cb), self); - gtk_window_present (GTK_WINDOW (dialog)); + gtk_file_dialog_open (file_dialog, + toplevel, + NULL, + custom_icon_file_dialog_response_cb, + self); } static void @@ -4344,6 +4367,7 @@ nautilus_properties_window_class_init (NautilusPropertiesWindowClass *klass) gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_image); gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_button); gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_button_image); + gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, reset_folder_image_bin); gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, star_button); gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, name_value_label); gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, type_value_label); @@ -4404,6 +4428,7 @@ nautilus_properties_window_class_init (NautilusPropertiesWindowClass *klass) gtk_widget_class_bind_template_callback (widget_class, open_link_target); gtk_widget_class_bind_template_callback (widget_class, navigate_main_page); gtk_widget_class_bind_template_callback (widget_class, navigate_permissions_page); + gtk_widget_class_bind_template_callback (widget_class, reset_folder_image_cb); } static void diff --git a/src/resources/style.css b/src/resources/style.css index ea349688f9ba20882244909d52e478191bd1f4c5..e0f29a8dbbb1cf768fdfacae6588f939e9469bd4 100644 --- a/src/resources/style.css +++ b/src/resources/style.css @@ -283,3 +283,10 @@ label.encrypted_zip { rubberband { border-radius: 6px; } + +/* This is used for revert_folder_image */ +.cutout-button { + background-color: @window_bg_color; + border-radius: 6px; + padding: 2px; +} diff --git a/src/resources/ui/nautilus-properties-window.ui b/src/resources/ui/nautilus-properties-window.ui index f10454ac5b3f297a5f2ab58cce3e56075c7cb0ae..54e7fa3cfd557681fa7c2d3f243f4eec6f15038c 100644 --- a/src/resources/ui/nautilus-properties-window.ui +++ b/src/resources/ui/nautilus-properties-window.ui @@ -41,33 +41,57 @@ - - center - start + - - icon_image - - - image-missing + + center + start + + + icon_image + + + image-missing + + - + + + + icon_button + + + True + True + + + image-missing + + + + + + - - - icon_button - - + + + + end + end + + True True - - - image-missing - - + document-revert-symbolic + + + Revert image folder + - +