Disallow to rename the layer mask. Instead, always name the mask "<layer

2004-02-01  Michael Natterer  <mitch@gimp.org>

	Disallow to rename the layer mask. Instead, always name the mask
	"<layer name> mask". Fixes bug #133112 along with some other
	unreported ones.

	* app/core/gimpitem.[ch]: added a boolean return value indicating
	success to GimpItem::rename().

	(gimp_item_real_rename): push an undo step only if the item is
	attached.

	* app/core/gimplayer.c (gimp_layer_rename): refuse renaming if
	the layer is a floating selection floated from a channel
	(renaming a layer's floating selection makes a new layer out
	of the floating selection).

	(gimp_layer_duplicate): use gimp_layer_add_mask() to attach the
	mask's duplicate. Fixes mask refcount brokenness for duplicated
	layer masks.

	(gimp_layer_name_changed): new function. Automatically renames the
	layer mask when the layer's name changes.

	* app/core/gimplayermask.c (gimp_layer_mask_rename): new function
	which refuses renaming.

	(gimp_layer_mask_name_changed): skip the unique name voodoo
	GimpItem does by not chaining up.

	(gimp_layer_mask_set_layer): change the mask's name whenever it is
	attached to a layer.

	* app/text/gimptextlayer.c (gimp_text_layer_rename): fiddle with
	text_layer->auto_rename only if renaming was successful.

	* app/widgets/gimpitemtreeview.c (gimp_item_tree_view_name_edited):
	restore the old name if renaming failed.

	* tools/pdbgen/pdb/drawable.pdb (set_name): return an execution
	error if renaming failed.

	* app/pdb/drawable_cmds.c: regenerated.
This commit is contained in:
Michael Natterer 2004-02-01 20:38:26 +00:00 committed by Michael Natterer
parent dc2e81ca52
commit 82276adaa4
9 changed files with 174 additions and 61 deletions

View File

@ -1,3 +1,47 @@
2004-02-01 Michael Natterer <mitch@gimp.org>
Disallow to rename the layer mask. Instead, always name the mask
"<layer name> mask". Fixes bug #133112 along with some other
unreported ones.
* app/core/gimpitem.[ch]: added a boolean return value indicating
success to GimpItem::rename().
(gimp_item_real_rename): push an undo step only if the item is
attached.
* app/core/gimplayer.c (gimp_layer_rename): refuse renaming if
the layer is a floating selection floated from a channel
(renaming a layer's floating selection makes a new layer out
of the floating selection).
(gimp_layer_duplicate): use gimp_layer_add_mask() to attach the
mask's duplicate. Fixes mask refcount brokenness for duplicated
layer masks.
(gimp_layer_name_changed): new function. Automatically renames the
layer mask when the layer's name changes.
* app/core/gimplayermask.c (gimp_layer_mask_rename): new function
which refuses renaming.
(gimp_layer_mask_name_changed): skip the unique name voodoo
GimpItem does by not chaining up.
(gimp_layer_mask_set_layer): change the mask's name whenever it is
attached to a layer.
* app/text/gimptextlayer.c (gimp_text_layer_rename): fiddle with
text_layer->auto_rename only if renaming was successful.
* app/widgets/gimpitemtreeview.c (gimp_item_tree_view_name_edited):
restore the old name if renaming failed.
* tools/pdbgen/pdb/drawable.pdb (set_name): return an execution
error if renaming failed.
* app/pdb/drawable_cmds.c: regenerated.
2004-02-01 Michael Natterer <mitch@gimp.org>
* app/xcf/xcf-load.c (xcf_load_layer): no need to set the layer

View File

