gimp r25426 - in trunk: . app/actions app/core app/dialogs app/gui app/widgets



Author: neo
Date: Wed Apr  9 10:50:29 2008
New Revision: 25426
URL: http://svn.gnome.org/viewvc/gimp?rev=25426&view=rev

Log:
2008-04-09  Sven Neumann  <sven gimp org>

	* app/core/gimpcontainer.[ch]: added new methods
	gimp_container_get_{first,last}_child().

	* app/actions/file-actions.c (file_actions_close_all_update)
	* app/dialogs/layer-add-mask-dialog.c (layer_add_mask_dialog_new)
	* app/dialogs/palette-import-dialog.c (palette_import_image_callback)
	* app/gui/gui-vtable.c (gui_get_empty_display): 
	* app/widgets/gimpmenudock.c (gimp_menu_dock_image_changed): use
	the new GimpContainer methods.

	* app/core/gimpundostack.c: use the new GimpContainer methods and
	cleaned up the code.


Modified:
   trunk/ChangeLog
   trunk/app/actions/file-actions.c
   trunk/app/core/gimpcontainer.c
   trunk/app/core/gimpcontainer.h
   trunk/app/core/gimpundostack.c
   trunk/app/dialogs/layer-add-mask-dialog.c
   trunk/app/dialogs/palette-import-dialog.c
   trunk/app/gui/gui-vtable.c
   trunk/app/widgets/gimpmenudock.c

Modified: trunk/app/actions/file-actions.c
==============================================================================
--- trunk/app/actions/file-actions.c	(original)
+++ trunk/app/actions/file-actions.c	Wed Apr  9 10:50:29 2008
@@ -335,8 +335,9 @@
 
   if (n_displays == 1)
     {
-      GimpDisplay *display = (GimpDisplay *)
-        gimp_container_get_child_by_index (container, 0);
+      GimpDisplay *display;
+
+      display = GIMP_DISPLAY (gimp_container_get_first_child (container));
 
       if (! display->image)
         sensitive = FALSE;

Modified: trunk/app/core/gimpcontainer.c
==============================================================================
--- trunk/app/core/gimpcontainer.c	(original)
+++ trunk/app/core/gimpcontainer.c	Wed Apr  9 10:50:29 2008
@@ -783,6 +783,44 @@
                                                                    index);
 }
 
+/**
+ * gimp_container_get_first_child:
+ * @container: a #GimpContainer
+ *
+ * Return value: the first child object stored in @container or %NULL if the
+ *               container is empty
+ */
+GimpObject *
+gimp_container_get_first_child (const GimpContainer *container)
+{
+  g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
+
+  if (container->num_children > 0)
+    return GIMP_CONTAINER_GET_CLASS (container)->get_child_by_index (container,
+                                                                     0);
+
+  return NULL;
+}
+
+/**
+ * gimp_container_get_last_child:
+ * @container: a #GimpContainer
+ *
+ * Return value: the last child object stored in @container or %NULL if the
+ *               container is empty
+ */
+GimpObject *
+gimp_container_get_last_child (const GimpContainer *container)
+{
+  g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
+
+  if (container->num_children > 0)
+    return GIMP_CONTAINER_GET_CLASS (container)->get_child_by_index (container,
+                                                                     container->num_children - 1);
+
+  return NULL;
+}
+
 gint
 gimp_container_get_child_index (const GimpContainer *container,
                                 const GimpObject    *object)

Modified: trunk/app/core/gimpcontainer.h
==============================================================================
--- trunk/app/core/gimpcontainer.h	(original)
+++ trunk/app/core/gimpcontainer.h	Wed Apr  9 10:50:29 2008
@@ -114,6 +114,8 @@
                                                 const gchar         *name);
 GimpObject * gimp_container_get_child_by_index (const GimpContainer *container,
                                                 gint                 index);
+GimpObject * gimp_container_get_first_child    (const GimpContainer *container);
+GimpObject * gimp_container_get_last_child     (const GimpContainer *container);
 gint         gimp_container_get_child_index    (const GimpContainer *container,
                                                 const GimpObject    *object);
 

Modified: trunk/app/core/gimpundostack.c
==============================================================================
--- trunk/app/core/gimpundostack.c	(original)
+++ trunk/app/core/gimpundostack.c	Wed Apr  9 10:50:29 2008
@@ -128,9 +128,7 @@
       g_object_unref (child);
     }
 
-  while (GIMP_LIST (stack->undos)->list)
-    gimp_container_remove (GIMP_CONTAINER (stack->undos),
-                           GIMP_LIST (stack->undos)->list->data);
+  gimp_container_clear (stack->undos);
 }
 
 GimpUndoStack *
@@ -150,7 +148,7 @@
   g_return_if_fail (GIMP_IS_UNDO_STACK (stack));
   g_return_if_fail (GIMP_IS_UNDO (undo));
 
-  gimp_container_add (GIMP_CONTAINER (stack->undos), GIMP_OBJECT (undo));
+  gimp_container_add (stack->undos, GIMP_OBJECT (undo));
 }
 
 GimpUndo *
@@ -163,12 +161,11 @@
   g_return_val_if_fail (GIMP_IS_UNDO_STACK (stack), NULL);
   g_return_val_if_fail (accum != NULL, NULL);
 
