From 5d03bb847eb68138d525d7829a3eea0279fa9ed2 Mon Sep 17 00:00:00 2001 From: Gabriele Barbero Date: Tue, 2 Sep 2025 21:20:09 +0200 Subject: [PATCH] core, widgets: ensure to add colors of GimpFillEditor in color history once Previously, changing the color via the GimpFillEditor color button immediately pushed each intermediate value into the color history, polluting it with transient previews. Only the final choice confirmed by the user should be recorded. Now the color is recorded in the history only when the user explicitly confirms the selection (e.g. OK/Apply), preventing noisy history entries while preserving the expected behavior when a color is accepted. core: add spaces to fix alignment --- app/core/gimpfilloptions.c | 48 ++++++++++++++++++++++++---- app/core/gimpfilloptions.h | 4 +++ app/widgets/gimpfilleditor.c | 62 ++++++++++++++++++++++++++++++------ 3 files changed, 98 insertions(+), 16 deletions(-) diff --git a/app/core/gimpfilloptions.c b/app/core/gimpfilloptions.c index a9d86af386..041cb3e02f 100644 --- a/app/core/gimpfilloptions.c +++ b/app/core/gimpfilloptions.c @@ -53,7 +53,8 @@ enum PROP_FEATHER, PROP_FEATHER_RADIUS, PROP_PATTERN_VIEW_TYPE, - PROP_PATTERN_VIEW_SIZE + PROP_PATTERN_VIEW_SIZE, + PROP_UPDATE_COLOR_HISTORY }; @@ -67,10 +68,12 @@ struct _GimpFillOptionsPrivate gboolean feather; gdouble feather_radius; - GimpViewType pattern_view_type; - GimpViewSize pattern_view_size; + GimpViewType pattern_view_type; + GimpViewSize pattern_view_size; - const gchar *undo_desc; + gboolean update_color_history; + + const gchar *undo_desc; }; #define GET_PRIVATE(options) \ @@ -160,6 +163,14 @@ gimp_fill_options_class_init (GimpFillOptionsClass *klass) GIMP_VIEW_SIZE_SMALL, G_PARAM_CONSTRUCT | GIMP_PARAM_READWRITE)); + + g_object_class_install_property (object_class, PROP_UPDATE_COLOR_HISTORY, + g_param_spec_boolean ("update-color-history", + NULL, + NULL, + TRUE, + G_PARAM_CONSTRUCT | + GIMP_PARAM_READWRITE)); } static void @@ -208,6 +219,10 @@ gimp_fill_options_set_property (GObject *object, private->pattern_view_size = g_value_get_int (value); break; + case PROP_UPDATE_COLOR_HISTORY: + private->update_color_history = g_value_get_boolean (value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -247,6 +262,10 @@ gimp_fill_options_get_property (GObject *object, g_value_set_int (value, private->pattern_view_size); break; + case PROP_UPDATE_COLOR_HISTORY: + g_value_set_boolean (value, private->update_color_history); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -567,6 +586,8 @@ gimp_fill_options_fill_buffer (GimpFillOptions *options, gint pattern_offset_x, gint pattern_offset_y) { + GimpFillOptionsPrivate *priv; + g_return_if_fail (GIMP_IS_FILL_OPTIONS (options)); g_return_if_fail (gimp_fill_options_get_style (options) != GIMP_FILL_STYLE_PATTERN || @@ -574,6 +595,8 @@ gimp_fill_options_fill_buffer (GimpFillOptions *options, g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (GEGL_IS_BUFFER (buffer)); + priv = GET_PRIVATE (options); + switch (gimp_fill_options_get_style (options)) { case GIMP_FILL_STYLE_FG_COLOR: @@ -581,7 +604,8 @@ gimp_fill_options_fill_buffer (GimpFillOptions *options, GeglColor *color; color = gimp_context_get_foreground (GIMP_CONTEXT (options)); - gimp_palettes_add_color_history (GIMP_CONTEXT (options)->gimp, color); + if (priv->update_color_history) + gimp_palettes_add_color_history (GIMP_CONTEXT (options)->gimp, color); gimp_drawable_fill_buffer (drawable, buffer, color, NULL, 0, 0); } @@ -592,7 +616,8 @@ gimp_fill_options_fill_buffer (GimpFillOptions *options, GeglColor *color; color = gimp_context_get_background (GIMP_CONTEXT (options)); - gimp_palettes_add_color_history (GIMP_CONTEXT (options)->gimp, color); + if (priv->update_color_history) + gimp_palettes_add_color_history (GIMP_CONTEXT (options)->gimp, color); gimp_drawable_fill_buffer (drawable, buffer, color, NULL, 0, 0); } @@ -612,3 +637,14 @@ gimp_fill_options_fill_buffer (GimpFillOptions *options, break; } } + +void +gimp_fill_options_enable_color_history (GimpFillOptions *options, + gboolean enable) +{ + g_return_if_fail (GIMP_IS_FILL_OPTIONS (options)); + + g_object_set (options, + "update-color-history", enable, + NULL); +} diff --git a/app/core/gimpfilloptions.h b/app/core/gimpfilloptions.h index 6835d53490..28129dea72 100644 --- a/app/core/gimpfilloptions.h +++ b/app/core/gimpfilloptions.h @@ -92,3 +92,7 @@ void gimp_fill_options_fill_buffer (GimpFillOptions *optio GeglBuffer *buffer, gint pattern_offset_x, gint pattern_offset_y); + +void gimp_fill_options_enable_color_history + (GimpFillOptions *options, + gboolean enable); \ No newline at end of file diff --git a/app/widgets/gimpfilleditor.c b/app/widgets/gimpfilleditor.c index 658cd9abd6..663e6c5c1c 100644 --- a/app/widgets/gimpfilleditor.c +++ b/app/widgets/gimpfilleditor.c @@ -48,16 +48,24 @@ enum }; -static void gimp_fill_editor_constructed (GObject *object); -static void gimp_fill_editor_finalize (GObject *object); -static void gimp_fill_editor_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void gimp_fill_editor_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); +static void gimp_fill_editor_constructed (GObject *object); +static void gimp_fill_editor_finalize (GObject *object); +static void gimp_fill_editor_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gimp_fill_editor_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void gimp_fill_editor_color_button_clicked + (GimpColorPanel *panel, + GimpFillEditor *editor); +static void gimp_fill_editor_color_button_response + (GimpColorPanel *panel, + GimpColorDialogState state, + GimpFillEditor *editor); G_DEFINE_TYPE (GimpFillEditor, gimp_fill_editor, GTK_TYPE_BOX) @@ -142,6 +150,13 @@ gimp_fill_editor_constructed (GObject *object) GIMP_CONTEXT (editor->options)); gimp_enum_radio_box_add (GTK_BOX (box), color_button, GIMP_CUSTOM_STYLE_SOLID_COLOR, FALSE); + + g_signal_connect_object (GIMP_COLOR_PANEL (color_button), "clicked", + G_CALLBACK (gimp_fill_editor_color_button_clicked), + editor, 0); + g_signal_connect_object (GIMP_COLOR_PANEL (color_button), "response", + G_CALLBACK (gimp_fill_editor_color_button_response), + editor, 0); } else { @@ -265,3 +280,30 @@ gimp_fill_editor_new (GimpFillOptions *options, "use-custom-style", use_custom_style ? TRUE : FALSE, NULL); } + +static void +gimp_fill_editor_color_button_clicked (GimpColorPanel *panel, + GimpFillEditor *editor) +{ + GimpFillOptions *options; + + g_return_if_fail (GIMP_IS_FILL_EDITOR (editor)); + + options = editor->options; + + gimp_fill_options_enable_color_history (options, FALSE); +} + +static void +gimp_fill_editor_color_button_response (GimpColorPanel *panel, + GimpColorDialogState state, + GimpFillEditor *editor) +{ + GimpFillOptions *options; + + g_return_if_fail (GIMP_IS_FILL_EDITOR (editor)); + + options = editor->options; + + gimp_fill_options_enable_color_history (options, TRUE); +}