[gimp] libgimpconfig: gimp_config_reset_properties(): reset only changed properties



commit 7111eadf3bb90a2e20ad143972ce10ddda4c0e56
Author: Michael Natterer <mitch gimp org>
Date:   Thu Feb 9 12:38:10 2017 +0100

    libgimpconfig: gimp_config_reset_properties(): reset only changed properties
    
    This avoids a lot of useless notifications when resetting an object,
    and fixes e.g. the "reset tool options" behavior of GimpTransformTool,
    which did completely reset itself instead of just behaving like all
    non-default options had changed.
    
    And probably breaks some things that were relying on these redundant
    notifications.

 libgimpconfig/gimpconfig-utils.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/libgimpconfig/gimpconfig-utils.c b/libgimpconfig/gimpconfig-utils.c
index fa8f300..5274b49 100644
--- a/libgimpconfig/gimpconfig-utils.c
+++ b/libgimpconfig/gimpconfig-utils.c
@@ -266,7 +266,6 @@ gimp_config_reset_properties (GObject *object)
 {
   GObjectClass  *klass;
   GParamSpec   **property_specs;
-  GValue         value = G_VALUE_INIT;
   guint          n_property_specs;
   guint          i;
 
@@ -283,6 +282,7 @@ gimp_config_reset_properties (GObject *object)
   for (i = 0; i < n_property_specs; i++)
     {
       GParamSpec *prop_spec;
+      GValue      value = G_VALUE_INIT;
 
       prop_spec = property_specs[i];
 
@@ -307,12 +307,22 @@ gimp_config_reset_properties (GObject *object)
             }
           else
             {
-              g_value_init (&value, prop_spec->value_type);
-              g_param_value_set_default (prop_spec, &value);
+              GValue default_value = G_VALUE_INIT;
+
+              g_value_init (&default_value, prop_spec->value_type);
+              g_value_init (&value,         prop_spec->value_type);
+
+              g_param_value_set_default (prop_spec, &default_value);
+              g_object_get_property (object, prop_spec->name, &value);
 
-              g_object_set_property (object, prop_spec->name, &value);
+              if (g_param_values_cmp (prop_spec, &default_value, &value))
+                {
+                  g_object_set_property (object, prop_spec->name,
+                                         &default_value);
+                }
 
               g_value_unset (&value);
+              g_value_unset (&default_value);
             }
         }
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]