-  undo = (GimpUndo *)
-    gimp_container_get_child_by_index (GIMP_CONTAINER (stack->undos), 0);
+  undo = GIMP_UNDO (gimp_container_get_first_child (stack->undos));
 
   if (undo)
     {
-      gimp_container_remove (GIMP_CONTAINER (stack->undos), GIMP_OBJECT (undo));
+      gimp_container_remove (stack->undos, GIMP_OBJECT (undo));
       gimp_undo_pop (undo, undo_mode, accum);
 
       return undo;
@@ -182,19 +179,14 @@
                              GimpUndoMode   undo_mode)
 {
   GimpUndo *undo;
-  gint      n_children;
 
   g_return_val_if_fail (GIMP_IS_UNDO_STACK (stack), NULL);
 
-  n_children = gimp_container_num_children (GIMP_CONTAINER (stack->undos));
-
-  undo = (GimpUndo *)
-    gimp_container_get_child_by_index (GIMP_CONTAINER (stack->undos),
-                                       n_children - 1);
+  undo = GIMP_UNDO (gimp_container_get_last_child (stack->undos));
 
   if (undo)
     {
-      gimp_container_remove (GIMP_CONTAINER (stack->undos), GIMP_OBJECT (undo));
+      gimp_container_remove (stack->undos, GIMP_OBJECT (undo));
       gimp_undo_free (undo, undo_mode);
 
       return undo;
@@ -206,13 +198,9 @@
 GimpUndo *
 gimp_undo_stack_peek (GimpUndoStack *stack)
 {
-  GimpObject *object;
-
   g_return_val_if_fail (GIMP_IS_UNDO_STACK (stack), NULL);
 
-  object = gimp_container_get_child_by_index (GIMP_CONTAINER (stack->undos), 0);
-
-  return (object ? GIMP_UNDO (object) : NULL);
+  return GIMP_UNDO (gimp_container_get_first_child (stack->undos));
 }
 
 gint

Modified: trunk/app/dialogs/layer-add-mask-dialog.c
==============================================================================
--- trunk/app/dialogs/layer-add-mask-dialog.c	(original)
+++ trunk/app/dialogs/layer-add-mask-dialog.c	Wed Apr  9 10:50:29 2008
@@ -130,9 +130,7 @@
   channel = gimp_image_get_active_channel (GIMP_ITEM (layer)->image);
 
   if (! channel)
-    channel = GIMP_CHANNEL
-      (gimp_container_get_child_by_index (GIMP_ITEM (layer)->image->channels,
-                                          0));
+    channel = GIMP_CHANNEL (gimp_container_get_first_child (GIMP_ITEM (layer)->image->channels));
 
   gimp_container_view_select_item (GIMP_CONTAINER_VIEW (combo),
                                    GIMP_VIEWABLE (channel));

Modified: trunk/app/dialogs/palette-import-dialog.c
==============================================================================
--- trunk/app/dialogs/palette-import-dialog.c	(original)
+++ trunk/app/dialogs/palette-import-dialog.c	Wed Apr  9 10:50:29 2008
@@ -678,8 +678,11 @@
   image = gimp_context_get_image (dialog->context);
 
   if (! image)
-    image = (GimpImage *)
-      gimp_container_get_child_by_index (dialog->context->gimp->images, 0);
+    {
+      GimpContainer *images = dialog->context->gimp->images;
+
+      image = GIMP_IMAGE (gimp_container_get_first_child (images));
+    }
 
   palette_import_set_sensitive (dialog);
 

Modified: trunk/app/gui/gui-vtable.c
==============================================================================
--- trunk/app/gui/gui-vtable.c	(original)
+++ trunk/app/gui/gui-vtable.c	Wed Apr  9 10:50:29 2008
@@ -283,7 +283,7 @@
 
   if (gimp_container_num_children (gimp->displays) == 1)
     {
-      display = gimp_container_get_child_by_index (gimp->displays, 0);
+      display = gimp_container_get_first_child (gimp->displays);
 
       if (GIMP_DISPLAY (display)->image)
         {

Modified: trunk/app/widgets/gimpmenudock.c
==============================================================================
--- trunk/app/widgets/gimpmenudock.c	(original)
+++ trunk/app/widgets/gimpmenudock.c	Wed Apr  9 10:50:29 2008
@@ -558,21 +558,17 @@
 
   if (image == NULL && ! gimp_container_is_empty (image_container))
     {
-      image = GIMP_IMAGE (gimp_container_get_child_by_index (image_container,
-                                                             0));
+      image = GIMP_IMAGE (gimp_container_get_first_child (image_container));
 
-      if (image)
-        {
-          /*  this invokes this function recursively but we don't enter
-           *  the if() branch the second time
-           */
-          gimp_context_set_image (context, image);
-
-          /*  stop the emission of the original signal (the emission of
-           *  the recursive signal is finished)
-           */
-          g_signal_stop_emission_by_name (context, "image-changed");
-        }
+      /*  this invokes this function recursively but we don't enter
+       *  the if() branch the second time
+       */
+      gimp_context_set_image (context, image);
+
+      /*  stop the emission of the original signal (the emission of
+       *  the recursive signal is finished)
+       */
+      g_signal_stop_emission_by_name (context, "image-changed");
     }
   else if (image != NULL && ! gimp_container_is_empty (display_container))
     {



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