Commit 0fb97ecb authored by jaycox's avatar jaycox

app/channel.[ch] app/channel_cmds.c app/drawable.h app/channels_dialog.c


	* app/channel.[ch]
	* app/channel_cmds.c
	* app/drawable.h
	* app/channels_dialog.c
	* app/gimage_cmds.c
	* app/gimpdrawable.[ch]
	* app/gimpimage.c
	* app/layer.[ch]
	* app/layer_cmds.c
	* app/layer_select.c
	* app/layers_dialog.c: enforce unique names for layers and
	channels.  New functions {channel,gimp_drawable,layer}_{get,set}_name
parent 34d938f5
Wed Sep 23 18:07:54 1998 Jay Cox (jaycox@earthlink.net)
* app/channel.[ch]
* app/channel_cmds.c
* app/drawable.h
* app/channels_dialog.c
* app/gimage_cmds.c
* app/gimpdrawable.[ch]
* app/gimpimage.c
* app/layer.[ch]
* app/layer_cmds.c
* app/layer_select.c
* app/layers_dialog.c: enforce unique names for layers and
channels. New functions {channel,gimp_drawable,layer}_{get,set}_name
Mon Sep 21 02:05:50 PDT 1998 Manish Singh <yosh@gimp.org>
* app/text_tool.c: correct test for restoring old foundry in
......
......@@ -173,10 +173,21 @@ channel_copy (Channel *channel)
char * channel_name;
Channel * new_channel;
PixelRegion srcPR, destPR;
char *ext;
int number;
char *name;
/* formulate the new channel name */
channel_name = (char *) g_malloc (strlen (GIMP_DRAWABLE(channel)->name) + 6);
sprintf (channel_name, "%s copy", GIMP_DRAWABLE(channel)->name);
name = channel_get_name(channel);
ext = strrchr(name, '#');
channel_name = (char *) g_malloc (strlen (name) + 6);
if ((strlen(name) >= 4 && strcmp(&name[strlen(name) -4], "copy") == 0) ||
(ext && (number = atoi(ext+1)) > 0 &&
((int)(log10(number) + 1)) == strlen(ext+1)))
/* don't have rudundant "copy"s */
sprintf (channel_name, "%s", name);
else
sprintf (channel_name, "%s copy", name);
/* allocate a new channel object */
new_channel = channel_new (GIMP_DRAWABLE(channel)->gimage,
......@@ -200,6 +211,18 @@ channel_copy (Channel *channel)
}
void
channel_set_name (Channel *channel, char *name)
{
gimp_drawable_set_name(GIMP_DRAWABLE(channel), name);
}
char *
channel_get_name (Channel *channel)
{
return gimp_drawable_get_name(GIMP_DRAWABLE(channel));
}
Channel *
channel_get_ID (int ID)
{
......
......@@ -80,6 +80,9 @@ Channel * channel_copy (Channel *);
Channel * channel_ref (Channel *);
void channel_unref (Channel *);
char * channel_get_name (Channel *);
void channel_set_name (Channel *, char *);
Channel * channel_get_ID (int);
void channel_delete (Channel *);
void channel_scale (Channel *, int, int);
......
......@@ -294,7 +294,7 @@ channel_get_name_invoker (Argument *args)
{
int_value = args[0].value.pdb_int;
if ((channel = channel_get_ID (int_value)))
name = GIMP_DRAWABLE(channel)->name;
name = channel_get_name(channel);
else
success = FALSE;
}
......@@ -366,11 +366,7 @@ channel_set_name_invoker (Argument *args)
if (success)
{
name = (char *) args[1].value.pdb_pointer;
if (GIMP_DRAWABLE(channel)->name)
{
g_free (GIMP_DRAWABLE(channel)->name);
GIMP_DRAWABLE(channel)->name = (name) ? g_strdup (name) : NULL;
}
channel_set_name(channel, name);
}
return procedural_db_return_args (&channel_set_name_proc, success);
......
......@@ -1069,7 +1069,7 @@ create_channel_widget (GImage *gimage,
case Blue: channel_widget->label = gtk_label_new ("Blue"); break;
case Gray: channel_widget->label = gtk_label_new ("Gray"); break;
case Indexed: channel_widget->label = gtk_label_new ("Indexed"); break;
case Auxillary: channel_widget->label = gtk_label_new (GIMP_DRAWABLE(channel)->name); break;
case Auxillary: channel_widget->label = gtk_label_new (channel_get_name(channel)); break;
}
gtk_box_pack_start (GTK_BOX (hbox), channel_widget->label, FALSE, FALSE, 2);
......@@ -1888,10 +1888,10 @@ edit_channel_query_ok_callback (GtkWidget *w,
if (options->gimage) {
/* Set the new channel name */
if (GIMP_DRAWABLE(channel)->name)
g_free (GIMP_DRAWABLE(channel)->name);
GIMP_DRAWABLE(channel)->name = g_strdup (gtk_entry_get_text (GTK_ENTRY (options->name_entry)));
gtk_label_set (GTK_LABEL (options->channel_widget->label), GIMP_DRAWABLE(channel)->name);
channel_set_name(channel,
gtk_entry_get_text (GTK_ENTRY (options->name_entry)));
gtk_label_set (GTK_LABEL (options->channel_widget->label),
channel_get_name(channel));
if (channel->opacity != opacity)
{
......@@ -1994,7 +1994,8 @@ channels_dialog_edit_channel_query (ChannelWidget *channel_widget)
gtk_widget_show (label);
options->name_entry = gtk_entry_new ();
gtk_box_pack_start (GTK_BOX (hbox), options->name_entry, TRUE, TRUE, 0);
gtk_entry_set_text (GTK_ENTRY (options->name_entry), GIMP_DRAWABLE(channel_widget->channel)->name);
gtk_entry_set_text (GTK_ENTRY (options->name_entry),
channel_get_name(channel_widget->channel));
gtk_widget_show (options->name_entry);
gtk_widget_show (hbox);
......
......@@ -173,10 +173,21 @@ channel_copy (Channel *channel)
char * channel_name;
Channel * new_channel;
PixelRegion srcPR, destPR;
char *ext;
int number;
char *name;
/* formulate the new channel name */
channel_name = (char *) g_malloc (strlen (GIMP_DRAWABLE(channel)->name) + 6);
sprintf (channel_name, "%s copy", GIMP_DRAWABLE(channel)->name);
name = channel_get_name(channel);
ext = strrchr(name, '#');
channel_name = (char *) g_malloc (strlen (name) + 6);
if ((strlen(name) >= 4 && strcmp(&name[strlen(name) -4], "copy") == 0) ||
(ext && (number = atoi(ext+1)) > 0 &&
((int)(log10(number) + 1)) == strlen(ext+1)))
/* don't have rudundant "copy"s */
sprintf (channel_name, "%s", name);
else
sprintf (channel_name, "%s copy", name);
/* allocate a new channel object */
new_channel = channel_new (GIMP_DRAWABLE(channel)->gimage,
......@@ -200,6 +211,18 @@ channel_copy (Channel *channel)
}
void
channel_set_name (Channel *channel, char *name)
{
gimp_drawable_set_name(GIMP_DRAWABLE(channel), name);
}
char *
channel_get_name (Channel *channel)
{
return gimp_drawable_get_name(GIMP_DRAWABLE(channel));
}
Channel *
channel_get_ID (int ID)
{
......
......@@ -80,6 +80,9 @@ Channel * channel_copy (Channel *);
Channel * channel_ref (Channel *);
void channel_unref (Channel *);
char * channel_get_name (Channel *);
void channel_set_name (Channel *, char *);
Channel * channel_get_ID (int);
void channel_delete (Channel *);
void channel_scale (Channel *, int, int);
......
......@@ -173,10 +173,21 @@ channel_copy (Channel *channel)
char * channel_name;
Channel * new_channel;
PixelRegion srcPR, destPR;
char *ext;
int number;
char *name;
/* formulate the new channel name */
channel_name = (char *) g_malloc (strlen (GIMP_DRAWABLE(channel)->name) + 6);
sprintf (channel_name, "%s copy", GIMP_DRAWABLE(channel)->name);
name = channel_get_name(channel);
ext = strrchr(name, '#');
channel_name = (char *) g_malloc (strlen (name) + 6);
if ((strlen(name) >= 4 && strcmp(&name[strlen(name) -4], "copy") == 0) ||
(ext && (number = atoi(ext+1)) > 0 &&
((int)(log10(number) + 1)) == strlen(ext+1)))
/* don't have rudundant "copy"s */
sprintf (channel_name, "%s", name);
else
sprintf (channel_name, "%s copy", name);
/* allocate a new channel object */
new_channel = channel_new (GIMP_DRAWABLE(channel)->gimage,
......@@ -200,6 +211,18 @@ channel_copy (Channel *channel)
}
void
channel_set_name (Channel *channel, char *name)
{
gimp_drawable_set_name(GIMP_DRAWABLE(channel), name);
}
char *
channel_get_name (Channel *channel)
{
return gimp_drawable_get_name(GIMP_DRAWABLE(channel));
}
Channel *
channel_get_ID (int ID)
{
......
......@@ -80,6 +80,9 @@ Channel * channel_copy (Channel *);
Channel * channel_ref (Channel *);
void channel_unref (Channel *);
char * channel_get_name (Channel *);
void channel_set_name (Channel *, char *);
Channel * channel_get_ID (int);
void channel_delete (Channel *);
void channel_scale (Channel *, int, int);
......
......@@ -16,6 +16,10 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <strings.h>
#include "gimpdrawableP.h"
#include "gimpsignal.h"
#include "gimage.h"
......@@ -276,11 +280,84 @@ gimp_drawable_visible (GimpDrawable *drawable)
}
char *
gimp_drawable_name (GimpDrawable *drawable)
gimp_drawable_get_name (GimpDrawable *drawable)
{
return drawable->name;
}
void
gimp_drawable_set_name (GimpDrawable *drawable, char *name)
{
GSList *list, *listb, *base_list;
GimpDrawable *drawableb;
int number = 1;
char *newname;
char *ext;
g_return_if_fail(GIMP_IS_DRAWABLE(drawable));
if (drawable->name)
g_free(drawable->name);
drawable->name = NULL;
if (drawable->gimage == 0 || drawable->gimage->layers == 0)
{
/* 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;
list = base_list;
while (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);
if (&ext[(int)(log10(number) + 1)] != &newname[strlen(newname) - 1])
{
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);
listb = base_list;
}
listb = listb->next;
}
drawable->name = g_strdup(newname);
g_free(newname);
return;
}
list = list->next;
}
drawable->name = g_strdup(name);
}
int
gimp_drawable_type_with_alpha (GimpDrawable *drawable)
{
......@@ -500,9 +577,7 @@ gimp_drawable_configure (GimpDrawable *drawable,
return;
}
if (drawable->name)
g_free (drawable->name);
drawable->name = g_strdup(name);
drawable->name = NULL;
drawable->width = width;
drawable->height = height;
drawable->bytes = bpp;
......@@ -519,6 +594,8 @@ gimp_drawable_configure (GimpDrawable *drawable,
drawable->gimage = gimage;
gimp_drawable_set_name(drawable, name);
/* preview variables */
drawable->preview = NULL;
drawable->preview_valid = FALSE;
......
......@@ -69,7 +69,8 @@ void gimp_drawable_offsets (GimpDrawable *,
int *, int *);
unsigned char * gimp_drawable_cmap (GimpDrawable *);
char * gimp_drawable_name (GimpDrawable *);
char * gimp_drawable_get_name (GimpDrawable *);
void gimp_drawable_set_name (GimpDrawable *, char *);
GimpDrawable * gimp_drawable_get_ID (int);
void gimp_drawable_deallocate (GimpDrawable *);
......
......@@ -1894,7 +1894,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
case INDEXED: type = INDEXED_GIMAGE; break;
}
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
type, drawable_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
type, drawable_get_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
if (!merge_layer) {
g_message ("gimp_image_merge_layers: could not allocate merge layer");
......@@ -1924,7 +1924,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
*/
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
drawable_type_with_alpha (GIMP_DRAWABLE(layer)),
drawable_name (GIMP_DRAWABLE(layer)),
drawable_get_name (GIMP_DRAWABLE(layer)),
OPAQUE_OPACITY, NORMAL_MODE);
......
......@@ -1894,7 +1894,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
case INDEXED: type = INDEXED_GIMAGE; break;
}
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
type, drawable_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
type, drawable_get_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
if (!merge_layer) {
g_message ("gimp_image_merge_layers: could not allocate merge layer");
......@@ -1924,7 +1924,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
*/
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
drawable_type_with_alpha (GIMP_DRAWABLE(layer)),
drawable_name (GIMP_DRAWABLE(layer)),
drawable_get_name (GIMP_DRAWABLE(layer)),
OPAQUE_OPACITY, NORMAL_MODE);
......
......@@ -1894,7 +1894,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
case INDEXED: type = INDEXED_GIMAGE; break;
}
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
type, drawable_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
type, drawable_get_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
if (!merge_layer) {
g_message ("gimp_image_merge_layers: could not allocate merge layer");
......@@ -1924,7 +1924,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
*/
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
drawable_type_with_alpha (GIMP_DRAWABLE(layer)),
drawable_name (GIMP_DRAWABLE(layer)),
drawable_get_name (GIMP_DRAWABLE(layer)),
OPAQUE_OPACITY, NORMAL_MODE);
......
......@@ -1894,7 +1894,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
case INDEXED: type = INDEXED_GIMAGE; break;
}
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
type, drawable_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
type, drawable_get_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
if (!merge_layer) {
g_message ("gimp_image_merge_layers: could not allocate merge layer");
......@@ -1924,7 +1924,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
*/
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
drawable_type_with_alpha (GIMP_DRAWABLE(layer)),
drawable_name (GIMP_DRAWABLE(layer)),
drawable_get_name (GIMP_DRAWABLE(layer)),
OPAQUE_OPACITY, NORMAL_MODE);
......
......@@ -1894,7 +1894,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
case INDEXED: type = INDEXED_GIMAGE; break;
}
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
type, drawable_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
type, drawable_get_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
if (!merge_layer) {
g_message ("gimp_image_merge_layers: could not allocate merge layer");
......@@ -1924,7 +1924,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
*/
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
drawable_type_with_alpha (GIMP_DRAWABLE(layer)),
drawable_name (GIMP_DRAWABLE(layer)),
drawable_get_name (GIMP_DRAWABLE(layer)),
OPAQUE_OPACITY, NORMAL_MODE);
......
......@@ -1894,7 +1894,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
case INDEXED: type = INDEXED_GIMAGE; break;
}
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
type, drawable_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
type, drawable_get_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
if (!merge_layer) {
g_message ("gimp_image_merge_layers: could not allocate merge layer");
......@@ -1924,7 +1924,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
*/
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
drawable_type_with_alpha (GIMP_DRAWABLE(layer)),
drawable_name (GIMP_DRAWABLE(layer)),
drawable_get_name (GIMP_DRAWABLE(layer)),
OPAQUE_OPACITY, NORMAL_MODE);
......
......@@ -19,6 +19,8 @@
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include "drawable.h"
#include "errors.h"
#include "floating_sel.h"
......@@ -292,12 +294,22 @@ layer_copy (layer, add_alpha)
char * layer_name;
Layer * new_layer;
int new_type;
char *ext;
int number;
char *name;
PixelRegion srcPR, destPR;
/* formulate the new layer name */
layer_name = (char *) g_malloc (strlen (GIMP_DRAWABLE(layer)->name) + 6);
sprintf (layer_name, "%s copy", GIMP_DRAWABLE(layer)->name);
name = layer_get_name(layer);
ext = strrchr(name, '#');
layer_name = (char *) g_malloc (strlen (name) + 6);
if ((strlen(name) >= 4 && strcmp(&name[strlen(name) -4], "copy") == 0) ||
(ext && (number = atoi(ext+1)) > 0 &&
((int)(log10(number) + 1)) == strlen(ext+1)))
/* don't have rudundant "copy"s */
sprintf (layer_name, "%s", name);
else
sprintf (layer_name, "%s copy", name);
/* when copying a layer, the copy ALWAYS has an alpha channel */
if (add_alpha)
{
......@@ -321,7 +333,9 @@ layer_copy (layer, add_alpha)
new_type = GIMP_DRAWABLE(layer)->type;
/* allocate a new layer object */
new_layer = layer_new (GIMP_DRAWABLE(layer)->gimage, GIMP_DRAWABLE(layer)->width, GIMP_DRAWABLE(layer)->height,
new_layer = layer_new (GIMP_DRAWABLE(layer)->gimage,
GIMP_DRAWABLE(layer)->width,
GIMP_DRAWABLE(layer)->height,
new_type, layer_name, layer->opacity, layer->mode);
if (!new_layer) {
g_message ("layer_copy: could not allocate new layer");
......@@ -969,6 +983,19 @@ layer_pick_correlate (layer, x, y)
/********************/
/* access functions */
void
layer_set_name (Layer *layer, char *name)
{
gimp_drawable_set_name(GIMP_DRAWABLE(layer), name);
}
char *
layer_get_name (Layer *layer)
{
return gimp_drawable_get_name(GIMP_DRAWABLE(layer));
}
unsigned char *
layer_data (layer)
Layer * layer;
......
......@@ -97,7 +97,6 @@ void layer_resize (Layer *, int, int, int, int);
BoundSeg * layer_boundary (Layer *, int *);
void layer_invalidate_boundary (Layer *);
int layer_pick_correlate (Layer *, int, int);
LayerMask * layer_mask_new (GimpImage*, int, int, char *,
int, unsigned char *);
LayerMask * layer_mask_copy (LayerMask *);
......@@ -108,6 +107,9 @@ void layer_mask_unref (LayerMask *);
/* access functions */
void layer_set_name (Layer *, char *);
char * layer_get_name (Layer *);
unsigned char * layer_data (Layer *);
LayerMask * layer_mask (Layer *);
int layer_has_alpha (Layer *);
......
......@@ -1894,7 +1894,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
case INDEXED: type = INDEXED_GIMAGE; break;
}
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
type, drawable_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
type, drawable_get_name (GIMP_DRAWABLE(layer)), OPAQUE_OPACITY, NORMAL_MODE);
if (!merge_layer) {
g_message ("gimp_image_merge_layers: could not allocate merge layer");
......@@ -1924,7 +1924,7 @@ gimp_image_merge_layers (GimpImage *gimage, GSList *merge_list, MergeType merge_
*/
merge_layer = layer_new (gimage, (x2 - x1), (y2 - y1),
drawable_type_with_alpha (GIMP_DRAWABLE(layer)),
drawable_name (GIMP_DRAWABLE(layer)),
drawable_get_name (GIMP_DRAWABLE(layer)),
OPAQUE_OPACITY, NORMAL_MODE);
......
......@@ -301,7 +301,7 @@ layer_select_set_layer (LayerSelect *layer_select)
return;
/* Set the layer label */
gtk_label_set (GTK_LABEL (layer_select->label), drawable_name (GIMP_DRAWABLE(layer)));
gtk_label_set (GTK_LABEL (layer_select->label), drawable_get_name (GIMP_DRAWABLE(layer)));
}
......
......@@ -46,7 +46,8 @@ void drawable_apply_image (GimpDrawable *, int, int, int, int,
#define drawable_visible gimp_drawable_visible
#define drawable_offsets gimp_drawable_offsets
#define drawable_cmap gimp_drawable_cmap
#define drawable_name gimp_drawable_name
#define drawable_get_name gimp_drawable_get_name
#define drawable_set_name gimp_drawable_set_name
#define drawable_get_ID gimp_drawable_get_ID
#define drawable_deallocate gimp_drawable_deallocate
......
......@@ -3372,14 +3372,14 @@ duplicate (GImage *gimage)
GIMP_DRAWABLE(new_layer)->gimage = new_gimage;
/* Make sure the copied layer doesn't say: "<old layer> copy" */
g_free (drawable_name (GIMP_DRAWABLE(new_layer)));
GIMP_DRAWABLE(new_layer)-> name = g_strdup (drawable_name (GIMP_DRAWABLE(layer)));
layer_set_name(GIMP_LAYER(new_layer),
layer_get_name(GIMP_LAYER(layer)));
/* Make sure if the layer has a layer mask, it's name isn't screwed up */
if (new_layer->mask)
{
g_free (drawable_name (GIMP_DRAWABLE(new_layer->mask)));
GIMP_DRAWABLE(new_layer->mask)->name = g_strdup (drawable_name (GIMP_DRAWABLE(layer->mask)));
gimp_drawable_set_name(GIMP_DRAWABLE(new_layer->mask),
gimp_drawable_get_name(GIMP_DRAWABLE(layer->mask)));
}
if (gimage->active_layer == layer)
......@@ -3408,8 +3408,8 @@ duplicate (GImage *gimage)
GIMP_DRAWABLE(new_channel)->gimage = new_gimage;
/* Make sure the copied channel doesn't say: "<old channel> copy" */
g_free (drawable_name (GIMP_DRAWABLE(new_channel)));
GIMP_DRAWABLE(new_channel)->name = g_strdup (drawable_name (GIMP_DRAWABLE(channel)));
gimp_drawable_set_name(GIMP_DRAWABLE(new_channel),
gimp_drawable_get_name(GIMP_DRAWABLE(channel)));
if (gimage->active_channel == channel)
active_channel = (new_channel);
......
......@@ -173,10 +173,21 @@ channel_copy (Channel *channel)
char * channel_name;
Channel * new_channel;
PixelRegion srcPR, destPR;
char *ext;
int number;
char *name;
/* formulate the new channel name */
channel_name = (char *) g_malloc (strlen (GIMP_DRAWABLE(channel)->name) + 6);
sprintf (channel_name, "%s copy", GIMP_DRAWABLE(channel)->name);
name = channel_get_name(channel);
ext = strrchr(name, '#');
channel_name = (char *) g_malloc (strlen (name) + 6);
if ((strlen(name) >= 4 && strcmp(&name[strlen(name) -4], "copy") == 0) ||
(ext && (number = atoi(ext+1)) > 0 &&
((int)(log10(number) + 1)) == strlen(ext+1)))
/* don't have rudundant "copy"s */
sprintf (channel_name, "%s", name);
else
sprintf (channel_name, "%s copy", name);
/* allocate a new channel object */
new_channel = channel_new (GIMP_DRAWABLE(channel)->gimage,
......@@ -200,6 +211,18 @@ channel_copy (Channel *channel)
}
void
channel_set_name (Channel *channel, char *name)
{
gimp_drawable_set_name(GIMP_DRAWABLE(channel), name);
}
char *
channel_get_name (Channel *channel)
{
return gimp_drawable_get_name(GIMP_DRAWABLE(channel));
}
Channel *
channel_get_ID (int ID)
{
......
......@@ -80,6 +80,9 @@ Channel * channel_copy (Channel *);
Channel * channel_ref (Channel *);
void channel_unref (Channel *);
char * channel_get_name (Channel *);
void channel_set_name (Channel *, char *);
Channel * channel_get_ID (int);
void channel_delete (Channel *);
void channel_scale (Channel *, int, int);
......
......@@ -16,6 +16,10 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <strings.h>
#include "gimpdrawableP.h"
#include "gimpsignal.h"
#include "gimage.h"
......@@ -276,11 +280,84 @@ gimp_drawable_visible (GimpDrawable *drawable)
}
char *
gimp_drawable_name (GimpDrawable *drawable)
gimp_drawable_get_name (GimpDrawable *drawable)
{
return drawable->name;
}
void
gimp_drawable_set_name (GimpDrawable *drawable, char *name)
{
GSList *list, *listb, *base_list;
GimpDrawable *drawableb;
int number = 1;
char *newname;
char *ext;
g_return_if_fail(GIMP_IS_DRAWABLE(drawable));
if (drawable->name)
g_free(drawable->name);
drawable->name = NULL;
if (drawable->gimage == 0 || drawable->gimage->layers == 0)