properies-window: Replace thumbnail button with two buttons

Replace the thumbnail button used to pick a custom icon with
two buttons for clearing and picking a new icon. The revert
button inside the dialog is therefore removed.
This commit is contained in:
Khalid Abu Shawarib 2023-12-22 17:48:53 +03:00 committed by Peter Eisenmann
parent 679f71a689
commit 1c70bab1f0
5 changed files with 101 additions and 31 deletions

View file

@ -88,8 +88,8 @@ struct _NautilusPropertiesWindow
GtkStack *icon_stack;
GtkWidget *icon_image;
GtkWidget *icon_button;
GtkWidget *icon_button_image;
GtkWidget *icon_overlay;
GtkWidget *reset_icon_button;
GtkWidget *icon_chooser;
GtkWidget *star_button;
@ -451,6 +451,7 @@ static void update_owner_row (AdwComboRow *row,
TargetPermissions *target_perm);
static void update_group_row (AdwComboRow *row,
TargetPermissions *target_perm);
static void update_reset_icon_button (NautilusPropertiesWindow *self);
static void select_image_button_callback (GtkWidget *widget,
NautilusPropertiesWindow *self);
static void set_icon (const char *icon_path,
@ -603,9 +604,7 @@ update_properties_window_icon (NautilusPropertiesWindow *self)
gdk_paintable_get_intrinsic_width (paintable));
gtk_image_set_from_paintable (GTK_IMAGE (self->icon_image), paintable);
gtk_image_set_from_paintable (GTK_IMAGE (self->icon_button_image), paintable);
gtk_image_set_pixel_size (GTK_IMAGE (self->icon_image), pixel_size);
gtk_image_set_pixel_size (GTK_IMAGE (self->icon_button_image), pixel_size);
}
/* utility to test if a uri refers to a local image */
@ -642,6 +641,8 @@ reset_icon (NautilusPropertiesWindow *self)
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL, NULL);
}
gtk_widget_set_visible (self->reset_icon_button, FALSE);
}
static void
@ -787,8 +788,9 @@ update_image_widget (NautilusPropertiesWindow *self)
}
else
{
gtk_stack_set_visible_child (self->icon_stack, self->icon_overlay);
gtk_stack_set_visible_child (self->icon_stack, self->icon_button);
update_reset_icon_button (self);
}
}
@ -797,12 +799,9 @@ setup_image_widget (NautilusPropertiesWindow *self)
{
/* prepare the image to receive dropped objects to assign custom images */
GtkDropTarget *target = gtk_drop_target_new (GDK_TYPE_FILE_LIST, GDK_ACTION_COPY);
gtk_widget_add_controller (self->icon_button, GTK_EVENT_CONTROLLER (target));
gtk_widget_add_controller (self->icon_overlay, GTK_EVENT_CONTROLLER (target));
g_signal_connect (target, "drop",
G_CALLBACK (nautilus_properties_window_drag_drop_cb), self->icon_button_image);
g_signal_connect (self->icon_button, "clicked",
G_CALLBACK (select_image_button_callback), self);
G_CALLBACK (nautilus_properties_window_drag_drop_cb), self->icon_image);
update_image_widget (self);
}
@ -2706,6 +2705,24 @@ setup_basic_page (NautilusPropertiesWindow *self)
}
}
static void
update_reset_icon_button (NautilusPropertiesWindow *self)
{
NautilusFile *file = get_target_file (self);
gboolean revert_is_visible = FALSE;
if (file != NULL && !nautilus_file_is_gone (file))
{
const gchar *image_path = nautilus_file_get_metadata (file,
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL);
revert_is_visible = (image_path != NULL);
}
gtk_widget_set_visible (self->reset_icon_button, revert_is_visible);
}
static FilterType
files_get_filter_type (NautilusPropertiesWindow *self)
{
@ -4143,12 +4160,6 @@ custom_icon_file_chooser_response_cb (GtkDialog *dialog,
{
switch (response)
{
case GTK_RESPONSE_NO:
{
reset_icon (self);
}
break;
case GTK_RESPONSE_OK:
{
g_autoptr (GFile) location = NULL;
@ -4183,7 +4194,6 @@ select_image_button_callback (GtkWidget *widget,
GtkWidget *dialog;
GtkFileFilter *filter;
NautilusFile *file;
const char *image_path;
g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (self));
@ -4194,7 +4204,6 @@ select_image_button_callback (GtkWidget *widget,
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);
@ -4232,9 +4241,6 @@ select_image_button_callback (GtkWidget *widget,
}
}
image_path = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_NO, image_path != NULL);
g_signal_connect (dialog, "response",
G_CALLBACK (custom_icon_file_chooser_response_cb), self);
gtk_window_present (GTK_WINDOW (dialog));
@ -4260,8 +4266,8 @@ nautilus_properties_window_class_init (NautilusPropertiesWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, nav_view);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_stack);
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, icon_overlay);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, reset_icon_button);
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);
@ -4323,6 +4329,8 @@ nautilus_properties_window_class_init (NautilusPropertiesWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, open_parent_folder);
gtk_widget_class_bind_template_callback (widget_class, open_link_target);
gtk_widget_class_bind_template_callback (widget_class, navigate_permissions_page);
gtk_widget_class_bind_template_callback (widget_class, reset_icon);
gtk_widget_class_bind_template_callback (widget_class, select_image_button_callback);
}
static void

