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

app/core/Makefile.am app/core/core-types.h new undo class which handles

2007-01-28  Michael Natterer  <mitch@gimp.org>

	* app/core/Makefile.am
	* app/core/core-types.h
	* app/core/gimpitempropundo.[ch]: new undo class which handles
	ITEM_RENAME, ITEM_DISPLACE, ITEM_VISIBILITY and ITEM_LINKED undos.

	* app/core/gimpimage-undo-push.c: use the new undo class and
	remove the resp. code here.


svn path=/trunk/; revision=21790
parent 11a43d6a
2007-01-28 Michael Natterer <mitch@gimp.org>
* app/core/Makefile.am
* app/core/core-types.h
* app/core/gimpitempropundo.[ch]: new undo class which handles
ITEM_RENAME, ITEM_DISPLACE, ITEM_VISIBILITY and ITEM_LINKED undos.
* app/core/gimpimage-undo-push.c: use the new undo class and
remove the resp. code here.
2007-01-28 Michael Natterer <mitch@gimp.org>
 
* app/core/Makefile.am
......@@ -198,6 +198,8 @@ libappcore_a_sources = \
gimpitem-linked.h \
gimpitem-preview.c \
gimpitem-preview.h \
gimpitempropundo.c \
gimpitempropundo.h \
gimpitemundo.c \
gimpitemundo.h \
gimplayer.c \
......
......@@ -112,6 +112,7 @@ typedef struct _GimpLayerMask GimpLayerMask;
typedef struct _GimpUndo GimpUndo;
typedef struct _GimpImageUndo GimpImageUndo;
typedef struct _GimpItemUndo GimpItemUndo;
typedef struct _GimpItemPropUndo GimpItemPropUndo;
typedef struct _GimpChannelUndo GimpChannelUndo;
typedef struct _GimpDrawableUndo GimpDrawableUndo;
typedef struct _GimpUndoStack GimpUndoStack;
......
......@@ -18,8 +18,6 @@
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
......@@ -43,6 +41,7 @@
#include "gimpimage-undo.h"
#include "gimpimage-undo-push.h"
#include "gimpimageundo.h"
#include "gimpitempropundo.h"
#include "gimplayer.h"
#include "gimplayer-floating-sel.h"
#include "gimplayermask.h"
......@@ -74,8 +73,7 @@ gimp_image_undo_push_image_type (GimpImage *image,
0, 0,
GIMP_UNDO_IMAGE_TYPE, undo_desc,
GIMP_DIRTY_IMAGE,
NULL,
NULL,
NULL, NULL,
NULL)))
{
return TRUE;
......@@ -101,8 +99,7 @@ gimp_image_undo_push_image_size (GimpImage *image,
0, 0,
GIMP_UNDO_IMAGE_SIZE, undo_desc,
GIMP_DIRTY_IMAGE | GIMP_DIRTY_IMAGE_SIZE,
NULL,
NULL,
NULL, NULL,
NULL)))
{
return TRUE;
......@@ -128,8 +125,7 @@ gimp_image_undo_push_image_resolution (GimpImage *image,
0, 0,
GIMP_UNDO_IMAGE_RESOLUTION, undo_desc,
GIMP_DIRTY_IMAGE,
NULL,
NULL,
NULL, NULL,
NULL)))
{
return TRUE;
......@@ -554,8 +550,7 @@ gimp_image_undo_push_drawable (GimpImage *image,
0, 0,
GIMP_UNDO_DRAWABLE, undo_desc,
GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE,
NULL,
NULL,
NULL, NULL,
"item", item,
"tiles", tiles,
"sparse", sparse,
......@@ -693,8 +688,7 @@ gimp_image_undo_push_mask (GimpImage *image,
GIMP_IS_SELECTION (mask) ?
GIMP_DIRTY_SELECTION :
GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE,
NULL,
NULL,
NULL, NULL,
"item", mask,
NULL)))
{
......@@ -709,104 +703,36 @@ gimp_image_undo_push_mask (GimpImage *image,
/* Item Rename Undo */
/**********************/
typedef struct _ItemRenameUndo ItemRenameUndo;
struct _ItemRenameUndo
{
gchar *name;
};
static gboolean undo_pop_item_rename (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void undo_free_item_rename (GimpUndo *undo,
GimpUndoMode undo_mode);
gboolean
gimp_image_undo_push_item_rename (GimpImage *image,
const gchar *undo_desc,
GimpItem *item)
{
GimpUndo *new;
gint64 size;
const gchar *name;
GimpUndo *new;
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
g_return_val_if_fail (gimp_item_is_attached (item), FALSE);
name = gimp_object_get_name (GIMP_OBJECT (item));
size = sizeof (ItemRenameUndo) + strlen (name) + 1;
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_UNDO,
size, sizeof (ItemRenameUndo),
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_PROP_UNDO,
0, 0,
GIMP_UNDO_ITEM_RENAME, undo_desc,
GIMP_DIRTY_ITEM_META,
undo_pop_item_rename,
undo_free_item_rename,
NULL, NULL,
"item", item,
NULL)))
{
ItemRenameUndo *iru = new->data;
iru->name = g_strdup (name);
return TRUE;
}
return FALSE;
}
static gboolean
undo_pop_item_rename (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
ItemRenameUndo *iru = undo->data;
GimpItem *item = GIMP_ITEM_UNDO (undo)->item;
gchar *tmp;
undo->size -= strlen (iru->name);
tmp = g_strdup (gimp_object_get_name (GIMP_OBJECT (item)));
gimp_object_take_name (GIMP_OBJECT (item), iru->name);
iru->name = tmp;
undo->size += strlen (iru->name);
return TRUE;
}
static void
undo_free_item_rename (GimpUndo *undo,
GimpUndoMode undo_mode)
{
ItemRenameUndo *iru = undo->data;
g_free (iru->name);
g_free (iru);
}
/****************************/
/* Item displacement Undo */
/****************************/
typedef struct _ItemDisplaceUndo ItemDisplaceUndo;
struct _ItemDisplaceUndo
{
gint old_offset_x;
gint old_offset_y;
};
static gboolean undo_pop_item_displace (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void undo_free_item_displace (GimpUndo *undo,
GimpUndoMode undo_mode);
gboolean
gimp_image_undo_push_item_displace (GimpImage *image,
const gchar *undo_desc,
......@@ -818,76 +744,27 @@ gimp_image_undo_push_item_displace (GimpImage *image,
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
g_return_val_if_fail (gimp_item_is_attached (item), FALSE);
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_UNDO,
sizeof (ItemDisplaceUndo),
sizeof (ItemDisplaceUndo),
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_PROP_UNDO,
0, 0,
GIMP_UNDO_ITEM_DISPLACE, undo_desc,
GIMP_IS_DRAWABLE (item) ?
GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE :
GIMP_DIRTY_ITEM | GIMP_DIRTY_VECTORS,
undo_pop_item_displace,
undo_free_item_displace,
NULL, NULL,
"item", item,
NULL)))
{
ItemDisplaceUndo *idu = new->data;
gimp_item_offsets (item, &idu->old_offset_x, &idu->old_offset_y);
return TRUE;
}
return FALSE;
}
static gboolean
undo_pop_item_displace (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
ItemDisplaceUndo *idu = undo->data;
GimpItem *item = GIMP_ITEM_UNDO (undo)->item;
gint offset_x;
gint offset_y;
gimp_item_offsets (item, &offset_x, &offset_y);
gimp_item_translate (item,
idu->old_offset_x - offset_x,
idu->old_offset_y - offset_y,
FALSE);
idu->old_offset_x = offset_x;
idu->old_offset_y = offset_y;
return TRUE;
}
static void
undo_free_item_displace (GimpUndo *undo,
GimpUndoMode undo_mode)
{
g_free (undo->data);
}
/******************************/
/* Item Visibility Undo */
/******************************/
typedef struct _ItemVisibilityUndo ItemVisibilityUndo;
struct _ItemVisibilityUndo
{
gboolean old_visible;
};
static gboolean undo_pop_item_visibility (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void undo_free_item_visibility (GimpUndo *undo,
GimpUndoMode undo_mode);
gboolean
gimp_image_undo_push_item_visibility (GimpImage *image,
const gchar *undo_desc,
......@@ -899,67 +776,25 @@ gimp_image_undo_push_item_visibility (GimpImage *image,
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
g_return_val_if_fail (gimp_item_is_attached (item), FALSE);
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_UNDO,
sizeof (ItemVisibilityUndo),
sizeof (ItemVisibilityUndo),
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_PROP_UNDO,
0, 0,
GIMP_UNDO_ITEM_VISIBILITY, undo_desc,
GIMP_DIRTY_ITEM_META,
undo_pop_item_visibility,
undo_free_item_visibility,
NULL, NULL,
"item", item,
NULL)))
{
ItemVisibilityUndo *ivu = new->data;
ivu->old_visible = gimp_item_get_visible (item);
return TRUE;
}
return FALSE;
}
static gboolean
undo_pop_item_visibility (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
ItemVisibilityUndo *ivu = undo->data;
GimpItem *item = GIMP_ITEM_UNDO (undo)->item;
gboolean visible;
visible = gimp_item_get_visible (item);
gimp_item_set_visible (item, ivu->old_visible, FALSE);
ivu->old_visible = visible;
return TRUE;
}
static void
undo_free_item_visibility (GimpUndo *undo,
GimpUndoMode undo_mode)
{
g_free (undo->data);
}
/**********************/
/* Item linked Undo */
/**********************/
typedef struct _ItemLinkedUndo ItemLinkedUndo;
struct _ItemLinkedUndo
{
gboolean old_linked;
};
static gboolean undo_pop_item_linked (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void undo_free_item_linked (GimpUndo *undo,
GimpUndoMode undo_mode);
gboolean
gimp_image_undo_push_item_linked (GimpImage *image,
const gchar *undo_desc,
......@@ -971,49 +806,20 @@ gimp_image_undo_push_item_linked (GimpImage *image,
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
g_return_val_if_fail (gimp_item_is_attached (item), FALSE);
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_UNDO,
sizeof (ItemLinkedUndo),
sizeof (ItemLinkedUndo),
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_PROP_UNDO,
0, 0,
GIMP_UNDO_ITEM_LINKED, undo_desc,
GIMP_DIRTY_ITEM_META,
undo_pop_item_linked,
undo_free_item_linked,
NULL, NULL,
"item", item,
NULL)))
{
ItemLinkedUndo *ilu = new->data;
ilu->old_linked = gimp_item_get_linked (item);
return TRUE;
}
return FALSE;
}
static gboolean
undo_pop_item_linked (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
ItemLinkedUndo *ilu = undo->data;
GimpItem *item = GIMP_ITEM_UNDO (undo)->item;
gboolean linked;
linked = gimp_item_get_linked (item);
gimp_item_set_linked (item, ilu->old_linked, FALSE);
ilu->old_linked = linked;
return TRUE;
}
static void
undo_free_item_linked (GimpUndo *undo,
GimpUndoMode undo_mode)
{
g_free (undo->data);
}
/***************************/
/* Layer Add/Remove Undo */
......@@ -1445,8 +1251,7 @@ gimp_image_undo_push_text_layer (GimpImage *image,
0, 0,
GIMP_UNDO_TEXT_LAYER, undo_desc,
GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE,
NULL,
NULL,
NULL, NULL,
"item", layer,
"param", pspec,
NULL)))
......
/* Gimp - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include "core-types.h"
#include "gimpitem.h"
#include "gimpitempropundo.h"
static GObject * gimp_item_prop_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_item_prop_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void gimp_item_prop_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode);
G_DEFINE_TYPE (GimpItemPropUndo, gimp_item_prop_undo, GIMP_TYPE_ITEM_UNDO)
#define parent_class gimp_item_prop_undo_parent_class
static void
gimp_item_prop_undo_class_init (GimpItemPropUndoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
object_class->constructor = gimp_item_prop_undo_constructor;
undo_class->pop = gimp_item_prop_undo_pop;
undo_class->free = gimp_item_prop_undo_free;
}
static void
gimp_item_prop_undo_init (GimpItemPropUndo *undo)
{
}
static GObject *
gimp_item_prop_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpItemPropUndo *item_prop_undo;
GimpItem *item;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
item_prop_undo = GIMP_ITEM_PROP_UNDO (object);
item = GIMP_ITEM_UNDO (object)->item;
if (GIMP_UNDO (object)->undo_type == GIMP_UNDO_ITEM_RENAME)
{
item_prop_undo->name = g_strdup (gimp_object_get_name (GIMP_OBJECT (item)));
GIMP_UNDO (object)->size += strlen (item_prop_undo->name) + 1;
}
gimp_item_offsets (item,
&item_prop_undo->offset_x,
&item_prop_undo->offset_y);
item_prop_undo->visible = gimp_item_get_visible (item);
item_prop_undo->linked = gimp_item_get_linked (item);
return object;
}
static void
gimp_item_prop_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
GimpItemPropUndo *item_prop_undo = GIMP_ITEM_PROP_UNDO (undo);
GimpItem *item = GIMP_ITEM_UNDO (undo)->item;
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
if (undo->undo_type == GIMP_UNDO_ITEM_RENAME)
{
gchar *name;
undo->size -= strlen (item_prop_undo->name) + 1;
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (item)));
gimp_object_take_name (GIMP_OBJECT (item), item_prop_undo->name);
item_prop_undo->name = name;
undo->size += strlen (item_prop_undo->name) + 1;
}
else if (undo->undo_type == GIMP_UNDO_ITEM_DISPLACE)
{
gint offset_x;
gint offset_y;
gimp_item_offsets (item, &offset_x, &offset_y);
gimp_item_translate (item,
item_prop_undo->offset_x - offset_x,
item_prop_undo->offset_y - offset_y,
FALSE);
item_prop_undo->offset_x = offset_x;
item_prop_undo->offset_y = offset_y;
}
else if (undo->undo_type == GIMP_UNDO_ITEM_VISIBILITY)
{
gboolean visible;
visible = gimp_item_get_visible (item);
gimp_item_set_visible (item, item_prop_undo->visible, FALSE);
item_prop_undo->visible = visible;
}
else if (undo->undo_type == GIMP_UNDO_ITEM_LINKED)
{
gboolean linked;
linked = gimp_item_get_linked (item);
gimp_item_set_linked (item, item_prop_undo->linked, FALSE);
item_prop_undo->linked = linked;
}
else
{
g_assert_not_reached ();
}
}
static void
gimp_item_prop_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode)
{
GimpItemPropUndo *item_prop_undo = GIMP_ITEM_PROP_UNDO (undo);
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
if (item_prop_undo->name)
{
g_free (item_prop_undo->name);
item_prop_undo->name = NULL;
}
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_ITEM_PROP_UNDO_H__
#define __GIMP_ITEM_PROP_UNDO_H__
#include "gimpitemundo.h"
#define GIMP_TYPE_ITEM_PROP_UNDO (gimp_item_prop_undo_get_type ())
#define GIMP_ITEM_PROP_UNDO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_ITEM_PROP_UNDO, GimpItemPropUndo))
#define GIMP_ITEM_PROP_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_ITEM_PROP_UNDO, GimpItemPropUndoClass))
#define GIMP_IS_ITEM_PROP_UNDO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_ITEM_PROP_UNDO))
#define GIMP_IS_ITEM_PROP_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_ITEM_PROP_UNDO))
#define GIMP_ITEM_PROP_UNDO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_ITEM_PROP_UNDO, GimpItemPropUndoClass))
typedef struct _GimpItemPropUndoClass GimpItemPropUndoClass;
struct _GimpItemPropUndo
{
GimpItemUndo parent_instance;
gchar *name;
gint offset_x;
gint offset