From 0fb97ecb8e0ecd28cfd4f110c758632d5cf90f1f Mon Sep 17 00:00:00 2001 From: jaycox Date: Thu, 24 Sep 1998 01:19:57 +0000 Subject: [PATCH] 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 --- ChangeLog | 15 ++++ app/channel.c | 27 ++++++- app/channel.h | 3 + app/channel_cmds.c | 8 +- app/channels_dialog.c | 13 ++-- app/core/gimpchannel-combine.c | 27 ++++++- app/core/gimpchannel-combine.h | 3 + app/core/gimpchannel.c | 27 ++++++- app/core/gimpchannel.h | 3 + app/core/gimpdrawable.c | 85 ++++++++++++++++++++- app/core/gimpdrawable.h | 3 +- app/core/gimpimage-guides.c | 4 +- app/core/gimpimage-merge.c | 4 +- app/core/gimpimage-projection.c | 4 +- app/core/gimpimage-resize.c | 4 +- app/core/gimpimage-scale.c | 4 +- app/core/gimpimage.c | 4 +- app/core/gimplayer.c | 35 ++++++++- app/core/gimplayer.h | 4 +- app/core/gimpprojection-construct.c | 4 +- app/display/gimpdisplayshell-layer-select.c | 2 +- app/drawable.h | 3 +- app/gimage_cmds.c | 12 +-- app/gimpchannel.c | 27 ++++++- app/gimpchannel.h | 3 + app/gimpdrawable.c | 85 ++++++++++++++++++++- app/gimpdrawable.h | 3 +- app/gimpimage.c | 4 +- app/gimplayer.c | 35 ++++++++- app/gimplayer.h | 4 +- app/gui/channels-dialog.c | 13 ++-- app/gui/layer-select.c | 2 +- app/gui/layers-dialog.c | 12 ++- app/layer.c | 35 ++++++++- app/layer.h | 4 +- app/layer_cmds.c | 8 +- app/layer_select.c | 2 +- app/layers_dialog.c | 12 ++- 38 files changed, 450 insertions(+), 97 deletions(-) diff --git a/ChangeLog b/ChangeLog index a252bde6aa..23c0c277d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +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 * app/text_tool.c: correct test for restoring old foundry in diff --git a/app/channel.c b/app/channel.c index 067eeb325f..ee04327eab 100644 --- a/app/channel.c +++ b/app/channel.c @@ -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) { diff --git a/app/channel.h b/app/channel.h index c13b31677a..a2fa9d86c5 100644 --- a/app/channel.h +++ b/app/channel.h @@ -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); diff --git a/app/channel_cmds.c b/app/channel_cmds.c index b63d89c79d..474324b39f 100644 --- a/app/channel_cmds.c +++ b/app/channel_cmds.c @@ -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); diff --git a/app/channels_dialog.c b/app/channels_dialog.c index 9555bf4449..967aef8a99 100644 --- a/app/channels_dialog.c +++ b/app/channels_dialog.c @@ -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); diff --git a/app/core/gimpchannel-combine.c b/app/core/gimpchannel-combine.c index 067eeb325f..ee04327eab 100644 --- a/app/core/gimpchannel-combine.c +++ b/app/core/gimpchannel-combine.c @@ -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) { diff --git a/app/core/gimpchannel-combine.h b/app/core/gimpchannel-combine.h index c13b31677a..a2fa9d86c5 100644 --- a/app/core/gimpchannel-combine.h +++ b/app/core/gimpchannel-combine.h @@ -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); diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c index 067eeb325f..ee04327eab 100644 --- a/app/core/gimpchannel.c +++ b/app/core/gimpchannel.c @@ -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) { diff --git a/app/core/gimpchannel.h b/app/core/gimpchannel.h index c13b31677a..a2fa9d86c5 100644 --- a/app/core/gimpchannel.h +++ b/app/core/gimpchannel.h @@ -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); diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c index a68071c8f6..b8256d58ab 100644 --- a/app/core/gimpdrawable.c +++ b/app/core/gimpdrawable.c @@ -16,6 +16,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include +#include +#include +#include #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; diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h index 975f7ef4b5..b2b37b6ecf 100644 --- a/app/core/gimpdrawable.h +++ b/app/core/gimpdrawable.h @@ -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 *); diff --git a/app/core/gimpimage-guides.c b/app/core/gimpimage-guides.c index 9f3d024814..879cf7fbf7 100644 --- a/app/core/gimpimage-guides.c +++ b/app/core/gimpimage-guides.c @@ -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); diff --git a/app/core/gimpimage-merge.c b/app/core/gimpimage-merge.c index 9f3d024814..879cf7fbf7 100644 --- a/app/core/gimpimage-merge.c +++ b/app/core/gimpimage-merge.c @@ -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); diff --git a/app/core/gimpimage-projection.c b/app/core/gimpimage-projection.c index 9f3d024814..879cf7fbf7 100644 --- a/app/core/gimpimage-projection.c +++ b/app/core/gimpimage-projection.c @@ -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); diff --git a/app/core/gimpimage-resize.c b/app/core/gimpimage-resize.c index 9f3d024814..879cf7fbf7 100644 --- a/app/core/gimpimage-resize.c +++ b/app/core/gimpimage-resize.c @@ -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); diff --git a/app/core/gimpimage-scale.c b/app/core/gimpimage-scale.c index 9f3d024814..879cf7fbf7 100644 --- a/app/core/gimpimage-scale.c +++ b/app/core/gimpimage-scale.c @@ -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); diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index 9f3d024814..879cf7fbf7 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -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); diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c index f8b0cd194a..adae52c7fa 100644 --- a/app/core/gimplayer.c +++ b/app/core/gimplayer.c @@ -19,6 +19,8 @@ */ #include #include +#include +#include #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; diff --git a/app/core/gimplayer.h b/app/core/gimplayer.h index 4c6cfcb29d..de8a39c2e9 100644 --- a/app/core/gimplayer.h +++ b/app/core/gimplayer.h @@ -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 *); diff --git a/app/core/gimpprojection-construct.c b/app/core/gimpprojection-construct.c index 9f3d024814..879cf7fbf7 100644 --- a/app/core/gimpprojection-construct.c +++ b/app/core/gimpprojection-construct.c @@ -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); diff --git a/app/display/gimpdisplayshell-layer-select.c b/app/display/gimpdisplayshell-layer-select.c index 31a4e804f6..5503825c97 100644 --- a/app/display/gimpdisplayshell-layer-select.c +++ b/app/display/gimpdisplayshell-layer-select.c @@ -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))); } diff --git a/app/drawable.h b/app/drawable.h index 68c6e11112..a85a1748b5 100644 --- a/app/drawable.h +++ b/app/drawable.h @@ -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 diff --git a/app/gimage_cmds.c b/app/gimage_cmds.c index 73dbb86958..c9d8771d51 100644 --- a/app/gimage_cmds.c +++ b/app/gimage_cmds.c @@ -3372,14 +3372,14 @@ duplicate (GImage *gimage) GIMP_DRAWABLE(new_layer)->gimage = new_gimage; /* Make sure the copied layer doesn't say: " 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: " 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); diff --git a/app/gimpchannel.c b/app/gimpchannel.c index 067eeb325f..ee04327eab 100644 --- a/app/gimpchannel.c +++ b/app/gimpchannel.c @@ -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) { diff --git a/app/gimpchannel.h b/app/gimpchannel.h index c13b31677a..a2fa9d86c5 100644 --- a/app/gimpchannel.h +++ b/app/gimpchannel.h @@ -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); diff --git a/app/gimpdrawable.c b/app/gimpdrawable.c index a68071c8f6..b8256d58ab 100644 --- a/app/gimpdrawable.c +++ b/app/gimpdrawable.c @@ -16,6 +16,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include +#include +#include +#include #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; diff --git a/app/gimpdrawable.h b/app/gimpdrawable.h index 975f7ef4b5..b2b37b6ecf 100644 --- a/app/gimpdrawable.h +++ b/app/gimpdrawable.h @@ -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 *); diff --git a/app/gimpimage.c b/app/gimpimage.c index 9f3d024814..879cf7fbf7 100644 --- a/app/gimpimage.c +++ b/app/gimpimage.c @@ -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); diff --git a/app/gimplayer.c b/app/gimplayer.c index f8b0cd194a..adae52c7fa 100644 --- a/app/gimplayer.c +++ b/app/gimplayer.c @@ -19,6 +19,8 @@ */ #include #include +#include +#include #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; diff --git a/app/gimplayer.h b/app/gimplayer.h index 4c6cfcb29d..de8a39c2e9 100644 --- a/app/gimplayer.h +++ b/app/gimplayer.h @@ -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 *); diff --git a/app/gui/channels-dialog.c b/app/gui/channels-dialog.c index 9555bf4449..967aef8a99 100644 --- a/app/gui/channels-dialog.c +++ b/app/gui/channels-dialog.c @@ -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); diff --git a/app/gui/layer-select.c b/app/gui/layer-select.c index 31a4e804f6..5503825c97 100644 --- a/app/gui/layer-select.c +++ b/app/gui/layer-select.c @@ -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))); } diff --git a/app/gui/layers-dialog.c b/app/gui/layers-dialog.c index f0aaba674e..4c0d062745 100644 --- a/app/gui/layers-dialog.c +++ b/app/gui/layers-dialog.c @@ -2070,7 +2070,7 @@ create_layer_widget (GImage *gimage, if (layer_is_floating_sel (layer)) layer_widget->label = gtk_label_new ("Floating Selection"); else - layer_widget->label = gtk_label_new (GIMP_DRAWABLE(layer)->name); + layer_widget->label = gtk_label_new (layer_get_name(layer)); gtk_box_pack_start (GTK_BOX (hbox), layer_widget->label, FALSE, FALSE, 2); gtk_widget_show (layer_widget->label); @@ -2891,7 +2891,7 @@ layer_widget_layer_flush (GtkWidget *widget, if (layer_is_floating_sel (layer_widget->layer)) name = "Floating Selection"; else - name = GIMP_DRAWABLE(layer_widget->layer)->name; + name = layer_get_name(layer_widget->layer); /* we need to set the name label if necessary */ gtk_label_get (GTK_LABEL (layer_widget->label), &label_name); @@ -3239,15 +3239,13 @@ edit_layer_query_ok_callback (GtkWidget *w, /* Set the new layer name */ if (GIMP_DRAWABLE(layer)->name) { - /* If the layer is a floating selection, make it a channel */ + /* If the layer is a floating selection, make it a layer */ if (layer_is_floating_sel (layer)) { floating_sel_to_layer (layer); } - - g_free (GIMP_DRAWABLE(layer)->name); } - GIMP_DRAWABLE(layer)->name = g_strdup (gtk_entry_get_text (GTK_ENTRY (options->name_entry))); + layer_set_name(layer, gtk_entry_get_text (GTK_ENTRY (options->name_entry))); } gdisplays_flush (); @@ -3320,7 +3318,7 @@ layers_dialog_edit_layer_query (LayerWidget *layer_widget) gtk_box_pack_start (GTK_BOX (hbox), options->name_entry, TRUE, TRUE, 0); gtk_entry_set_text (GTK_ENTRY (options->name_entry), ((layer_is_floating_sel (layer_widget->layer) ? - "Floating Selection" : GIMP_DRAWABLE(layer_widget->layer)->name))); + "Floating Selection" : layer_get_name(layer_widget->layer)))); gtk_widget_show (options->name_entry); gtk_widget_show (hbox); diff --git a/app/layer.c b/app/layer.c index f8b0cd194a..adae52c7fa 100644 --- a/app/layer.c +++ b/app/layer.c @@ -19,6 +19,8 @@ */ #include #include +#include +#include #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; diff --git a/app/layer.h b/app/layer.h index 4c6cfcb29d..de8a39c2e9 100644 --- a/app/layer.h +++ b/app/layer.h @@ -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 *); diff --git a/app/layer_cmds.c b/app/layer_cmds.c index ae5e1dc2d6..d1b972be07 100644 --- a/app/layer_cmds.c +++ b/app/layer_cmds.c @@ -756,7 +756,7 @@ layer_get_name_invoker (Argument *args) { int_value = args[0].value.pdb_int; if ((layer = layer_get_ID (int_value))) - name = GIMP_DRAWABLE(layer)->name; + name = layer_get_name(layer); else success = FALSE; } @@ -828,11 +828,7 @@ layer_set_name_invoker (Argument *args) if (success) { name = (char *) args[1].value.pdb_pointer; - if (GIMP_DRAWABLE(layer)->name) - { - g_free (GIMP_DRAWABLE(layer)->name); - GIMP_DRAWABLE(layer)->name = (name) ? g_strdup (name) : NULL; - } + layer_set_name(layer, name); } return procedural_db_return_args (&layer_set_name_proc, success); diff --git a/app/layer_select.c b/app/layer_select.c index 31a4e804f6..5503825c97 100644 --- a/app/layer_select.c +++ b/app/layer_select.c @@ -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))); } diff --git a/app/layers_dialog.c b/app/layers_dialog.c index f0aaba674e..4c0d062745 100644 --- a/app/layers_dialog.c +++ b/app/layers_dialog.c @@ -2070,7 +2070,7 @@ create_layer_widget (GImage *gimage, if (layer_is_floating_sel (layer)) layer_widget->label = gtk_label_new ("Floating Selection"); else - layer_widget->label = gtk_label_new (GIMP_DRAWABLE(layer)->name); + layer_widget->label = gtk_label_new (layer_get_name(layer)); gtk_box_pack_start (GTK_BOX (hbox), layer_widget->label, FALSE, FALSE, 2); gtk_widget_show (layer_widget->label); @@ -2891,7 +2891,7 @@ layer_widget_layer_flush (GtkWidget *widget, if (layer_is_floating_sel (layer_widget->layer)) name = "Floating Selection"; else - name = GIMP_DRAWABLE(layer_widget->layer)->name; + name = layer_get_name(layer_widget->layer); /* we need to set the name label if necessary */ gtk_label_get (GTK_LABEL (layer_widget->label), &label_name); @@ -3239,15 +3239,13 @@ edit_layer_query_ok_callback (GtkWidget *w, /* Set the new layer name */ if (GIMP_DRAWABLE(layer)->name) { - /* If the layer is a floating selection, make it a channel */ + /* If the layer is a floating selection, make it a layer */ if (layer_is_floating_sel (layer)) { floating_sel_to_layer (layer); } - - g_free (GIMP_DRAWABLE(layer)->name); } - GIMP_DRAWABLE(layer)->name = g_strdup (gtk_entry_get_text (GTK_ENTRY (options->name_entry))); + layer_set_name(layer, gtk_entry_get_text (GTK_ENTRY (options->name_entry))); } gdisplays_flush (); @@ -3320,7 +3318,7 @@ layers_dialog_edit_layer_query (LayerWidget *layer_widget) gtk_box_pack_start (GTK_BOX (hbox), options->name_entry, TRUE, TRUE, 0); gtk_entry_set_text (GTK_ENTRY (options->name_entry), ((layer_is_floating_sel (layer_widget->layer) ? - "Floating Selection" : GIMP_DRAWABLE(layer_widget->layer)->name))); + "Floating Selection" : layer_get_name(layer_widget->layer)))); gtk_widget_show (options->name_entry); gtk_widget_show (hbox);