View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="16px" viewBox="0 0 16 16" width="16px"><filter id="a" height="100%" width="100%" x="0%" y="0%"><feColorMatrix color-interpolation-filters="sRGB" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/></filter><mask id="b"><g filter="url(#a)"><path d="m -1.6 -1.6 h 19.2 v 19.2 h -19.2 z" fill-opacity="0.5"/></g></mask><clipPath id="c"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><mask id="d"><g filter="url(#a)"><path d="m -1.6 -1.6 h 19.2 v 19.2 h -19.2 z" fill-opacity="0.7"/></g></mask><clipPath id="e"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><mask id="f"><g filter="url(#a)"><path d="m -1.6 -1.6 h 19.2 v 19.2 h -19.2 z" fill-opacity="0.35"/></g></mask><clipPath id="g"><path d="m 0 0 h 1600 v 1200 h -1600 z"/></clipPath><g mask="url(#b)"><g clip-path="url(#c)" transform="matrix(1 0 0 1 -56 -916)"><path d="m 550 182 c -0.351562 0.003906 -0.695312 0.101562 -1 0.28125 v 3.4375 c 0.304688 0.179688 0.648438 0.277344 1 0.28125 c 1.105469 0 2 -0.894531 2 -2 s -0.894531 -2 -2 -2 z m 0 5 c -0.339844 0 -0.679688 0.058594 -1 0.175781 v 6.824219 h 4 v -4 c 0 -1.65625 -1.34375 -3 -3 -3 z m 0 0"/></g></g><g mask="url(#d)"><g clip-path="url(#e)" transform="matrix(1 0 0 1 -56 -916)"><path d="m 569 182 v 4 c 1.105469 0 2 -0.894531 2 -2 s -0.894531 -2 -2 -2 z m 0 5 v 7 h 3 v -4 c 0 -1.65625 -1.34375 -3 -3 -3 z m 0 0"/></g></g><g mask="url(#f)"><g clip-path="url(#g)" transform="matrix(1 0 0 1 -56 -916)"><path d="m 573 182.269531 v 3.449219 c 0.613281 -0.355469 0.996094 -1.007812 1 -1.71875 c 0 -0.714844 -0.382812 -1.375 -1 -1.730469 z m 0 4.90625 v 6.824219 h 2 v -4 c 0 -1.269531 -0.800781 -2.402344 -2 -2.824219 z m 0 0"/></g></g><g fill="#222222"><path d="m 13.949219 8.359375 s 0 0.019531 0.003906 0.011719 l -5.003906 4.914062 l 0.699219 -0.285156 h -4.621094 l 0.707031 0.292969 l -3.683594 -3.683594 v -0.019531 l 6.554688 -6.554688 h 0.019531 l -0.292969 -0.707031 c 0 0.265625 0.105469 0.519531 0.292969 0.707031 z m -3.617188 -6.03125 c 0 -0.265625 -0.105469 -0.519531 -0.292969 -0.707031 c -0.789062 -0.789063 -2.058593 -0.789063 -2.847656 0 l -6.554687 6.554687 c -0.789063 0.789063 -0.789063 2.058594 0 2.847657 l 3.683593 3.683593 c 0.1875 0.1875 0.441407 0.292969 0.707032 0.292969 h 4.621094 c 0.261718 0 0.511718 -0.101562 0.699218 -0.285156 l 5.015625 -4.921875 c 0.789063 -0.789063 0.789063 -2.058594 0 -2.847657 l -5.324219 -5.324218 z m 0 0"/><path d="m 5.664062 15 h 9.804688 c 0.273438 0 0.5 -0.222656 0.5 -0.5 s -0.226562 -0.5 -0.5 -0.5 h -9.804688 c -0.277343 0 -0.5 0.222656 -0.5 0.5 s 0.222657 0.5 0.5 0.5 z m 0 0"/><path d="m 4.277344 7.007812 l 6.015625 5.992188 c 0.195312 0.195312 0.511719 0.195312 0.707031 0 s 0.195312 -0.511719 0 -0.707031 l -6.015625 -5.996094 c -0.195313 -0.195313 -0.511719 -0.195313 -0.707031 0.003906 c -0.195313 0.195313 -0.195313 0.511719 0 0.707031 z m 0 0"/><path d="m 4.132812 6.152344 l -3.03125 3.257812 l 3.527344 4.402344 l 4.929688 0.1875 l 1.589844 -1.34375 z m 0 0" fill-opacity="0.329412"/></g></svg>

