[gimp/wip/gradient-edit: 23/52] app: add compare() virtual function to GimpData



commit bc6c960f22bbe8b9c29bed746e34b492241c4387
Author: Ell <ell_se yahoo com>
Date:   Wed Jul 26 14:17:59 2017 -0400

    app: add compare() virtual function to GimpData
    
    ... which subclasses can override to refine comparison.  Provide a
    default implementation that uses the current logic.

 app/core/gimpdata.c |   39 +++++++++++++++++++++++++++------------
 app/core/gimpdata.h |    2 ++
 2 files changed, 29 insertions(+), 12 deletions(-)
---
diff --git a/app/core/gimpdata.c b/app/core/gimpdata.c
index f037d2d..c7c8cb3 100644
--- a/app/core/gimpdata.c
+++ b/app/core/gimpdata.c
@@ -102,6 +102,8 @@ static gboolean   gimp_data_is_name_editable  (GimpViewable        *viewable);
 
 static void       gimp_data_real_dirty        (GimpData            *data);
 static GimpData * gimp_data_real_duplicate    (GimpData            *data);
+static gint       gimp_data_real_compare      (GimpData            *data1,
+                                               GimpData            *data2);
 
 static gboolean   gimp_data_add_tag           (GimpTagged          *tagged,
                                                GimpTag             *tag);
@@ -188,6 +190,7 @@ gimp_data_class_init (GimpDataClass *klass)
   klass->get_extension             = NULL;
   klass->copy                      = NULL;
   klass->duplicate                 = gimp_data_real_duplicate;
+  klass->compare                   = gimp_data_real_compare;
 
   g_object_class_install_property (object_class, PROP_FILE,
                                    g_param_spec_object ("file", NULL, NULL,
@@ -396,6 +399,25 @@ gimp_data_real_duplicate (GimpData *data)
   return NULL;
 }
 
+static gint
+gimp_data_real_compare (GimpData *data1,
+                        GimpData *data2)
+{
+  GimpDataPrivate *private1 = GIMP_DATA_GET_PRIVATE (data1);
+  GimpDataPrivate *private2 = GIMP_DATA_GET_PRIVATE (data2);
+
+  /*  move the internal objects (like the FG -> BG) gradient) to the top  */
+  if (private1->internal != private2->internal)
+    return private1->internal ? -1 : 1;
+
+  /*  keep user-deletable objects above system resource files  */
+  if (private1->deletable != private2->deletable)
+    return private1->deletable ? -1 : 1;
+
+  return gimp_object_name_collate ((GimpObject *) data1,
+                                   (GimpObject *) data2);
+}
+
 static gboolean
 gimp_data_add_tag (GimpTagged *tagged,
                    GimpTag    *tag)
@@ -1205,19 +1227,12 @@ gint
 gimp_data_compare (GimpData *data1,
                    GimpData *data2)
 {
-  GimpDataPrivate *private1 = GIMP_DATA_GET_PRIVATE (data1);
-  GimpDataPrivate *private2 = GIMP_DATA_GET_PRIVATE (data2);
-
-  /*  move the internal objects (like the FG -> BG) gradient) to the top  */
-  if (private1->internal != private2->internal)
-    return private1->internal ? -1 : 1;
+  g_return_val_if_fail (GIMP_IS_DATA (data1), 0);
+  g_return_val_if_fail (GIMP_IS_DATA (data2), 0);
+  g_return_val_if_fail (GIMP_DATA_GET_CLASS (data1)->compare ==
+                        GIMP_DATA_GET_CLASS (data2)->compare, 0);
 
-  /*  keep user-deletable objects above system resource files  */
-  if (private1->deletable != private2->deletable)
-    return private1->deletable ? -1 : 1;
-
-  return gimp_object_name_collate ((GimpObject *) data1,
-                                   (GimpObject *) data2);
+  return GIMP_DATA_GET_CLASS (data1)->compare (data1, data2);
 }
 
 /**
diff --git a/app/core/gimpdata.h b/app/core/gimpdata.h
index 08536fb..dacfd55 100644
--- a/app/core/gimpdata.h
+++ b/app/core/gimpdata.h
@@ -64,6 +64,8 @@ struct _GimpDataClass
   void          (* copy)          (GimpData       *data,
                                    GimpData       *src_data);
   GimpData    * (* duplicate)     (GimpData       *data);
+  gint          (* compare)       (GimpData       *data1,
+                                   GimpData       *data2);
 };
 
 


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