[gimp] app: add gimp_container_get_neighbor_of() to GimpContainer



commit 8184296b3cf7308921962af71b54a604070f717d
Author: Michael Natterer <mitch gimp org>
Date:   Sun Mar 13 02:14:44 2011 +0100

    app: add gimp_container_get_neighbor_of() to GimpContainer
    
    instead of gimp_container_get_neighbor_of_active() in gimp-utils.c.
    Move the additional GimpContext logic of the old function into the
    callers, but use the new function in more places.

 app/actions/data-commands.c           |   19 +++++++++++++------
 app/actions/templates-commands.c      |   12 +++++++-----
 app/core/gimp-utils.c                 |   30 ------------------------------
 app/core/gimp-utils.h                 |    4 ----
 app/core/gimpcontainer.c              |   26 ++++++++++++++++++++++++++
 app/core/gimpcontainer.h              |    3 +++
 app/widgets/gimpcontainerview-utils.c |   13 ++++++-------
 app/widgets/gimpsettingseditor.c      |   23 ++++++-----------------
 8 files changed, 61 insertions(+), 69 deletions(-)
---
diff --git a/app/actions/data-commands.c b/app/actions/data-commands.c
index f15d93b..d5b0f1e 100644
--- a/app/actions/data-commands.c
+++ b/app/actions/data-commands.c
@@ -24,7 +24,6 @@
 #include "actions-types.h"
 
 #include "core/gimp.h"
-#include "core/gimp-utils.h"
 #include "core/gimpcontainer.h"
 #include "core/gimpcontext.h"
 #include "core/gimpdata.h"
@@ -324,14 +323,22 @@ data_delete_confirm_response (GtkWidget          *dialog,
 
   if (response_id == GTK_RESPONSE_OK)
     {
-      GimpDataFactory *factory    = gimp_data_factory_view_get_data_factory (delete_data->view);
+      GimpDataFactory *factory;
+      GimpContainer   *container;
       GimpData        *data       = delete_data->data;
-      GimpObject      *new_active;
+      GimpObject      *new_active = NULL;
       GError          *error      = NULL;
 
-      new_active = gimp_container_get_neighbor_of_active (gimp_data_factory_get_container (factory),
-                                                          delete_data->context,
-                                                          GIMP_OBJECT (data));
+      factory    = gimp_data_factory_view_get_data_factory (delete_data->view);
+      container  = gimp_data_factory_get_container (factory);
+
+      if (GIMP_OBJECT (data) ==
+          gimp_context_get_by_type (delete_data->context,
+                                    gimp_container_get_children_type (container)))
+        {
+          new_active = gimp_container_get_neighbor_of (container,
+                                                       GIMP_OBJECT (data));
+        }
 
       if (! gimp_data_factory_data_delete (factory, data, TRUE, &error))
         {
diff --git a/app/actions/templates-commands.c b/app/actions/templates-commands.c
index 9769f87..c65546b 100644
--- a/app/actions/templates-commands.c
+++ b/app/actions/templates-commands.c
@@ -27,7 +27,6 @@
 #include "config/gimpcoreconfig.h"
 
 #include "core/gimp.h"
-#include "core/gimp-utils.h"
 #include "core/gimpcontainer.h"
 #include "core/gimpcontext.h"
 #include "core/gimpimage-new.h"
@@ -292,11 +291,14 @@ templates_delete_response (GtkWidget          *dialog,
 {
   if (response_id == GTK_RESPONSE_OK)
     {
-      GimpObject *new_active;
+      GimpObject *new_active = NULL;
 
-      new_active = gimp_container_get_neighbor_of_active (delete_data->container,
-                                                          delete_data->context,
-                                                          GIMP_OBJECT (delete_data->template));
+      if (delete_data->template ==
+          gimp_context_get_template (delete_data->context))
+        {
+          new_active = gimp_container_get_neighbor_of (delete_data->container,
+                                                       GIMP_OBJECT (delete_data->template));
+        }
 
       if (gimp_container_have (delete_data->container,
                                GIMP_OBJECT (delete_data->template)))
diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c
index 5b2ad6c..a6ebd0b 100644
--- a/app/core/gimp-utils.c
+++ b/app/core/gimp-utils.c
@@ -499,36 +499,6 @@ gimp_get_temp_filename (Gimp        *gimp,
   return filename;
 }
 
-GimpObject *
-gimp_container_get_neighbor_of_active (GimpContainer *container,
-                                       GimpContext   *context,
-                                       GimpObject    *active)
-{
-  g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
-  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
-  g_return_val_if_fail (GIMP_IS_OBJECT (active), NULL);
-
-  if (active == gimp_context_get_by_type (context,
-                                          gimp_container_get_children_type (container)))
-    {
-      gint index = gimp_container_get_child_index (container, active);
-
-      if (index != -1)
-        {
-          GimpObject *new;
-
-          new = gimp_container_get_child_by_index (container, index + 1);
-
-          if (! new && index > 0)
-            new = gimp_container_get_child_by_index (container, index - 1);
-
-          return new;
-        }
-    }
-
-  return NULL;
-}
-
 /*  markup unescape code stolen and adapted from gmarkup.c
  */
 static gchar *
diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h
index 96043fc..91fad8d 100644
--- a/app/core/gimp-utils.h
+++ b/app/core/gimp-utils.h
@@ -72,10 +72,6 @@ void         gimp_value_array_truncate             (GValueArray     *args,
 gchar      * gimp_get_temp_filename                (Gimp            *gimp,
                                                     const gchar     *extension);
 
-GimpObject * gimp_container_get_neighbor_of_active (GimpContainer   *container,
-                                                    GimpContext     *context,
-                                                    GimpObject      *active);
-
 gchar      * gimp_markup_extract_text              (const gchar     *markup);
 
 const gchar* gimp_enum_get_value_name              (GType            enum_type,
diff --git a/app/core/gimpcontainer.c b/app/core/gimpcontainer.c
index bf118c1..69928d6 100644
--- a/app/core/gimpcontainer.c
+++ b/app/core/gimpcontainer.c
@@ -886,6 +886,32 @@ gimp_container_get_child_index (const GimpContainer *container,
                                                                 object);
 }
 
+GimpObject *
+gimp_container_get_neighbor_of (const GimpContainer *container,
+                                const GimpObject    *object)
+{
+  gint index;
+
+  g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
+  g_return_val_if_fail (GIMP_IS_OBJECT (object), NULL);
+
+  index = gimp_container_get_child_index (container, object);
+
+  if (index != -1)
+    {
+      GimpObject *new;
+
+      new = gimp_container_get_child_by_index (container, index + 1);
+
+      if (! new && index > 0)
+        new = gimp_container_get_child_by_index (container, index - 1);
+
+      return new;
+    }
+
+  return NULL;
+}
+
 static void
 gimp_container_get_name_array_foreach_func (GimpObject   *object,
                                             gchar      ***iter)
diff --git a/app/core/gimpcontainer.h b/app/core/gimpcontainer.h
index 9a8c688..99e86bf 100644
--- a/app/core/gimpcontainer.h
+++ b/app/core/gimpcontainer.h
@@ -112,6 +112,9 @@ GimpObject * gimp_container_get_last_child     (const GimpContainer *container);
 gint         gimp_container_get_child_index    (const GimpContainer *container,
                                                 const GimpObject    *object);
 
+GimpObject * gimp_container_get_neighbor_of    (const GimpContainer *container,
+                                                const GimpObject    *object);
+
 gchar     ** gimp_container_get_name_array     (const GimpContainer *container,
                                                 gint                *length);
 
diff --git a/app/widgets/gimpcontainerview-utils.c b/app/widgets/gimpcontainerview-utils.c
index fdf00a2..9304151 100644
--- a/app/widgets/gimpcontainerview-utils.c
+++ b/app/widgets/gimpcontainerview-utils.c
@@ -21,7 +21,6 @@
 
 #include "widgets-types.h"
 
-#include "core/gimp-utils.h"
 #include "core/gimpcontainer.h"
 #include "core/gimpcontext.h"
 
@@ -70,21 +69,21 @@ gimp_container_view_remove_active (GimpContainerView *view)
 
   if (context && container)
     {
+      GType       children_type;
       GimpObject *active;
 
-      active = gimp_context_get_by_type (context, gimp_container_get_children_type (container));
+      children_type = gimp_container_get_children_type (container);
+
+      active = gimp_context_get_by_type (context, children_type);
 
       if (active)
         {
           GimpObject *new;
 
-          new = gimp_container_get_neighbor_of_active (container, context,
-                                                       active);
+          new = gimp_container_get_neighbor_of (container, active);
 
           if (new)
-            gimp_context_set_by_type (context,
-                                      gimp_container_get_children_type (container),
-                                      new);
+            gimp_context_set_by_type (context, children_type, new);
 
           gimp_container_remove (container, active);
         }
diff --git a/app/widgets/gimpsettingseditor.c b/app/widgets/gimpsettingseditor.c
index 097b90a..a554e86 100644
--- a/app/widgets/gimpsettingseditor.c
+++ b/app/widgets/gimpsettingseditor.c
@@ -347,25 +347,14 @@ gimp_settings_editor_delete_clicked (GtkWidget          *widget,
 
   if (private->selected_setting)
     {
-      GimpObject *new = NULL;
-      gint        index;
+      GimpObject *new;
 
-      index = gimp_container_get_child_index (private->container,
-                                              GIMP_OBJECT (private->selected_setting));
+      new = gimp_container_get_neighbor_of (private->container,
+                                            GIMP_OBJECT (private->selected_setting));
 
-      if (index != -1)
-        {
-          new = gimp_container_get_child_by_index (private->container,
-                                                   index + 1);
-
-          if (! new && index > 0)
-            new = gimp_container_get_child_by_index (private->container,
-                                                     index - 1);
-
-          /*  don't select the separator  */
-          if (new && ! gimp_object_get_name (new))
-            new = NULL;
-        }
+      /*  don't select the separator  */
+      if (new && ! gimp_object_get_name (new))
+        new = NULL;
 
       gimp_container_remove (private->container,
                              GIMP_OBJECT (private->selected_setting));



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