[gimp/wip/gradient-edit: 197/225] app: implement compare() for GimpGradient



commit 9807b539292d57152ec3976a22a2c66aa43c48c9
Author: Ell <ell_se yahoo com>
Date:   Wed Jul 26 15:16:54 2017 -0400

    app: implement compare() for GimpGradient
    
    Order the custom gradient before all the other gradients, and use
    the default ordering for the rest.

 app/core/gimpgradient.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpgradient.c b/app/core/gimpgradient.c
index 173bd21..26ce0e2 100644
--- a/app/core/gimpgradient.c
+++ b/app/core/gimpgradient.c
@@ -65,6 +65,8 @@ static GimpTempBuf * gimp_gradient_get_new_preview   (GimpViewable        *viewa
 static const gchar * gimp_gradient_get_extension     (GimpData            *data);
 static void          gimp_gradient_copy              (GimpData            *data,
                                                       GimpData            *src_data);
+static gint          gimp_gradient_compare           (GimpData            *data1,
+                                                      GimpData            *data2);
 
 static gchar       * gimp_gradient_get_checksum      (GimpTagged          *tagged);
 
@@ -113,6 +115,7 @@ gimp_gradient_class_init (GimpGradientClass *klass)
   data_class->save                  = gimp_gradient_save;
   data_class->get_extension         = gimp_gradient_get_extension;
   data_class->copy                  = gimp_gradient_copy;
+  data_class->compare               = gimp_gradient_compare;
 }
 
 static void
@@ -277,6 +280,37 @@ gimp_gradient_copy (GimpData *data,
   gimp_data_thaw (GIMP_DATA (gradient));
 }
 
+static gint
+gimp_gradient_compare (GimpData *data1,
+                       GimpData *data2)
+{
+  gboolean is_custom1;
+  gboolean is_custom2;
+
+  /* check whether data1 and data2 are the custom gradient, which is the only
+   * writable internal gradient.
+   */
+  is_custom1 = gimp_data_is_internal (data1) && gimp_data_is_writable (data1);
+  is_custom2 = gimp_data_is_internal (data2) && gimp_data_is_writable (data2);
+
+  /* order the custom gradient before all the other gradients; use the default
+   * ordering for the rest.
+   */
+  if (is_custom1)
+    {
+      if (is_custom2)
+        return 0;
+      else
+        return -1;
+    }
+  else if (is_custom2)
+    {
+      return +1;
+    }
+  else
+    return GIMP_DATA_CLASS (parent_class)->compare (data1, data2);
+}
+
 static gchar *
 gimp_gradient_get_checksum (GimpTagged *tagged)
 {


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