added GError to GimpItem::rename().

2007-12-12  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpitem.[ch]: added GError to GimpItem::rename().

	* app/core/gimplayer.c
	* app/core/gimplayermask.c: set errors when renaming is impossible.

	* app/text/gimptextlayer.c
	* app/core/gimpimage-quick-mask.c: changed accordingly.

	* app/actions/channels-commands.c
	* app/actions/layers-commands.c
	* app/actions/vectors-commands.c
	* app/widgets/gimpitemtreeview.c: handle the returned errors.

	* tools/pdbgen/pdb/drawable.pdb
	* tools/pdbgen/pdb/vectors.pdb: pass the error.

	* app/pdb/drawable_cmds.c
	* app/pdb/vectors_cmds.c: regenerated.


svn path=/trunk/; revision=24338
This commit is contained in:
Michael Natterer 2007-12-12 13:57:11 +00:00 committed by Michael Natterer
parent 35710e8d8d
commit dfaf761dc0
15 changed files with 137 additions and 75 deletions

View File

@ -1,3 +1,24 @@
2007-12-12 Michael Natterer <mitch@gimp.org>
* app/core/gimpitem.[ch]: added GError to GimpItem::rename().
* app/core/gimplayer.c
* app/core/gimplayermask.c: set errors when renaming is impossible.
* app/text/gimptextlayer.c
* app/core/gimpimage-quick-mask.c: changed accordingly.
* app/actions/channels-commands.c
* app/actions/layers-commands.c
* app/actions/vectors-commands.c
* app/widgets/gimpitemtreeview.c: handle the returned errors.
* tools/pdbgen/pdb/drawable.pdb
* tools/pdbgen/pdb/vectors.pdb: pass the error.
* app/pdb/drawable_cmds.c
* app/pdb/vectors_cmds.c: regenerated.
2007-12-12 Michael Natterer <mitch@gimp.org>
* app/paint/gimpheal.c: no need to declare init() and class_init(),

View File

@ -395,7 +395,7 @@ channels_edit_channel_response (GtkWidget *widget,
_("Channel Attributes"));
if (name_changed)
gimp_item_rename (GIMP_ITEM (channel), new_name);
gimp_item_rename (GIMP_ITEM (channel), new_name, NULL);
if (color_changed)
gimp_channel_set_color (channel, &color, TRUE);

View File

@ -968,8 +968,21 @@ layers_edit_layer_response (GtkWidget *widget,
if (strcmp (new_name, gimp_object_get_name (GIMP_OBJECT (layer))))
{
gimp_item_rename (GIMP_ITEM (layer), new_name);
gimp_image_flush (dialog->image);
GError *error = NULL;
if (gimp_item_rename (GIMP_ITEM (layer), new_name, &error))
{
gimp_image_flush (dialog->image);
}
else
{
gimp_message (dialog->image->gimp, G_OBJECT (widget),
GIMP_MESSAGE_WARNING,
"%s", error->message);
g_clear_error (&error);
return;
}
}
if (dialog->rename_toggle &&

View File

@ -627,7 +627,7 @@ vectors_edit_vectors_response (GtkWidget *widget,
if (strcmp (new_name, gimp_object_get_name (GIMP_OBJECT (vectors))))
{
gimp_item_rename (GIMP_ITEM (vectors), new_name);
gimp_item_rename (GIMP_ITEM (vectors), new_name, NULL);
gimp_image_flush (options->image);
}
}

View File

@ -111,7 +111,8 @@ gimp_image_set_quick_mask_state (GimpImage *image,
gimp_channel_clear (selection, NULL, TRUE);
gimp_channel_set_color (mask, &image->quick_mask_color, FALSE);
gimp_item_rename (GIMP_ITEM (mask), GIMP_IMAGE_QUICK_MASK_NAME);
gimp_item_rename (GIMP_ITEM (mask), GIMP_IMAGE_QUICK_MASK_NAME,
NULL);
}
if (image->quick_mask_inverted)

View File

@ -84,7 +84,8 @@ static void gimp_item_real_convert (GimpItem *item,
GimpImage *dest_image);
static gboolean gimp_item_real_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
const gchar *undo_desc,
GError **error);
static void gimp_item_real_translate (GimpItem *item,
gint offset_x,
gint offset_y,
@ -352,9 +353,10 @@ gimp_item_real_convert (GimpItem *item,
}
static gboolean
gimp_item_real_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc)
gimp_item_real_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc,
GError **error)
{
if (gimp_item_is_attached (item))
gimp_image_undo_push_item_rename (item->image, undo_desc, item);
@ -574,6 +576,7 @@ gimp_item_convert (GimpItem *item,
* gimp_item_rename:
* @item: The #GimpItem to rename.
* @new_name: The new name to give the item.
* @error: Return location for error message.
*
* This function assigns a new name to the item, if the desired name is
* different from the name it already has, and pushes an entry onto the
@ -584,12 +587,14 @@ gimp_item_convert (GimpItem *item,
* Returns: %TRUE if the @item could be renamed, %FALSE otherwise.
*/
gboolean
gimp_item_rename (GimpItem *item,
const gchar *new_name)
gimp_item_rename (GimpItem *item,
const gchar *new_name,
GError **error)
{
GimpItemClass *item_class;
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
item_class = GIMP_ITEM_GET_CLASS (item);
@ -597,7 +602,7 @@ gimp_item_rename (GimpItem *item,
new_name = item_class->default_name;
if (strcmp (new_name, gimp_object_get_name (GIMP_OBJECT (item))))
return item_class->rename (item, new_name, item_class->rename_desc);
return item_class->rename (item, new_name, item_class->rename_desc, error);
return TRUE;
}

View File

@ -71,7 +71,8 @@ struct _GimpItemClass
GimpImage *dest_image);
gboolean (* rename) (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
const gchar *undo_desc,
GError **error);
void (* translate) (GimpItem *item,
gint offset_x,
gint offset_y,
@ -149,7 +150,8 @@ GimpItem * gimp_item_convert (GimpItem *item,
gboolean add_alpha);
gboolean gimp_item_rename (GimpItem *item,
const gchar *new_name);
const gchar *new_name,
GError **error);
gint gimp_item_width (const GimpItem *item);
gint gimp_item_height (const GimpItem *item);

View File

@ -99,7 +99,8 @@ static void gimp_layer_convert (GimpItem *item,
GimpImage *dest_image);
static gboolean gimp_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
const gchar *undo_desc,
GError **error);
static void gimp_layer_translate (GimpItem *item,
gint offset_x,
gint offset_y,
@ -622,9 +623,10 @@ gimp_layer_convert (GimpItem *item,
}
static gboolean
gimp_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc)
gimp_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc,
GError **error)
{
GimpLayer *layer = GIMP_LAYER (item);
GimpImage *image = gimp_item_get_image (item);
@ -637,7 +639,12 @@ gimp_layer_rename (GimpItem *item,
if (floating_sel)
{
if (GIMP_IS_CHANNEL (layer->fs.drawable))
return FALSE;
{
g_set_error (error, 0, 0,
_("Cannot create a new layer from the floating selection "
"because it belongs to a layer mask or channel."));
return FALSE;
}
if (attached)
{
@ -649,7 +656,7 @@ gimp_layer_rename (GimpItem *item,
}
}
GIMP_ITEM_CLASS (parent_class)->rename (item, new_name, undo_desc);
GIMP_ITEM_CLASS (parent_class)->rename (item, new_name, undo_desc, error);
if (attached && floating_sel)
gimp_image_undo_group_end (image);

View File

@ -45,13 +45,14 @@ enum
};
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 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,
GError **error);
G_DEFINE_TYPE (GimpLayerMask, gimp_layer_mask, GIMP_TYPE_CHANNEL)
@ -149,12 +150,15 @@ gimp_layer_mask_duplicate (GimpItem *item,
}
static gboolean
gimp_layer_mask_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc)
gimp_layer_mask_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc,
GError **error)
{
/* reject renaming, layer masks are always named "<layer name> mask" */
g_set_error (error, 0, 0, _("Cannot rename layer masks."));
return FALSE;
}

View File

@ -562,7 +562,7 @@ drawable_set_name_invoker (GimpProcedure *procedure,
if (success)
{
success = gimp_item_rename (GIMP_ITEM (drawable), name);
success = gimp_item_rename (GIMP_ITEM (drawable), name, error);
}
return gimp_procedure_get_return_values (procedure, success);

View File

@ -170,7 +170,7 @@ vectors_set_name_invoker (GimpProcedure *procedure,
if (success)
{
success = gimp_item_rename (GIMP_ITEM (vectors), name);
success = gimp_item_rename (GIMP_ITEM (vectors), name, error);
}
return gimp_procedure_get_return_values (procedure, success);

View File

@ -61,46 +61,47 @@ enum
PROP_MODIFIED
};
static void gimp_text_layer_finalize (GObject *object);
static void gimp_text_layer_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_text_layer_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_text_layer_finalize (GObject *object);
static void gimp_text_layer_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_text_layer_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gint64 gimp_text_layer_get_memsize (GimpObject *object,
gint64 *gui_size);
static gint64 gimp_text_layer_get_memsize (GimpObject *object,
gint64 *gui_size);
static GimpItem * gimp_text_layer_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
static gboolean gimp_text_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
static GimpItem * gimp_text_layer_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
static gboolean gimp_text_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc,
GError **error);
static void gimp_text_layer_set_tiles (GimpDrawable *drawable,
gboolean push_undo,
const gchar *undo_desc,
TileManager *tiles,
GimpImageType type,
gint offset_x,
gint offset_y);
static void gimp_text_layer_push_undo (GimpDrawable *drawable,
const gchar *undo_desc,
TileManager *tiles,
gboolean sparse,
gint x,
gint y,
gint width,
gint height);
static void gimp_text_layer_set_tiles (GimpDrawable *drawable,
gboolean push_undo,
const gchar *undo_desc,
TileManager *tiles,
GimpImageType type,
gint offset_x,
gint offset_y);
static void gimp_text_layer_push_undo (GimpDrawable *drawable,
const gchar *undo_desc,
TileManager *tiles,
gboolean sparse,
gint x,
gint y,
gint width,
gint height);
static void gimp_text_layer_text_notify (GimpTextLayer *layer);
static gboolean gimp_text_layer_render (GimpTextLayer *layer);
static void gimp_text_layer_render_layout (GimpTextLayer *layer,
GimpTextLayout *layout);
static void gimp_text_layer_text_notify (GimpTextLayer *layer);
static gboolean gimp_text_layer_render (GimpTextLayer *layer);
static void gimp_text_layer_render_layout (GimpTextLayer *layer,
GimpTextLayout *layout);
G_DEFINE_TYPE (GimpTextLayer, gimp_text_layer, GIMP_TYPE_LAYER)
@ -274,11 +275,12 @@ gimp_text_layer_duplicate (GimpItem *item,
}
static gboolean
gimp_text_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc)
gimp_text_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc,
GError **error)
{
if (GIMP_ITEM_CLASS (parent_class)->rename (item, new_name, undo_desc))
if (GIMP_ITEM_CLASS (parent_class)->rename (item, new_name, undo_desc, error))
{
g_object_set (item, "auto-rename", FALSE, NULL);

View File

@ -30,6 +30,7 @@
#include "widgets-types.h"
#include "core/gimp.h"
#include "core/gimpchannel.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
@ -846,6 +847,7 @@ gimp_item_tree_view_name_edited (GtkCellRendererText *cell,
GimpViewRenderer *renderer;
GimpItem *item;
const gchar *old_name;
GError *error = NULL;
gtk_tree_model_get (tree_view->model, &iter,
tree_view->model_column_renderer, &renderer,
@ -859,7 +861,7 @@ gimp_item_tree_view_name_edited (GtkCellRendererText *cell,
if (! new_name) new_name = "";
if (strcmp (old_name, new_name) &&
gimp_item_rename (item, new_name))
gimp_item_rename (item, new_name, &error))
{
gimp_image_flush (gimp_item_get_image (item));
}
@ -871,6 +873,11 @@ gimp_item_tree_view_name_edited (GtkCellRendererText *cell,
tree_view->model_column_name, name,
-1);
g_free (name);
gimp_message (view->image->gimp, G_OBJECT (view),
GIMP_MESSAGE_WARNING,
"%s", error->message);
g_clear_error (&error);
}
g_object_unref (renderer);

View File

@ -689,7 +689,7 @@ sub drawable_set_name {
%invoke = (
code => <<'CODE'
{
success = gimp_item_rename (GIMP_ITEM (drawable), name);
success = gimp_item_rename (GIMP_ITEM (drawable), name, error);
}
CODE
);

View File

@ -143,7 +143,7 @@ sub vectors_set_name {
%invoke = (
code => <<"CODE"
{
success = gimp_item_rename (GIMP_ITEM (vectors), name);
success = gimp_item_rename (GIMP_ITEM (vectors), name, error);
}
CODE
);