From 9b5463b5c5cad58d4e7b590868976c0eeaa3ba60 Mon Sep 17 00:00:00 2001 From: Jehan Date: Sat, 31 Aug 2024 01:37:14 +0200 Subject: [PATCH] libgimpbase, libgimpconfig: new GIMP_PARAM_DONT_SERIALIZE flag. The purpose of this flag is to have some procedure arguments for which you wish to ignore last values, or restored values. This may be needed for arguments which are really volatile and likely won't survive a session (or even from a run to another). This will be used in my next commit. Note: this is very close to GIMP_CONFIG_PARAM_IGNORE, except that this latter is used for obsolete properties instead, so I felt that it may not have been the best idea to mix these semantically different flag. Also GIMP_CONFIG_PARAM_IGNORE properties are not serialized but they are deserialized, which is not exactly what we want (in most case, it would work the same, but it also means that if last-used values were to contain some deprecated value for a property for which we added this flag, there would be at least one run where a buggy behavior would happen). --- libgimpbase/gimpparamspecs.h | 13 ++++++++++++- libgimpconfig/gimpconfig-deserialize.c | 7 ++++--- libgimpconfig/gimpconfig-serialize.c | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/libgimpbase/gimpparamspecs.h b/libgimpbase/gimpparamspecs.h index b00064fd15..55273cda90 100644 --- a/libgimpbase/gimpparamspecs.h +++ b/libgimpbase/gimpparamspecs.h @@ -37,13 +37,24 @@ G_BEGIN_DECLS */ #define GIMP_PARAM_NO_VALIDATE (1 << (0 + G_PARAM_USER_SHIFT)) +/** + * GIMP_PARAM_DONT_SERIALIZE: + * + * This property will be ignored when serializing and deserializing. + * This is useful for GimpProcedure arguments for which you never want + * the last run values to be restored. + * + * Since 3.0 + */ +#define GIMP_PARAM_DONT_SERIALIZE (1 << (1 + G_PARAM_USER_SHIFT)) + /** * GIMP_PARAM_FLAG_SHIFT: * * Minimum shift count to be used for libgimpconfig defined * [flags@GObject.ParamFlags] (see libgimpconfig/gimpconfig-params.h). */ -#define GIMP_PARAM_FLAG_SHIFT (1 + G_PARAM_USER_SHIFT) +#define GIMP_PARAM_FLAG_SHIFT (2 + G_PARAM_USER_SHIFT) /** * GIMP_PARAM_STATIC_STRINGS: diff --git a/libgimpconfig/gimpconfig-deserialize.c b/libgimpconfig/gimpconfig-deserialize.c index 07f27e1a63..cea24ec426 100644 --- a/libgimpconfig/gimpconfig-deserialize.c +++ b/libgimpconfig/gimpconfig-deserialize.c @@ -325,9 +325,10 @@ gimp_config_deserialize_property (GimpConfig *config, if (token == G_TOKEN_RIGHT_PAREN && g_scanner_peek_next_token (scanner) == token) { - if (GIMP_VALUE_HOLDS_COLOR (&value) || - ! (G_VALUE_HOLDS_OBJECT (&value) && - (prop_spec->flags & GIMP_CONFIG_PARAM_AGGREGATE))) + if (! (prop_spec->flags & GIMP_PARAM_DONT_SERIALIZE) && + (GIMP_VALUE_HOLDS_COLOR (&value) || + ! (G_VALUE_HOLDS_OBJECT (&value) && + (prop_spec->flags & GIMP_CONFIG_PARAM_AGGREGATE)))) g_object_set_property (G_OBJECT (config), prop_spec->name, &value); } #ifdef CONFIG_DEBUG diff --git a/libgimpconfig/gimpconfig-serialize.c b/libgimpconfig/gimpconfig-serialize.c index 258e12d995..5e2d3dbd13 100644 --- a/libgimpconfig/gimpconfig-serialize.c +++ b/libgimpconfig/gimpconfig-serialize.c @@ -182,7 +182,8 @@ gimp_config_serialize_property (GimpConfig *config, if (! (param_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE)) return FALSE; - if (param_spec->flags & GIMP_CONFIG_PARAM_IGNORE) + if (param_spec->flags & GIMP_CONFIG_PARAM_IGNORE || + param_spec->flags & GIMP_PARAM_DONT_SERIALIZE) return TRUE; g_value_init (&value, param_spec->value_type);