Commit 6642bc2c authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

removed the "name" parameter and use GimpObject's name instead.

2001-01-10  Michael Natterer  <mitch@gimp.org>

	* app/gimpdrawable.[ch]: removed the "name" parameter and use
	GimpObject's name instead.

	* app/channel.c
	* app/channel_ops.c
	* app/channels_dialog.c
	* app/drawable.h
	* app/gimpimage.c
	* app/interface.c
	* app/layer.c
	* app/layer_select.c
	* app/layers_dialog.c
	* app/qmask.c
	* app/undo.c
	* app/xcf.c: changed accordingly, cleanup.
parent 65543971
2001-01-10 Michael Natterer <mitch@gimp.org>
* app/gimpdrawable.[ch]: removed the "name" parameter and use
GimpObject's name instead.
* app/channel.c
* app/channel_ops.c
* app/channels_dialog.c
* app/drawable.h
* app/gimpimage.c
* app/interface.c
* app/layer.c
* app/layer_select.c
* app/layers_dialog.c
* app/qmask.c
* app/undo.c
* app/xcf.c: changed accordingly, cleanup.
2001-01-10 Michael Natterer <mitch@gimp.org> 2001-01-10 Michael Natterer <mitch@gimp.org>
* app/gimpbrushlist.c * app/gimpbrushlist.c
......
...@@ -229,7 +229,7 @@ qmask_activate (GtkWidget *widget, ...@@ -229,7 +229,7 @@ qmask_activate (GtkWidget *widget,
gmask = channel_copy (gimp_image_get_mask (gimg)); gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0); gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, color); channel_set_color (gmask, color);
drawable_set_name (GIMP_DRAWABLE (gmask), "Qmask"); gimp_object_set_name (GIMP_OBJECT (gmask), "Qmask");
channel_set_opacity (gmask, opacity); channel_set_opacity (gmask, opacity);
gimage_mask_none (gimg); /* Clear the selection */ gimage_mask_none (gimg); /* Clear the selection */
} }
......
...@@ -229,7 +229,7 @@ qmask_activate (GtkWidget *widget, ...@@ -229,7 +229,7 @@ qmask_activate (GtkWidget *widget,
gmask = channel_copy (gimp_image_get_mask (gimg)); gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0); gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, color); channel_set_color (gmask, color);
drawable_set_name (GIMP_DRAWABLE (gmask), "Qmask"); gimp_object_set_name (GIMP_OBJECT (gmask), "Qmask");
channel_set_opacity (gmask, opacity); channel_set_opacity (gmask, opacity);
gimage_mask_none (gimg); /* Clear the selection */ gimage_mask_none (gimg); /* Clear the selection */
} }
......
...@@ -187,7 +187,8 @@ channel_copy (const Channel *channel) ...@@ -187,7 +187,8 @@ channel_copy (const Channel *channel)
gint len; gint len;
/* formulate the new channel name */ /* formulate the new channel name */
name = drawable_get_name (GIMP_DRAWABLE (channel)); name = gimp_object_get_name (GIMP_OBJECT (channel));
ext = strrchr (name, '#'); ext = strrchr (name, '#');
len = strlen (_("copy")); len = strlen (_("copy"));
if ((strlen (name) >= len && if ((strlen (name) >= len &&
...@@ -231,13 +232,13 @@ void ...@@ -231,13 +232,13 @@ void
channel_set_name (Channel *channel, channel_set_name (Channel *channel,
const gchar *name) const gchar *name)
{ {
gimp_drawable_set_name (GIMP_DRAWABLE (channel), name); gimp_object_set_name (GIMP_OBJECT (channel), name);
} }
const gchar * const gchar *
channel_get_name (const Channel *channel) channel_get_name (const Channel *channel)
{ {
return gimp_drawable_get_name (GIMP_DRAWABLE (channel)); return gimp_object_get_name (GIMP_OBJECT (channel));
} }
void void
......
...@@ -612,8 +612,8 @@ duplicate (GimpImage *gimage) ...@@ -612,8 +612,8 @@ duplicate (GimpImage *gimage)
/* Make sure if the layer has a layer mask, it's name isn't screwed up */ /* Make sure if the layer has a layer mask, it's name isn't screwed up */
if (new_layer->mask) if (new_layer->mask)
{ {
gimp_drawable_set_name(GIMP_DRAWABLE(new_layer->mask), gimp_object_set_name (GIMP_OBJECT (new_layer->mask),
gimp_drawable_get_name(GIMP_DRAWABLE(layer->mask))); gimp_object_get_name (GIMP_OBJECT (layer->mask)));
} }
if (gimage->active_layer == layer) if (gimage->active_layer == layer)
...@@ -643,8 +643,8 @@ duplicate (GimpImage *gimage) ...@@ -643,8 +643,8 @@ duplicate (GimpImage *gimage)
gimp_drawable_set_gimage(GIMP_DRAWABLE(new_channel), new_gimage); gimp_drawable_set_gimage(GIMP_DRAWABLE(new_channel), new_gimage);
/* Make sure the copied channel doesn't say: "<old channel> copy" */ /* Make sure the copied channel doesn't say: "<old channel> copy" */
gimp_drawable_set_name(GIMP_DRAWABLE(new_channel), gimp_object_set_name (GIMP_OBJECT (new_channel),
gimp_drawable_get_name(GIMP_DRAWABLE(channel))); gimp_object_get_name (GIMP_OBJECT (channel)));
if (gimage->active_channel == channel) if (gimage->active_channel == channel)
active_channel = (new_channel); active_channel = (new_channel);
......
...@@ -1462,7 +1462,7 @@ channel_widget_create (GimpImage *gimage, ...@@ -1462,7 +1462,7 @@ channel_widget_create (GimpImage *gimage,
case AUXILLARY_CHANNEL: case AUXILLARY_CHANNEL:
channel_widget->label = channel_widget->label =
gtk_label_new (drawable_get_name (GIMP_DRAWABLE (channel))); gtk_label_new (gimp_object_get_name (GIMP_OBJECT (channel)));
break; break;
} }
...@@ -2650,10 +2650,10 @@ edit_channel_query_ok_callback (GtkWidget *widget, ...@@ -2650,10 +2650,10 @@ edit_channel_query_ok_callback (GtkWidget *widget,
if (options->gimage) if (options->gimage)
{ {
/* Set the new channel name */ /* Set the new channel name */
drawable_set_name (GIMP_DRAWABLE (channel), gimp_object_set_name (GIMP_OBJECT (channel),
gtk_entry_get_text (GTK_ENTRY (options->name_entry))); gtk_entry_get_text (GTK_ENTRY (options->name_entry)));
gtk_label_set_text (GTK_LABEL (options->channel_widget->label), gtk_label_set_text (GTK_LABEL (options->channel_widget->label),
drawable_get_name (GIMP_DRAWABLE (channel))); gimp_object_get_name (GIMP_OBJECT (channel)));
if (channel->opacity != opacity) if (channel->opacity != opacity)
{ {
...@@ -2755,7 +2755,7 @@ channels_dialog_edit_channel_query (ChannelWidget *channel_widget) ...@@ -2755,7 +2755,7 @@ channels_dialog_edit_channel_query (ChannelWidget *channel_widget)
1, 2, 0, 1); 1, 2, 0, 1);
gtk_entry_set_text gtk_entry_set_text
(GTK_ENTRY (options->name_entry), (GTK_ENTRY (options->name_entry),
drawable_get_name (GIMP_DRAWABLE (channel_widget->channel))); gimp_object_get_name (GIMP_OBJECT (channel_widget->channel)));
gtk_widget_show (options->name_entry); gtk_widget_show (options->name_entry);
/* The opacity scale */ /* The opacity scale */
......
...@@ -187,7 +187,8 @@ channel_copy (const Channel *channel) ...@@ -187,7 +187,8 @@ channel_copy (const Channel *channel)
gint len; gint len;
/* formulate the new channel name */ /* formulate the new channel name */
name = drawable_get_name (GIMP_DRAWABLE (channel)); name = gimp_object_get_name (GIMP_OBJECT (channel));
ext = strrchr (name, '#'); ext = strrchr (name, '#');
len = strlen (_("copy")); len = strlen (_("copy"));
if ((strlen (name) >= len && if ((strlen (name) >= len &&
...@@ -231,13 +232,13 @@ void ...@@ -231,13 +232,13 @@ void
channel_set_name (Channel *channel, channel_set_name (Channel *channel,
const gchar *name) const gchar *name)
{ {
gimp_drawable_set_name (GIMP_DRAWABLE (channel), name); gimp_object_set_name (GIMP_OBJECT (channel), name);
} }
const gchar * const gchar *
channel_get_name (const Channel *channel) channel_get_name (const Channel *channel)
{ {
return gimp_drawable_get_name (GIMP_DRAWABLE (channel)); return gimp_object_get_name (GIMP_OBJECT (channel));
} }
void void
......
...@@ -187,7 +187,8 @@ channel_copy (const Channel *channel) ...@@ -187,7 +187,8 @@ channel_copy (const Channel *channel)
gint len; gint len;
/* formulate the new channel name */ /* formulate the new channel name */
name = drawable_get_name (GIMP_DRAWABLE (channel)); name = gimp_object_get_name (GIMP_OBJECT (channel));
ext = strrchr (name, '#'); ext = strrchr (name, '#');
len = strlen (_("copy")); len = strlen (_("copy"));
if ((strlen (name) >= len && if ((strlen (name) >= len &&
...@@ -231,13 +232,13 @@ void ...@@ -231,13 +232,13 @@ void
channel_set_name (Channel *channel, channel_set_name (Channel *channel,
const gchar *name) const gchar *name)
{ {
gimp_drawable_set_name (GIMP_DRAWABLE (channel), name); gimp_object_set_name (GIMP_OBJECT (channel), name);
} }
const gchar * const gchar *
channel_get_name (const Channel *channel) channel_get_name (const Channel *channel)
{ {
return gimp_drawable_get_name (GIMP_DRAWABLE (channel)); return gimp_object_get_name (GIMP_OBJECT (channel));
} }
void void
......
...@@ -612,8 +612,8 @@ duplicate (GimpImage *gimage) ...@@ -612,8 +612,8 @@ duplicate (GimpImage *gimage)
/* Make sure if the layer has a layer mask, it's name isn't screwed up */ /* Make sure if the layer has a layer mask, it's name isn't screwed up */
if (new_layer->mask) if (new_layer->mask)
{ {
gimp_drawable_set_name(GIMP_DRAWABLE(new_layer->mask), gimp_object_set_name (GIMP_OBJECT (new_layer->mask),
gimp_drawable_get_name(GIMP_DRAWABLE(layer->mask))); gimp_object_get_name (GIMP_OBJECT (layer->mask)));
} }
if (gimage->active_layer == layer) if (gimage->active_layer == layer)
...@@ -643,8 +643,8 @@ duplicate (GimpImage *gimage) ...@@ -643,8 +643,8 @@ duplicate (GimpImage *gimage)
gimp_drawable_set_gimage(GIMP_DRAWABLE(new_channel), new_gimage); gimp_drawable_set_gimage(GIMP_DRAWABLE(new_channel), new_gimage);
/* Make sure the copied channel doesn't say: "<old channel> copy" */ /* Make sure the copied channel doesn't say: "<old channel> copy" */
gimp_drawable_set_name(GIMP_DRAWABLE(new_channel), gimp_object_set_name (GIMP_OBJECT (new_channel),
gimp_drawable_get_name(GIMP_DRAWABLE(channel))); gimp_object_get_name (GIMP_OBJECT (channel)));
if (gimage->active_channel == channel) if (gimage->active_channel == channel)
active_channel = (new_channel); active_channel = (new_channel);
......
...@@ -52,9 +52,10 @@ enum ...@@ -52,9 +52,10 @@ enum
LAST_SIGNAL LAST_SIGNAL
}; };
static void gimp_drawable_class_init (GimpDrawableClass *klass); static void gimp_drawable_class_init (GimpDrawableClass *klass);
static void gimp_drawable_init (GimpDrawable *drawable); static void gimp_drawable_init (GimpDrawable *drawable);
static void gimp_drawable_destroy (GtkObject *object); static void gimp_drawable_destroy (GtkObject *object);
static void gimp_drawable_name_changed (GimpObject *drawable);
static guint gimp_drawable_signals[LAST_SIGNAL] = { 0 }; static guint gimp_drawable_signals[LAST_SIGNAL] = { 0 };
...@@ -90,9 +91,11 @@ gimp_drawable_get_type (void) ...@@ -90,9 +91,11 @@ gimp_drawable_get_type (void)
static void static void
gimp_drawable_class_init (GimpDrawableClass *klass) gimp_drawable_class_init (GimpDrawableClass *klass)
{ {
GtkObjectClass *object_class; GtkObjectClass *object_class;
GimpObjectClass *gimp_object_class;
object_class = (GtkObjectClass *) klass; object_class = (GtkObjectClass *) klass;
gimp_object_class = (GimpObjectClass *) klass;
parent_class = gtk_type_class (GIMP_TYPE_OBJECT); parent_class = gtk_type_class (GIMP_TYPE_OBJECT);
...@@ -110,9 +113,105 @@ gimp_drawable_class_init (GimpDrawableClass *klass) ...@@ -110,9 +113,105 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
object_class->destroy = gimp_drawable_destroy; object_class->destroy = gimp_drawable_destroy;
gimp_object_class->name_changed = gimp_drawable_name_changed;
klass->invalidate_preview = NULL; klass->invalidate_preview = NULL;
} }
static void
gimp_drawable_name_changed (GimpObject *object)
{
GimpDrawable *drawable;
GimpDrawable *drawable2;
GSList *list, *list2, *base_list;
gint unique_ext = 0;
gchar *ext;
gchar *new_name = NULL;
g_return_if_fail (GIMP_IS_DRAWABLE (object));
drawable = GIMP_DRAWABLE (object);
/* if no other layers to check name against */
if (drawable->gimage == NULL || drawable->gimage->layers == NULL)
return;
if (GIMP_IS_LAYER (drawable))
base_list = drawable->gimage->layers;
else if (GIMP_IS_CHANNEL (drawable))
base_list = drawable->gimage->channels;
else
base_list = NULL;
for (list = base_list; list; list = g_slist_next (list))
{
drawable2 = GIMP_DRAWABLE (list->data);
if (drawable != drawable2 &&
strcmp (gimp_object_get_name (GIMP_OBJECT (drawable)),
gimp_object_get_name (GIMP_OBJECT (drawable2))) == 0)
{
ext = strrchr (GIMP_OBJECT (drawable)->name, '#');
if (ext)
{
gchar *ext_str;
unique_ext = atoi (ext + 1);
ext_str = g_strdup_printf ("%d", unique_ext);
/* check if the extension really is of the form "#<n>" */
if (! strcmp (ext_str, ext + 1))
{
*ext = '\0';
}
else
{
unique_ext = 0;
}
g_free (ext_str);
}
else
{
unique_ext = 0;
}
do
{
unique_ext++;
g_free (new_name);
new_name = g_strdup_printf ("%s#%d",
GIMP_OBJECT (drawable)->name,
unique_ext);
for (list2 = base_list; list2; list2 = g_slist_next (list2))
{
drawable2 = GIMP_DRAWABLE (list2->data);
if (drawable == drawable2)
continue;
if (! strcmp (GIMP_OBJECT (drawable2)->name, new_name))
{
break;
}
}
}
while (list2);
g_free (GIMP_OBJECT (drawable)->name);
GIMP_OBJECT (drawable)->name = new_name;
break;
}
}
}
/* /*
* Static variables * Static variables
...@@ -358,100 +457,6 @@ gimp_drawable_visible (const GimpDrawable *drawable) ...@@ -358,100 +457,6 @@ gimp_drawable_visible (const GimpDrawable *drawable)
return drawable->visible; return drawable->visible;
} }
const gchar *
gimp_drawable_get_name (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
return drawable->name;
}
void
gimp_drawable_set_name (GimpDrawable *drawable,
const gchar *name)
{
GSList *list, *listb, *base_list;
GimpDrawable *drawableb;
gint number = 1;
gchar *newname;
gchar *ext;
gchar numberbuf[20];
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (name != NULL);
if (drawable->name)
{
g_free (drawable->name);
drawable->name = NULL;
}
if (drawable->gimage == NULL || drawable->gimage->layers == NULL)
{
/* no other layers to check name against */
drawable->name = g_strdup (name);
return;
}
if (GIMP_IS_LAYER (drawable))
base_list = drawable->gimage->layers;
else if (GIMP_IS_CHANNEL (drawable))
base_list = drawable->gimage->channels;
else
base_list = NULL;
for (list = base_list; list; list = g_slist_next (list))
{
drawableb = GIMP_DRAWABLE (list->data);
if (drawable != drawableb &&
strcmp (name, gimp_drawable_get_name (drawableb)) == 0)
{ /* names conflict */
newname = g_malloc (strlen (name) + 10); /* if this aint enough
yer screwed */
strcpy (newname, name);
if ((ext = strrchr (newname, '#')))
{
number = atoi(ext+1);
/* Check if there really was the number we think after the # */
g_snprintf (numberbuf, sizeof (numberbuf), "#%d", number);
if (strcmp (ext, numberbuf) != 0)
{
/* No, so just ignore the # */
number = 1;
ext = &newname[strlen (newname)];
}
}
else
{
number = 1;
ext = &newname[strlen (newname)];
}
sprintf (ext, "#%d", number + 1);
listb = base_list;
while (listb) /* make sure the new name is unique */
{
drawableb = GIMP_DRAWABLE (listb->data);
if (drawable != drawableb &&
strcmp (newname, gimp_drawable_get_name (drawableb)) == 0)
{
number++;
sprintf (ext, "#%d", number+1);
/* Rescan from beginning */
listb = base_list;
continue;
}
listb = listb->next;
}
drawable->name = g_strdup (newname);
g_free (newname);
return;
}
}
drawable->name = g_strdup (name);
}
guchar * guchar *
gimp_drawable_get_color_at (GimpDrawable *drawable, gimp_drawable_get_color_at (GimpDrawable *drawable,
gint x, gint x,
...@@ -727,7 +732,6 @@ gimp_drawable_deallocate (GimpDrawable *drawable) ...@@ -727,7 +732,6 @@ gimp_drawable_deallocate (GimpDrawable *drawable)
static void static void
gimp_drawable_init (GimpDrawable *drawable) gimp_drawable_init (GimpDrawable *drawable)
{ {
drawable->name = NULL;
drawable->tiles = NULL; drawable->tiles = NULL;
drawable->visible = FALSE; drawable->visible = FALSE;
drawable->width = 0; drawable->width = 0;
...@@ -764,9 +768,6 @@ gimp_drawable_destroy (GtkObject *object) ...@@ -764,9 +768,6 @@ gimp_drawable_destroy (GtkObject *object)
drawable = GIMP_DRAWABLE (object); drawable = GIMP_DRAWABLE (object);
g_hash_table_remove (gimp_drawable_table, (gpointer) drawable->ID); g_hash_table_remove (gimp_drawable_table, (gpointer) drawable->ID);
if (drawable->name)
g_free (drawable->name);
if (drawable->tiles) if (drawable->tiles)
tile_manager_destroy (drawable->tiles); tile_manager_destroy (drawable->tiles);
...@@ -816,7 +817,6 @@ gimp_drawable_configure (GimpDrawable *drawable, ...@@ -816,7 +817,6 @@ gimp_drawable_configure (GimpDrawable *drawable,
return; return;
} }
drawable->name = NULL;
drawable->width = width; drawable->width = width;
drawable->height = height; drawable->height = height;
drawable->bytes = bpp; drawable->bytes = bpp;
...@@ -834,7 +834,7 @@ gimp_drawable_configure (GimpDrawable *drawable, ...@@ -834,7 +834,7 @@ gimp_drawable_configure (GimpDrawable *drawable,
if (gimage) if (gimage)
gimp_drawable_set_gimage (drawable, gimage); gimp_drawable_set_gimage (drawable, gimage);
gimp_drawable_set_name (drawable, name); gimp_object_set_name (GIMP_OBJECT (drawable), name);
/* preview variables */ /* preview variables */
drawable->preview_cache = NULL; drawable->preview_cache = NULL;
......
...@@ -36,7 +36,6 @@ struct _GimpDrawable ...@@ -36,7 +36,6 @@ struct _GimpDrawable
{ {
GimpObject data; GimpObject data;
gchar *name; /* name of drawable */
TileManager *tiles; /* tiles for drawable data */ TileManager *tiles; /* tiles for drawable data */
gboolean visible; /* controls visibility */ gboolean visible; /* controls visibility */
gint width, height; /* size of drawable */ gint width, height; /* size of drawable */
...@@ -96,13 +95,11 @@ gint gimp_drawable_bytes (GimpDrawable *); ...@@ -96,13 +95,11 @@ gint gimp_drawable_bytes (GimpDrawable *);
gint gimp_drawable_width (GimpDrawable *); gint gimp_drawable_width (GimpDrawable *);
gint gimp_drawable_height (GimpDrawable *); gint gimp_drawable_height (GimpDrawable *);
gboolean gimp_drawable_visible (const GimpDrawable *drawable); gboolean gimp_drawable_visible (