[gimp] app: don't merge similarly-named objects during GimpContainer deserialization ...



commit a63bf32310228df0a182f87b1374d33764435aca
Author: Ell <ell_se yahoo com>
Date:   Wed Jan 29 21:30:37 2020 +0200

    app: don't merge similarly-named objects during GimpContainer deserialization ...
    
    ... if not using unique names
    
    Add a new GimpContainer::get_unique_names() virtual function, and a
    corresponding gimp_container_get_unique_names() function, which
    determines if the container uses unique names for its objects.
    Override get_unique_names() in GimpList, to return the corresponding
    property.
    
    In gimp_container_deserialize(), don't merge new objects with
    existing objects sharing the same name if the container doesn't use
    unique names.

 app/core/gimpcontainer.c        | 17 +++++++++++++++--
 app/core/gimpcontainer.h        |  3 +++
 app/core/gimplist.c             | 10 ++++++++++
 app/widgets/gimpdevicemanager.c |  2 +-
 4 files changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/app/core/gimpcontainer.c b/app/core/gimpcontainer.c
index 3d9da38567..5935b7e001 100644
--- a/app/core/gimpcontainer.c
+++ b/app/core/gimpcontainer.c
@@ -192,6 +192,7 @@ gimp_container_class_init (GimpContainerClass *klass)
   klass->clear                   = NULL;
   klass->have                    = NULL;
   klass->foreach                 = NULL;
+  klass->get_unique_names        = NULL;
   klass->get_child_by_name       = NULL;
   klass->get_child_by_index      = NULL;
   klass->get_child_index         = NULL;
@@ -413,7 +414,7 @@ gimp_container_deserialize (GimpConfig *config,
 
         case G_TOKEN_IDENTIFIER:
           {
-            GimpObject *child;
+            GimpObject *child     = NULL;
             GType       type;
             gchar      *name      = NULL;
             gboolean    add_child = FALSE;
@@ -454,7 +455,8 @@ gimp_container_deserialize (GimpConfig *config,
             if (! name)
               name = g_strdup ("");
 
-            child = gimp_container_get_child_by_name (container, name);
+            if (gimp_container_get_unique_names (container))
+              child = gimp_container_get_child_by_name (container, name);
 
             if (! child)
               {
@@ -816,6 +818,17 @@ gimp_container_foreach (GimpContainer *container,
     GIMP_CONTAINER_GET_CLASS (container)->foreach (container, func, user_data);
 }
 
+gboolean
+gimp_container_get_unique_names (GimpContainer *container)
+{
+  g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE);
+
+  if (GIMP_CONTAINER_GET_CLASS (container)->get_unique_names)
+    return GIMP_CONTAINER_GET_CLASS (container)->get_unique_names (container);
+
+  return FALSE;
+}
+
 GimpObject *
 gimp_container_get_child_by_name (GimpContainer *container,
                                   const gchar   *name)
diff --git a/app/core/gimpcontainer.h b/app/core/gimpcontainer.h
index 8b428599fa..1966e3f795 100644
--- a/app/core/gimpcontainer.h
+++ b/app/core/gimpcontainer.h
@@ -65,6 +65,7 @@ struct _GimpContainerClass
   void         (* foreach)            (GimpContainer *container,
                                        GFunc          func,
                                        gpointer       user_data);
+  gboolean     (* get_unique_names)   (GimpContainer *container);
   GimpObject * (* get_child_by_name)  (GimpContainer *container,
                                        const gchar   *name);
   GimpObject * (* get_child_by_index) (GimpContainer *container,
@@ -104,6 +105,8 @@ void         gimp_container_foreach            (GimpContainer *container,
                                                 GFunc          func,
                                                 gpointer       user_data);
 
+gboolean     gimp_container_get_unique_names   (GimpContainer *container);
+
 GimpObject * gimp_container_get_child_by_name  (GimpContainer *container,
                                                 const gchar   *name);
 GimpObject * gimp_container_get_child_by_index (GimpContainer *container,
diff --git a/app/core/gimplist.c b/app/core/gimplist.c
index 018ee85fda..3401dde0a0 100644
--- a/app/core/gimplist.c
+++ b/app/core/gimplist.c
@@ -68,6 +68,7 @@ static gboolean     gimp_list_have               (GimpContainer *container,
 static void         gimp_list_foreach            (GimpContainer *container,
                                                   GFunc          func,
                                                   gpointer       user_data);
+static gboolean     gimp_list_get_unique_names   (GimpContainer *container);
 static GimpObject * gimp_list_get_child_by_name  (GimpContainer *container,
                                                   const gchar   *name);
 static GimpObject * gimp_list_get_child_by_index (GimpContainer *container,
@@ -105,6 +106,7 @@ gimp_list_class_init (GimpListClass *klass)
   container_class->clear              = gimp_list_clear;
   container_class->have               = gimp_list_have;
   container_class->foreach            = gimp_list_foreach;
+  container_class->get_unique_names   = gimp_list_get_unique_names;
   container_class->get_child_by_name  = gimp_list_get_child_by_name;
   container_class->get_child_by_index = gimp_list_get_child_by_index;
   container_class->get_child_index    = gimp_list_get_child_index;
@@ -328,6 +330,14 @@ gimp_list_foreach (GimpContainer *container,
   g_queue_foreach (list->queue, func, user_data);
 }
 
+static gboolean
+gimp_list_get_unique_names (GimpContainer *container)
+{
+  GimpList *list = GIMP_LIST (container);
+
+  return list->unique_names;
+}
+
 static GimpObject *
 gimp_list_get_child_by_name (GimpContainer *container,
                              const gchar   *name)
diff --git a/app/widgets/gimpdevicemanager.c b/app/widgets/gimpdevicemanager.c
index e98b18fea5..bc07ff4ff0 100644
--- a/app/widgets/gimpdevicemanager.c
+++ b/app/widgets/gimpdevicemanager.c
@@ -275,7 +275,7 @@ gimp_device_manager_new (Gimp *gimp)
                        "gimp",          gimp,
                        "children-type", GIMP_TYPE_DEVICE_INFO,
                        "policy",        GIMP_CONTAINER_POLICY_STRONG,
-                       "unique-names",  FALSE,
+                       "unique-names",  TRUE,
                        "sort-func",     gimp_device_info_compare,
                        NULL);
 }


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