After

Width:  |  Height:  |  Size: 3 KiB

View file

@ -41,5 +41,6 @@
<file alias="funnel-symbolic.svg" preprocess="xml-stripblanks">icons/funnel-symbolic.svg</file>
<file alias="external-link-symbolic.svg" preprocess="xml-stripblanks">icons/external-link-symbolic.svg</file>
<file alias="cross-filled-symbolic.svg" preprocess="xml-stripblanks">icons/cross-filled-symbolic.svg</file>
<file alias="eraser3-symbolic.svg" preprocess="xml-stripblanks">icons/eraser3-symbolic.svg</file>
</gresource>
</gresources>

View file

@ -249,6 +249,16 @@ placesview list {
padding-bottom: 66px;
}
.image-frame {
margin: 8px;
border-radius: 4px;
}
.cutout {
border-radius: 9999px;
padding: 2px;
}
.view .thumbnail {
background: url('/org/gnome/nautilus/Checkerboard.png') repeat;
border-radius: 2px;

View file

@ -54,7 +54,6 @@
<property name="valign">start</property>
<child>
<object class="GtkStackPage">
<property name="name">icon_image</property>
<property name="child">
<object class="GtkImage" id="icon_image">
<property name="icon-name">image-missing</property>
@ -64,15 +63,65 @@
</child>
<child>
<object class="GtkStackPage">
<property name="name">icon_button</property>
<property name="child">
<object class="GtkButton" id="icon_button">
<property name="tooltip-text" translatable="yes">Set Custom Icon</property>
<property name="focusable">True</property>
<property name="receives_default">True</property>
<object class="GtkOverlay" id="icon_overlay">
<child>
<object class="GtkImage" id="icon_button_image">
<property name="icon-name">image-missing</property>
<object class="GtkFrame">
<style>
<class name="image-frame"/>
</style>
<child>
<object class="GtkImage">
<binding name="paintable">
<lookup name="paintable">icon_image</lookup>
</binding>
<binding name="pixel-size">
<lookup name="pixel-size">icon_image</lookup>
</binding>
</object>
</child>
</object>
</child>
<child type="overlay">
<object class="AdwBin">
<property name="halign">end</property>
<property name="valign">end</property>
<style>
<class name="cutout"/>
<class name="background"/>
</style>
<property name="child">
<object class="GtkButton">
<property name="tooltip-text" translatable="yes">Set Custom Icon</property>
<property name="focusable">True</property>
<property name="icon-name">document-edit-symbolic</property>
<signal name="clicked" handler="select_image_button_callback"/>
<style>
<class name="circular"/>
</style>
</object>
</property>
</object>
</child>
<child type="overlay">
<object class="AdwBin">
<property name="halign">end</property>
<property name="valign">start</property>
<style>
<class name="cutout"/>
<class name="background"/>
</style>
<property name="child">
<object class="GtkButton" id="reset_icon_button">
<property name="tooltip-text" translatable="yes">Remove Custom Icon</property>
<property name="focusable">True</property>
<property name="icon-name">eraser3-symbolic</property>
<signal name="clicked" handler="reset_icon" swapped="yes"/>
<style>
<class name="circular"/>
</style>
</object>
</property>
</object>
</child>
</object>