@ -75,7 +75,7 @@ static GimpItem * gimp_item_real_convert (GimpItem *item,
GimpImage *dest_image,
GType new_type,
gboolean add_alpha);
static void gimp_item_real_rename (GimpItem *item,
static gboolean gimp_item_real_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
static void gimp_item_real_translate (GimpItem *item,
@ -235,11 +235,9 @@ gimp_item_finalize (GObject *object)
static void
gimp_item_name_changed (GimpObject *object)
{
GimpItem *item;
GimpItem *item = GIMP_ITEM (object);
GimpList *list = NULL;
item = GIMP_ITEM (object);
/* if no other items to check name against */
if (item->gimage == NULL)
return;
@ -259,11 +257,9 @@ static gint64
gimp_item_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpItem *item;
GimpItem *item = GIMP_ITEM (object);
gint64 memsize = 0;
item = GIMP_ITEM (object);
memsize += gimp_object_get_memsize (GIMP_OBJECT (item->parasites), gui_size);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
@ -337,15 +333,17 @@ gimp_item_real_convert (GimpItem *item,
return gimp_item_duplicate (item, new_type, add_alpha);
}
static void
static gboolean
gimp_item_real_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc)
{
if (item->gimage)
if (gimp_item_is_attached (item))
gimp_image_undo_push_item_rename (item->gimage, undo_desc, item);
gimp_object_set_name (GIMP_OBJECT (item), new_name);
return TRUE;
}
static void
@ -492,13 +490,13 @@ gimp_item_convert (GimpItem *item,
return new_item;
}
void
gboolean
gimp_item_rename (GimpItem *item,
const gchar *new_name)
{
GimpItemClass *item_class;
g_return_if_fail (GIMP_IS_ITEM (item));
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
item_class = GIMP_ITEM_GET_CLASS (item);
@ -506,7 +504,9 @@ gimp_item_rename (GimpItem *item,
new_name = item_class->default_name;
if (strcmp (new_name, gimp_object_get_name (GIMP_OBJECT (item))))
item_class->rename (item, new_name, item_class->rename_desc);
return item_class->rename (item, new_name, item_class->rename_desc);
return TRUE;
}
gint

View File

@ -71,7 +71,7 @@ struct _GimpItemClass
GimpImage *dest_image,
GType new_type,
gboolean add_alpha);
void (* rename) (GimpItem *item,
gboolean (* rename) (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
void (* translate) (GimpItem *item,
@ -139,7 +139,7 @@ GimpItem * gimp_item_convert (GimpItem *item,
GType new_type,
gboolean add_alpha);
void gimp_item_rename (GimpItem *item,
gboolean gimp_item_rename (GimpItem *item,
const gchar *new_name);
gint gimp_item_width (const GimpItem *item);

View File

@ -65,6 +65,7 @@ static void gimp_layer_init (GimpLayer *layer);
static void gimp_layer_dispose (GObject *object);
static void gimp_layer_finalize (GObject *object);
static void gimp_layer_name_changed (GimpObject *object);
static gint64 gimp_layer_get_memsize (GimpObject *object,
gint64 *gui_size);
@ -78,7 +79,7 @@ static GimpItem * gimp_layer_convert (GimpItem *item,
GimpImage *dest_image,
GType new_type,
gboolean add_alpha);
static void gimp_layer_rename (GimpItem *item,
static gboolean gimp_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
static void gimp_layer_translate (GimpItem *item,
@ -220,6 +221,7 @@ gimp_layer_class_init (GimpLayerClass *klass)
object_class->dispose = gimp_layer_dispose;
object_class->finalize = gimp_layer_finalize;
gimp_object_class->name_changed = gimp_layer_name_changed;
gimp_object_class->get_memsize = gimp_layer_get_memsize;
viewable_class->default_stock_id = "gimp-layer";
@ -306,15 +308,30 @@ gimp_layer_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_layer_name_changed (GimpObject *object)
{
GimpLayer *layer = GIMP_LAYER (object);
GIMP_OBJECT_CLASS (parent_class)->name_changed (object);
if (layer->mask)
{
gchar *mask_name;
mask_name = g_strdup_printf (_("%s mask"), gimp_object_get_name (object));
gimp_object_set_name (GIMP_OBJECT (layer->mask), mask_name);
g_free (mask_name);
}
}
static gint64
gimp_layer_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpLayer *layer;
GimpLayer *layer = GIMP_LAYER (object);
gint64 memsize = 0;
layer = GIMP_LAYER (object);
if (layer->mask)
memsize += gimp_object_get_memsize (GIMP_OBJECT (layer->mask), gui_size);
@ -343,8 +360,8 @@ static void
gimp_layer_get_active_components (const GimpDrawable *drawable,
gboolean *active)
{
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (drawable));
GimpLayer *layer = GIMP_LAYER (drawable);
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (drawable));
gint i;
/* first copy the gimage active channels */
@ -389,12 +406,12 @@ gimp_layer_duplicate (GimpItem *item,
/* duplicate the layer mask if necessary */
if (layer->mask)
{
new_layer->mask =
GimpLayerMask *layer_mask =
GIMP_LAYER_MASK (gimp_item_duplicate (GIMP_ITEM (layer->mask),
G_TYPE_FROM_INSTANCE (layer->mask),
FALSE));
gimp_layer_mask_set_layer (new_layer->mask, new_layer);
gimp_layer_add_mask (new_layer, layer_mask, FALSE);
}
return new_item;
@ -496,30 +513,42 @@ gimp_layer_convert (GimpItem *item,
return new_item;
}
static void
static gboolean
gimp_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc)
{
GimpLayer *layer = GIMP_LAYER (item);
GimpImage *gimage;
gboolean floating_sel = FALSE;
gboolean attached;
gboolean floating_sel;
gimage = gimp_item_get_image (item);
floating_sel = gimp_layer_is_floating_sel (GIMP_LAYER (item));
if (gimage && floating_sel)
attached = gimp_item_is_attached (item);
floating_sel = gimp_layer_is_floating_sel (layer);
if (floating_sel)
{
gimp_image_undo_group_start (gimage,
GIMP_UNDO_GROUP_ITEM_PROPERTIES,
undo_desc);
if (GIMP_IS_CHANNEL (layer->fs.drawable))
return FALSE;
floating_sel_to_layer (GIMP_LAYER (item));
if (attached)
{
gimp_image_undo_group_start (gimage,
GIMP_UNDO_GROUP_ITEM_PROPERTIES,
undo_desc);
floating_sel_to_layer (layer);
}
}
GIMP_ITEM_CLASS (parent_class)->rename (item, new_name, undo_desc);
if (gimage && floating_sel)
if (attached && floating_sel)
gimp_image_undo_group_end (gimage);
return TRUE;
}
static void
@ -528,9 +557,7 @@ gimp_layer_translate (GimpItem *item,
gint offset_y,
gboolean push_undo)
{
GimpLayer *layer;
layer = GIMP_LAYER (item);
GimpLayer *layer = GIMP_LAYER (item);
if (push_undo)
gimp_image_undo_push_item_displace (gimp_item_get_image (item),
@ -567,10 +594,9 @@ gimp_layer_scale (GimpItem *item,
gint new_offset_y,
GimpInterpolationType interpolation_type)
{
GimpLayer *layer;
GimpLayer *layer = GIMP_LAYER (item);
GimpImage *gimage;
layer = GIMP_LAYER (item);
gimage = gimp_item_get_image (item);
if (layer->mask)
@ -605,10 +631,9 @@ gimp_layer_resize (GimpItem *item,
gint offset_x,
gint offset_y)
{
GimpLayer *layer;
GimpLayer *layer = GIMP_LAYER (item);
GimpImage *gimage;
layer = GIMP_LAYER (item);
gimage = gimp_item_get_image (item);
if (layer->mask)
@ -638,10 +663,9 @@ gimp_layer_flip (GimpItem *item,
gdouble axis,
gboolean clip_result)
{
GimpLayer *layer;
GimpLayer *layer = GIMP_LAYER (item);
GimpImage *gimage;
layer = GIMP_LAYER (item);
gimage = gimp_item_get_image (item);
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_TRANSFORM,
@ -667,10 +691,9 @@ gimp_layer_rotate (GimpItem *item,
gdouble center_y,
gboolean clip_result)
{
GimpLayer *layer;
GimpLayer *layer = GIMP_LAYER (item);
GimpImage *gimage;
layer = GIMP_LAYER (item);
gimage = gimp_item_get_image (item);
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_TRANSFORM,
@ -700,10 +723,9 @@ gimp_layer_transform (GimpItem *item,
GimpProgressFunc progress_callback,
gpointer progress_data)
{
GimpLayer *layer;
GimpLayer *layer = GIMP_LAYER (item);
GimpImage *gimage;
layer = GIMP_LAYER (item);
gimage = gimp_item_get_image (item);
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_TRANSFORM,
@ -729,12 +751,10 @@ gimp_layer_transform (GimpItem *item,
static void
gimp_layer_invalidate_boundary (GimpDrawable *drawable)
{
GimpLayer *layer;
GimpLayer *layer = GIMP_LAYER (drawable);
GimpImage *gimage;
GimpChannel *mask;
layer = GIMP_LAYER (drawable);
if (! (gimage = gimp_item_get_image (GIMP_ITEM (layer))))
return;

View File

@ -47,10 +47,15 @@ enum
static void gimp_layer_mask_class_init (GimpLayerMaskClass *klass);
static void gimp_layer_mask_init (GimpLayerMask *layer_mask);
static gboolean gimp_layer_mask_is_attached (GimpItem *item);
static GimpItem * gimp_layer_mask_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
static void gimp_layer_mask_name_changed (GimpObject *object);
static gboolean gimp_layer_mask_is_attached (GimpItem *item);
static GimpItem * gimp_layer_mask_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
static gboolean gimp_layer_mask_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
static guint layer_mask_signals[LAST_SIGNAL] = { 0 };
@ -89,11 +94,13 @@ gimp_layer_mask_get_type (void)
static void
gimp_layer_mask_class_init (GimpLayerMaskClass *klass)
{
GimpItemClass *item_class;
GimpObjectClass *gimp_object_class;
GimpViewableClass *viewable_class;
GimpItemClass *item_class;
item_class = GIMP_ITEM_CLASS (klass);
viewable_class = GIMP_VIEWABLE_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
viewable_class = GIMP_VIEWABLE_CLASS (klass);
item_class = GIMP_ITEM_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@ -124,10 +131,13 @@ gimp_layer_mask_class_init (GimpLayerMaskClass *klass)
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
gimp_object_class->name_changed = gimp_layer_mask_name_changed;
viewable_class->default_stock_id = "gimp-layer-mask";
item_class->is_attached = gimp_layer_mask_is_attached;
item_class->duplicate = gimp_layer_mask_duplicate;
item_class->rename = gimp_layer_mask_rename;
}
static void
@ -139,6 +149,12 @@ gimp_layer_mask_init (GimpLayerMask *layer_mask)
layer_mask->show_mask = FALSE;
}
static void
gimp_layer_mask_name_changed (GimpObject *object)
{
/* skip unique name logic by not chaining up */
}
static gboolean
gimp_layer_mask_is_attached (GimpItem *item)
{
@ -178,6 +194,16 @@ gimp_layer_mask_duplicate (GimpItem *item,
return new_item;
}
static gboolean
gimp_layer_mask_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc)
{
/* reject renaming, layer masks are always named "<layer name> mask" */
return FALSE;
}
GimpLayerMask *
gimp_layer_mask_new (GimpImage *gimage,
gint width,
@ -217,8 +243,15 @@ gimp_layer_mask_set_layer (GimpLayerMask *layer_mask,
if (layer)
{
gchar *mask_name;
GIMP_ITEM (layer_mask)->offset_x = GIMP_ITEM (layer)->offset_x;
GIMP_ITEM (layer_mask)->offset_y = GIMP_ITEM (layer)->offset_y;
mask_name = g_strdup_printf (_("%s mask"),
gimp_object_get_name (GIMP_OBJECT (layer)));
gimp_object_set_name (GIMP_OBJECT (layer_mask), mask_name);
g_free (mask_name);
}
}

View File

@ -1054,7 +1054,7 @@ drawable_set_name_invoker (Gimp *gimp,
success = FALSE;
if (success)
gimp_item_rename (GIMP_ITEM (drawable), name);
success = gimp_item_rename (GIMP_ITEM (drawable), name);
return procedural_db_return_args (&drawable_set_name_proc, success);
}

View File

@ -65,7 +65,7 @@ static gint64 gimp_text_layer_get_memsize (GimpObject *object,
static GimpItem * gimp_text_layer_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
static void gimp_text_layer_rename (GimpItem *item,
static gboolean gimp_text_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
@ -230,14 +230,19 @@ gimp_text_layer_duplicate (GimpItem *item,
return new_item;
}
static void
static gboolean
gimp_text_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc)
{
GIMP_TEXT_LAYER (item)->auto_rename = FALSE;
if (GIMP_ITEM_CLASS (parent_class)->rename (item, new_name, undo_desc))
{
GIMP_TEXT_LAYER (item)->auto_rename = FALSE;
GIMP_ITEM_CLASS (parent_class)->rename (item, new_name, undo_desc);
return TRUE;
}
return FALSE;
}
/**

View File

@ -1253,8 +1253,19 @@ gimp_item_tree_view_name_edited (GtkCellRendererText *cell,
item = GIMP_ITEM (renderer->viewable);
gimp_item_rename (item, new_text);
gimp_image_flush (gimp_item_get_image (item));
if (gimp_item_rename (item, new_text))
{
gimp_image_flush (gimp_item_get_image (item));
}
else
{
gchar *name = gimp_viewable_get_description (renderer->viewable, NULL);
gtk_list_store_set (GTK_LIST_STORE (tree_view->model), &iter,
tree_view->model_column_name, name,
-1);
g_free (name);
}
g_object_unref (renderer);
}

View File

@ -415,7 +415,7 @@ sub drawable_is_channel {
}
&drawable_accessors('name', 'string', 'name', 0, [ undef, <<'CODE' ],
$invoke{code} =~ s/gimp_object_set_name/gimp_item_rename/;
$invoke{code} =~ s/gimp_object_set_name/success = gimp_item_rename/;
$invoke{code} =~ s/GIMP_OBJECT/GIMP_ITEM/;
CODE
'object', 'GIMP_OBJECT (drawable)');