[gimp] app: handle an index of -1 generically in GimpContainer::reorder()



commit 47ec9e2e1a324f907d94729bd1e6b07038226557
Author: Michael Natterer <mitch gimp org>
Date:   Fri Oct 11 23:09:30 2013 +0200

    app: handle an index of -1 generically in GimpContainer::reorder()
    
    by turning the -1 into n_children - 1 directly in gimp_container_reorder()
    instead of having all subclasses deal with the -1 separately. Remove -1
    handling from gimp_list_reorder().
    
    Also, optimize reordering to the same index away without increasing
    the function's cost (it was doing a gimp_container_have() before, now
    it doees gimp_container_get_child_index(), which both have the same
    cost).

 app/core/gimpcontainer.c |   17 +++++++++++------
 app/core/gimplist.c      |    3 +--
 2 files changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/app/core/gimpcontainer.c b/app/core/gimpcontainer.c
index 0157e39..1e4942e 100644
--- a/app/core/gimpcontainer.c
+++ b/app/core/gimpcontainer.c
@@ -707,6 +707,8 @@ gimp_container_reorder (GimpContainer *container,
                         GimpObject    *object,
                         gint           new_index)
 {
+  gint index;
+
   g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE);
   g_return_val_if_fail (object != NULL, FALSE);
   g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (object,
@@ -716,18 +718,21 @@ gimp_container_reorder (GimpContainer *container,
   g_return_val_if_fail (new_index >= -1 &&
                         new_index < container->priv->n_children, FALSE);
 
-  if (! gimp_container_have (container, object))
+  if (new_index == -1)
+    new_index = container->priv->n_children - 1;
+
+  index = gimp_container_get_child_index (container, object);
+
+  if (index == -1)
     {
       g_warning ("%s: container %p does not contain object %p",
                  G_STRFUNC, container, object);
       return FALSE;
     }
 
-  if (container->priv->n_children == 1)
-    return TRUE;
-
-  g_signal_emit (container, container_signals[REORDER], 0,
-                 object, new_index);
+  if (index != new_index)
+    g_signal_emit (container, container_signals[REORDER], 0,
+                   object, new_index);
 
   return TRUE;
 }
diff --git a/app/core/gimplist.c b/app/core/gimplist.c
index 7fcf7aa..0ae918c 100644
--- a/app/core/gimplist.c
+++ b/app/core/gimplist.c
@@ -258,8 +258,7 @@ gimp_list_reorder (GimpContainer *container,
 
   list->list = g_list_remove (list->list, object);
 
-  if (new_index == -1 ||
-      new_index == gimp_container_get_n_children (container) - 1)
+  if (new_index == gimp_container_get_n_children (container) - 1)
     list->list = g_list_append (list->list, object);
   else
     list->list = g_list_insert (list->list, object, new_index);


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