Commit 3f2385dc authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

added new methods gimp_container_get_{first,last}_child().

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.

svn path=/trunk/; revision=25426
parent e9b913d1
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.
2008-04-09 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/scripts/Makefile.am
......
......@@ -335,8 +335,9 @@ file_actions_close_all_update (GimpContainer *images,
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;
......
......@@ -783,6 +783,44 @@ gimp_container_get_child_by_index (const GimpContainer *container,
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)
......
......@@ -114,6 +114,8 @@ GimpObject * gimp_container_get_child_by_name (const GimpContainer *container,
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);
......
......@@ -128,9 +128,7 @@ gimp_undo_stack_free (GimpUndo *undo,
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 @@ gimp_undo_stack_push_undo (GimpUndoStack *stack,
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 @@ gimp_undo_stack_pop_undo (GimpUndoStack *stack,
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 @@ gimp_undo_stack_free_bottom (GimpUndoStack *stack,
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 @@ gimp_undo_stack_free_bottom (GimpUndoStack *stack,
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
......
......@@ -130,9 +130,7 @@ layer_add_mask_dialog_new (GimpLayer *layer,
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));
......
......@@ -678,8 +678,11 @@ palette_import_image_callback (GtkWidget *widget,
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);
......
......@@ -283,7 +283,7 @@ gui_get_empty_display (Gimp *gimp)
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)
{
......
......@@ -558,21 +558,17 @@ gimp_menu_dock_image_changed (GimpContext *context,
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))
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment