From 6a08376d4962e7c583e662709ce25d89f0d9dba0 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Wed, 2 Feb 2011 19:40:20 +0100 Subject: [PATCH] app: add new virtual function GimpItem::unset_removed() and implement it in GimpLayer to unset the removed flag on the layer mask. Remove layer mask special casing from gimp_image_add_layer(). Make sure that all an item's children get their removed flag unset in gimp_item_unset_removed(). --- app/core/gimpimage.c | 11 ----------- app/core/gimpitem.c | 11 +++++++++++ app/core/gimpitem.h | 1 + app/core/gimplayer.c | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index e0ab23296f..5b234f32e7 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -3471,17 +3471,6 @@ gimp_image_add_layer (GimpImage *image, if (old_has_alpha != gimp_image_has_alpha (image)) private->flush_accum.alpha_changed = TRUE; - if (gimp_layer_get_mask (layer)) - { - GimpLayerMask *mask = gimp_layer_get_mask (layer); - - /* if the layer came from the undo stack, - * reset the mask's "removed" state - */ - if (gimp_item_is_removed (GIMP_ITEM (mask))) - gimp_item_unset_removed (GIMP_ITEM (mask)); - } - return TRUE; } diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c index c86f1b09f2..8c35a9c572 100644 --- a/app/core/gimpitem.c +++ b/app/core/gimpitem.c @@ -215,6 +215,7 @@ gimp_item_class_init (GimpItemClass *klass) klass->linked_changed = NULL; klass->lock_content_changed = NULL; + klass->unset_removed = NULL; klass->is_attached = NULL; klass->is_content_locked = gimp_item_real_is_content_locked; klass->get_tree = NULL; @@ -738,10 +739,20 @@ gimp_item_is_removed (const GimpItem *item) void gimp_item_unset_removed (GimpItem *item) { + GimpContainer *children; + g_return_if_fail (GIMP_IS_ITEM (item)); g_return_if_fail (gimp_item_is_removed (item)); GET_PRIVATE (item)->removed = FALSE; + + children = gimp_viewable_get_children (GIMP_VIEWABLE (item)); + + if (children) + gimp_container_foreach (children, (GFunc) gimp_item_unset_removed, NULL); + + if (GIMP_ITEM_GET_CLASS (item)->unset_removed) + GIMP_ITEM_GET_CLASS (item)->unset_removed (item); } /** diff --git a/app/core/gimpitem.h b/app/core/gimpitem.h index 402758feef..5d3ef5afda 100644 --- a/app/core/gimpitem.h +++ b/app/core/gimpitem.h @@ -50,6 +50,7 @@ struct _GimpItemClass void (* lock_content_changed) (GimpItem *item); /* virtual functions */ + void (* unset_removed) (GimpItem *item); gboolean (* is_attached) (const GimpItem *item); gboolean (* is_content_locked) (const GimpItem *item); GimpItemTree * (* get_tree) (GimpItem *item); diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c index b27381d958..3d46685c57 100644 --- a/app/core/gimplayer.c +++ b/app/core/gimplayer.c @@ -97,6 +97,7 @@ static gchar * gimp_layer_get_description (GimpViewable *viewable, gchar **tooltip); static void gimp_layer_removed (GimpItem *item); +static void gimp_layer_unset_removed (GimpItem *item); static gboolean gimp_layer_is_attached (const GimpItem *item); static GimpItemTree * gimp_layer_get_tree (GimpItem *item); static GimpItem * gimp_layer_duplicate (GimpItem *item, @@ -249,6 +250,7 @@ gimp_layer_class_init (GimpLayerClass *klass) viewable_class->get_description = gimp_layer_get_description; item_class->removed = gimp_layer_removed; + item_class->unset_removed = gimp_layer_unset_removed; item_class->is_attached = gimp_layer_is_attached; item_class->get_tree = gimp_layer_get_tree; item_class->duplicate = gimp_layer_duplicate; @@ -493,6 +495,18 @@ gimp_layer_removed (GimpItem *item) GIMP_ITEM_CLASS (parent_class)->removed (item); } +static void +gimp_layer_unset_removed (GimpItem *item) +{ + GimpLayer *layer = GIMP_LAYER (item); + + if (layer->mask) + gimp_item_unset_removed (GIMP_ITEM (layer->mask)); + + if (GIMP_ITEM_CLASS (parent_class)->unset_removed) + GIMP_ITEM_CLASS (parent_class)->unset_removed (item); +} + static gboolean gimp_layer_is_attached (const GimpItem *item) {