Commit 418c5997 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

added virtual function rename() which pushes an item rename undo. Added

2003-03-17  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpitem.[ch]: added virtual function rename() which
	pushes an item rename undo. Added "default_name" and "rename_desc"
	to the GimpItemClass struct which are used as default values.

	* app/core/gimplayer.c: implement it and special-case floating
	selections. set item_clas->default_name and item_class->rename_desc.

	* app/core/gimpchannel.c
	* app/vectors/gimpvectors.c: set item_class->default_name and
	item_class->rename_desc.

	* app/widgets/gimpitemtreeview.[ch]: removed rename_item() virtual
	function and call gimp_item_rename().

	* app/widgets/gimpchanneltreeview.c
	* app/widgets/gimplayertreeview.c
	* app/widgets/gimpvectorstreeview.c: changed accordingly.
parent 5e48cfb8
2003-03-17 Michael Natterer <mitch@gimp.org>
* app/core/gimpitem.[ch]: added virtual function rename() which
pushes an item rename undo. Added "default_name" and "rename_desc"
to the GimpItemClass struct which are used as default values.
* app/core/gimplayer.c: implement it and special-case floating
selections. set item_clas->default_name and item_class->rename_desc.
* app/core/gimpchannel.c
* app/vectors/gimpvectors.c: set item_class->default_name and
item_class->rename_desc.
* app/widgets/gimpitemtreeview.[ch]: removed rename_item() virtual
function and call gimp_item_rename().
* app/widgets/gimpchanneltreeview.c
* app/widgets/gimplayertreeview.c
* app/widgets/gimpvectorstreeview.c: changed accordingly.
2003-03-16 Sven Neumann <sven@gimp.org>
* app/gui/file-save-dialog.c (file_save_overwrite): set the dialog
......@@ -114,6 +114,8 @@ gimp_channel_class_init (GimpChannelClass *klass)
gimp_object_class->get_memsize = gimp_channel_get_memsize;
item_class->duplicate = gimp_channel_duplicate;
item_class->default_name = _("Channel");
item_class->rename_desc = _("Rename Channel");
}
static void
......
......@@ -114,6 +114,8 @@ gimp_channel_class_init (GimpChannelClass *klass)
gimp_object_class->get_memsize = gimp_channel_get_memsize;
item_class->duplicate = gimp_channel_duplicate;
item_class->default_name = _("Channel");
item_class->rename_desc = _("Rename Channel");
}
static void
......
......@@ -65,6 +65,9 @@ static gsize gimp_item_get_memsize (GimpObject *object);
static GimpItem * gimp_item_real_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
static void gimp_item_real_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
/* private variables */
......@@ -129,6 +132,7 @@ gimp_item_class_init (GimpItemClass *klass)
klass->removed = NULL;
klass->duplicate = gimp_item_real_duplicate;
klass->rename = gimp_item_real_rename;
}
static void
......@@ -324,6 +328,17 @@ gimp_item_real_duplicate (GimpItem *item,
return new_item;
}
static void
gimp_item_real_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc)
{
if (item->gimage)
gimp_image_undo_push_item_rename (item->gimage, undo_desc, item);
gimp_object_set_name (GIMP_OBJECT (item), new_name);
}
void
gimp_item_removed (GimpItem *item)
{
......@@ -365,6 +380,23 @@ gimp_item_duplicate (GimpItem *item,
return GIMP_ITEM_GET_CLASS (item)->duplicate (item, new_type, add_alpha);
}
void
gimp_item_rename (GimpItem *item,
const gchar *new_name)
{
GimpItemClass *item_class;
g_return_if_fail (GIMP_IS_ITEM (item));
item_class = GIMP_ITEM_GET_CLASS (item);
if (! new_name || ! *new_name)
new_name = item_class->default_name;
if (strcmp (new_name, gimp_object_get_name (GIMP_OBJECT (item))))
item_class->rename (item, new_name, item_class->rename_desc);
}
gint
gimp_item_get_ID (GimpItem *item)
{
......
......@@ -50,12 +50,18 @@ struct _GimpItemClass
GimpViewableClass parent_class;
/* signals */
void (* removed) (GimpItem *item);
void (* removed) (GimpItem *item);
/* virtual functions */
GimpItem * (* duplicate) (GimpItem *item,
GType new_type,
gboolean add_alpha);
GimpItem * (* duplicate) (GimpItem *item,
GType new_type,
gboolean add_alpha);
void (* rename) (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
const gchar *default_name;
const gchar *rename_desc;
};
......@@ -70,6 +76,9 @@ GimpItem * gimp_item_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
void gimp_item_rename (GimpItem *item,
const gchar *new_name);
gint gimp_item_get_ID (GimpItem *item);
GimpItem * gimp_item_get_by_ID (Gimp *gimp,
gint id);
......
......@@ -72,6 +72,9 @@ static void gimp_layer_invalidate_preview (GimpViewable *viewable);
static GimpItem * gimp_layer_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
static void gimp_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
static void gimp_layer_transform_color (GimpImage *gimage,
PixelRegion *layerPR,
......@@ -180,6 +183,9 @@ gimp_layer_class_init (GimpLayerClass *klass)
viewable_class->invalidate_preview = gimp_layer_invalidate_preview;
item_class->duplicate = gimp_layer_duplicate;
item_class->rename = gimp_layer_rename;
item_class->default_name = _("Layer");
item_class->rename_desc = _("Rename Layer");
klass->opacity_changed = NULL;
klass->mode_changed = NULL;
......@@ -311,6 +317,32 @@ gimp_layer_duplicate (GimpItem *item,
return new_item;
}
static void
gimp_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc)
{
GimpImage *gimage;
gboolean floating_sel = FALSE;
gimage = gimp_item_get_image (item);
floating_sel = gimp_layer_is_floating_sel (GIMP_LAYER (item));
if (gimage && floating_sel)
{
gimp_image_undo_group_start (gimage,
GIMP_UNDO_GROUP_ITEM_PROPERTIES,
undo_desc);
floating_sel_to_layer (GIMP_LAYER (item));
}
GIMP_ITEM_CLASS (parent_class)->rename (item, new_name, undo_desc);
if (gimage && floating_sel)
gimp_image_undo_group_end (gimage);
}
static void
gimp_layer_transform_color (GimpImage *gimage,
PixelRegion *layerPR,
......
......@@ -32,6 +32,8 @@
#include "gimpvectors.h"
#include "gimpvectors-preview.h"
#include "libgimp/gimpintl.h"
static void gimp_vectors_class_init (GimpVectorsClass *klass);
static void gimp_vectors_init (GimpVectors *vectors);
......@@ -100,6 +102,8 @@ gimp_vectors_class_init (GimpVectorsClass *klass)
viewable_class->get_new_preview = gimp_vectors_get_new_preview;
item_class->duplicate = gimp_vectors_duplicate;
item_class->default_name = _("Path");
item_class->rename_desc = _("Rename Path");
klass->changed = NULL;
......
......@@ -128,7 +128,6 @@ gimp_channel_tree_view_class_init (GimpChannelTreeViewClass *klass)
item_view_class->raise_to_top_desc = _("Raise Channel to Top");
item_view_class->lower_desc = _("Lower Channel");
item_view_class->lower_to_bottom_desc = _("Lower Channel to Bottom");
item_view_class->rename_desc = _("Rename Channel");
}
static void
......
......@@ -21,8 +21,6 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
......@@ -33,7 +31,6 @@
#include "core/gimpchannel.h"
#include "core/gimpcontainer.h"
#include "core/gimpimage.h"
#include "core/gimpimage-undo-push.h"
#include "core/gimplayer.h"
#include "core/gimpmarshal.h"
......@@ -81,10 +78,6 @@ static void gimp_item_tree_view_context_item (GimpContainerView *view,
GimpViewable *item,
gpointer insert_data);
static void gimp_item_tree_view_real_rename_item (GimpItemTreeView *view,
GimpItem *item,
const gchar *new_name);
static void gimp_item_tree_view_new_clicked (GtkWidget *widget,
GimpItemTreeView *view);
static void gimp_item_tree_view_new_dropped (GtkWidget *widget,
......@@ -195,7 +188,6 @@ gimp_item_tree_view_class_init (GimpItemTreeViewClass *klass)
klass->add_item = NULL;
klass->remove_item = NULL;
klass->convert_item = NULL;
klass->rename_item = gimp_item_tree_view_real_rename_item;
klass->new_desc = NULL;
klass->duplicate_desc = NULL;
......@@ -574,30 +566,6 @@ gimp_item_tree_view_context_item (GimpContainerView *view,
}
/* GimpItemTreeView methods */
static void
gimp_item_tree_view_real_rename_item (GimpItemTreeView *view,
GimpItem *item,
const gchar *new_name)
{
if (strcmp (new_name, gimp_object_get_name (GIMP_OBJECT (item))))
{
GimpItemTreeViewClass *item_view_class;
item_view_class = GIMP_ITEM_TREE_VIEW_GET_CLASS (view);
gimp_image_undo_push_item_rename (view->gimage,
item_view_class->rename_desc,
item);
gimp_object_set_name (GIMP_OBJECT (item), new_name);
gimp_image_flush (view->gimage);
}
}
/* "New" functions */
static void
......@@ -871,8 +839,8 @@ gimp_item_tree_view_name_edited (GtkCellRendererText *cell,
item = GIMP_ITEM (renderer->viewable);
GIMP_ITEM_TREE_VIEW_GET_CLASS (view)->rename_item (view, item,
new_text);
gimp_item_rename (item, new_text);
gimp_image_flush (gimp_item_get_image (item));
g_object_unref (renderer);
}
......
......@@ -101,10 +101,6 @@ struct _GimpItemTreeViewClass
GimpRemoveItemFunc remove_item;
GimpConvertItemFunc convert_item;
void (* rename_item) (GimpItemTreeView *view,
GimpItem *item,
const gchar *new_name);
/* various descriptive strings for tooltips and undo steps */
const gchar *new_desc;
const gchar *duplicate_desc;
......@@ -114,7 +110,6 @@ struct _GimpItemTreeViewClass
const gchar *raise_to_top_desc;
const gchar *lower_desc;
const gchar *lower_to_bottom_desc;
const gchar *rename_desc;
};
......
......@@ -21,8 +21,6 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
......@@ -36,8 +34,6 @@
#include "core/gimplayermask.h"
#include "core/gimplayer-floating-sel.h"
#include "core/gimpimage.h"
#include "core/gimpimage-undo.h"
#include "core/gimpimage-undo-push.h"
#include "gimpcellrenderertoggle.h"
#include "gimpcellrendererviewable.h"
......@@ -70,9 +66,6 @@ static void gimp_layer_tree_view_set_preview_size (GimpContainerView *view);
static void gimp_layer_tree_view_remove_item (GimpImage *gimage,
GimpItem *layer);
static void gimp_layer_tree_view_rename_item (GimpItemTreeView *view,
GimpItem *item,
const gchar *new_name);
static void gimp_layer_tree_view_anchor_clicked (GtkWidget *widget,
GimpLayerTreeView *view);
......@@ -188,7 +181,6 @@ gimp_layer_tree_view_class_init (GimpLayerTreeViewClass *klass)
item_view_class->add_item = (GimpAddItemFunc) gimp_image_add_layer;
item_view_class->remove_item = gimp_layer_tree_view_remove_item;
item_view_class->convert_item = (GimpConvertItemFunc) gimp_layer_new_from_drawable;
item_view_class->rename_item = gimp_layer_tree_view_rename_item;
item_view_class->new_desc = _("New Layer");
item_view_class->duplicate_desc = _("Duplicate Layer");
......@@ -198,7 +190,6 @@ gimp_layer_tree_view_class_init (GimpLayerTreeViewClass *klass)
item_view_class->raise_to_top_desc = _("Raise Layer to Top");
item_view_class->lower_desc = _("Lower Layer");
item_view_class->lower_to_bottom_desc = _("Lower Layer to Bottom");
item_view_class->rename_desc = _("Rename Layer");
gimp_rgba_set (&black_color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
gimp_rgba_set (&white_color, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
......@@ -564,40 +555,6 @@ gimp_layer_tree_view_remove_item (GimpImage *gimage,
gimp_image_remove_layer (gimage, GIMP_LAYER (item));
}
static void
gimp_layer_tree_view_rename_item (GimpItemTreeView *view,
GimpItem *item,
const gchar *new_name)
{
if (strcmp (new_name, gimp_object_get_name (GIMP_OBJECT (item))))
{
GimpItemTreeViewClass *item_view_class;
GimpLayer *layer;
item_view_class = GIMP_ITEM_TREE_VIEW_GET_CLASS (view);
layer = GIMP_LAYER (item);
gimp_image_undo_group_start (view->gimage,
GIMP_UNDO_GROUP_ITEM_PROPERTIES,
item_view_class->rename_desc);
/* If the layer is a floating selection, make it a layer */
if (gimp_layer_is_floating_sel (layer))
floating_sel_to_layer (layer);
gimp_image_undo_push_item_rename (view->gimage,
item_view_class->rename_desc,
item);
gimp_object_set_name (GIMP_OBJECT (item), new_name);
gimp_image_undo_group_end (view->gimage);
gimp_image_flush (view->gimage);
}
}
/* Anchor callback */
......
......@@ -119,7 +119,6 @@ gimp_vectors_tree_view_class_init (GimpVectorsTreeViewClass *klass)
item_view_class->raise_to_top_desc = _("Raise Path to Top");
item_view_class->lower_desc = _("Lower Path");
item_view_class->lower_to_bottom_desc = _("Lower Path to Bottom");
item_view_class->rename_desc = _("Rename Path");
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment