mirror of https://github.com/GNOME/gimp.git
app/core/gimpimageundo.[ch] implement image and item parasite attach and
2007-02-02 Michael Natterer <mitch@gimp.org> * app/core/gimpimageundo.[ch] * app/core/gimpitempropundo.[ch]: implement image and item parasite attach and remove undos. They are image/item properties after all. * app/core/gimpimage-undo-push.[ch]: use them here and move the undo functions to the resp. image and item property sections. svn path=/trunk/; revision=21835
This commit is contained in:
parent
71fc3e7b00
commit
3c6912c52c
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2007-02-02 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/core/gimpimageundo.[ch]
|
||||
* app/core/gimpitempropundo.[ch]: implement image and item
|
||||
parasite attach and remove undos. They are image/item properties
|
||||
after all.
|
||||
|
||||
* app/core/gimpimage-undo-push.[ch]: use them here and move the
|
||||
undo functions to the resp. image and item property sections.
|
||||
|
||||
2007-02-02 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* plug-ins/FractalExplorer/Dialogs.c
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <glib-object.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
#include "libgimpconfig/gimpconfig.h"
|
||||
|
||||
#include "core-types.h"
|
||||
|
||||
|
@ -49,7 +48,6 @@
|
|||
#include "gimplayerpropundo.h"
|
||||
#include "gimplayerundo.h"
|
||||
#include "gimpmaskundo.h"
|
||||
#include "gimpparasitelist.h"
|
||||
#include "gimpsamplepoint.h"
|
||||
#include "gimpsamplepointundo.h"
|
||||
#include "gimpselection.h"
|
||||
|
@ -142,6 +140,40 @@ gimp_image_undo_push_image_colormap (GimpImage *image,
|
|||
NULL);
|
||||
}
|
||||
|
||||
GimpUndo *
|
||||
gimp_image_undo_push_image_parasite (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
const GimpParasite *parasite)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (parasite != NULL, NULL);
|
||||
|
||||
return gimp_image_undo_push (image, GIMP_TYPE_IMAGE_UNDO,
|
||||
0, 0,
|
||||
GIMP_UNDO_PARASITE_ATTACH, undo_desc,
|
||||
GIMP_DIRTY_IMAGE_META,
|
||||
NULL, NULL,
|
||||
"parasite-name", gimp_parasite_name (parasite),
|
||||
NULL);
|
||||
}
|
||||
|
||||
GimpUndo *
|
||||
gimp_image_undo_push_image_parasite_remove (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
const gchar *name)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
return gimp_image_undo_push (image, GIMP_TYPE_IMAGE_UNDO,
|
||||
0, 0,
|
||||
GIMP_UNDO_PARASITE_REMOVE, undo_desc,
|
||||
GIMP_DIRTY_IMAGE_META,
|
||||
NULL, NULL,
|
||||
"parasite-name", name,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
/********************************/
|
||||
/* Guide & Sample Point Undos */
|
||||
|
@ -354,6 +386,48 @@ gimp_image_undo_push_item_linked (GimpImage *image,
|
|||
NULL);
|
||||
}
|
||||
|
||||
GimpUndo *
|
||||
gimp_image_undo_push_item_parasite (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpItem *item,
|
||||
const GimpParasite *parasite)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
|
||||
g_return_val_if_fail (gimp_item_is_attached (item), NULL);
|
||||
g_return_val_if_fail (parasite != NULL, NULL);
|
||||
|
||||
return gimp_image_undo_push (image, GIMP_TYPE_ITEM_PROP_UNDO,
|
||||
0, 0,
|
||||
GIMP_UNDO_PARASITE_ATTACH, undo_desc,
|
||||
GIMP_DIRTY_ITEM_META,
|
||||
NULL, NULL,
|
||||
"item", item,
|
||||
"parasite-name", gimp_parasite_name (parasite),
|
||||
NULL);
|
||||
}
|
||||
|
||||
GimpUndo *
|
||||
gimp_image_undo_push_item_parasite_remove (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpItem *item,
|
||||
const gchar *name)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
|
||||
g_return_val_if_fail (gimp_item_is_attached (item), NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
return gimp_image_undo_push (image, GIMP_TYPE_ITEM_PROP_UNDO,
|
||||
0, 0,
|
||||
GIMP_UNDO_PARASITE_REMOVE, undo_desc,
|
||||
GIMP_DIRTY_ITEM_META,
|
||||
NULL, NULL,
|
||||
"item", item,
|
||||
"parasite-name", name,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
/***************************/
|
||||
/* Layer Add/Remove Undo */
|
||||
|
@ -974,213 +1048,6 @@ gimp_image_undo_push_fs_relax (GimpImage *image,
|
|||
}
|
||||
|
||||
|
||||
/*******************/
|
||||
/* Parasite Undo */
|
||||
/*******************/
|
||||
|
||||
typedef struct _ParasiteUndo ParasiteUndo;
|
||||
|
||||
struct _ParasiteUndo
|
||||
{
|
||||
GimpImage *image;
|
||||
GimpItem *item;
|
||||
GimpParasite *parasite;
|
||||
gchar *name;
|
||||
};
|
||||
|
||||
static gboolean undo_pop_parasite (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode,
|
||||
GimpUndoAccumulator *accum);
|
||||
static void undo_free_parasite (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode);
|
||||
|
||||
GimpUndo *
|
||||
gimp_image_undo_push_image_parasite (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
const GimpParasite *parasite)
|
||||
{
|
||||
GimpUndo *new;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (parasite != NULL, NULL);
|
||||
|
||||
if ((new = gimp_image_undo_push (image, GIMP_TYPE_UNDO,
|
||||
sizeof (ParasiteUndo),
|
||||
sizeof (ParasiteUndo),
|
||||
GIMP_UNDO_PARASITE_ATTACH, undo_desc,
|
||||
GIMP_DIRTY_IMAGE_META,
|
||||
undo_pop_parasite,
|
||||
undo_free_parasite,
|
||||
NULL)))
|
||||
{
|
||||
ParasiteUndo *pu = new->data;
|
||||
|
||||
pu->image = image;
|
||||
pu->item = NULL;
|
||||
pu->name = g_strdup (gimp_parasite_name (parasite));
|
||||
pu->parasite = gimp_parasite_copy (gimp_image_parasite_find (image,
|
||||
pu->name));
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GimpUndo *
|
||||
gimp_image_undo_push_image_parasite_remove (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
const gchar *name)
|
||||
{
|
||||
GimpUndo *new;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
if ((new = gimp_image_undo_push (image, GIMP_TYPE_UNDO,
|
||||
sizeof (ParasiteUndo),
|
||||
sizeof (ParasiteUndo),
|
||||
GIMP_UNDO_PARASITE_REMOVE, undo_desc,
|
||||
GIMP_DIRTY_IMAGE_META,
|
||||
undo_pop_parasite,
|
||||
undo_free_parasite,
|
||||
NULL)))
|
||||
{
|
||||
ParasiteUndo *pu = new->data;
|
||||
|
||||
pu->image = image;
|
||||
pu->item = NULL;
|
||||
pu->name = g_strdup (name);
|
||||
pu->parasite = gimp_parasite_copy (gimp_image_parasite_find (image,
|
||||
pu->name));
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GimpUndo *
|
||||
gimp_image_undo_push_item_parasite (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpItem *item,
|
||||
const GimpParasite *parasite)
|
||||
{
|
||||
GimpUndo *new;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
|
||||
g_return_val_if_fail (gimp_item_is_attached (item), NULL);
|
||||
g_return_val_if_fail (parasite != NULL, NULL);
|
||||
|
||||
if ((new = gimp_image_undo_push (image, GIMP_TYPE_UNDO,
|
||||
sizeof (ParasiteUndo),
|
||||
sizeof (ParasiteUndo),
|
||||
GIMP_UNDO_PARASITE_ATTACH, undo_desc,
|
||||
GIMP_DIRTY_ITEM_META,
|
||||
undo_pop_parasite,
|
||||
undo_free_parasite,
|
||||
NULL)))
|
||||
{
|
||||
ParasiteUndo *pu = new->data;
|
||||
|
||||
pu->image = NULL;
|
||||
pu->item = item;
|
||||
pu->name = g_strdup (gimp_parasite_name (parasite));
|
||||
pu->parasite = gimp_parasite_copy (gimp_item_parasite_find (item,
|
||||
pu->name));
|
||||
return new;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GimpUndo *
|
||||
gimp_image_undo_push_item_parasite_remove (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpItem *item,
|
||||
const gchar *name)
|
||||
{
|
||||
GimpUndo *new;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
|
||||
g_return_val_if_fail (gimp_item_is_attached (item), NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
if ((new = gimp_image_undo_push (image, GIMP_TYPE_UNDO,
|
||||
sizeof (ParasiteUndo),
|
||||
sizeof (ParasiteUndo),
|
||||
GIMP_UNDO_PARASITE_REMOVE, undo_desc,
|
||||
GIMP_DIRTY_ITEM_META,
|
||||
undo_pop_parasite,
|
||||
undo_free_parasite,
|
||||
NULL)))
|
||||
{
|
||||
ParasiteUndo *pu = new->data;
|
||||
|
||||
pu->image = NULL;
|
||||
pu->item = item;
|
||||
pu->name = g_strdup (name);
|
||||
pu->parasite = gimp_parasite_copy (gimp_item_parasite_find (item,
|
||||
pu->name));
|
||||
return new;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
undo_pop_parasite (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode,
|
||||
GimpUndoAccumulator *accum)
|
||||
{
|
||||
ParasiteUndo *pu = undo->data;
|
||||
GimpParasite *tmp;
|
||||
|
||||
tmp = pu->parasite;
|
||||
|
||||
if (pu->image)
|
||||
{
|
||||
pu->parasite = gimp_parasite_copy (gimp_image_parasite_find (undo->image,
|
||||
pu->name));
|
||||
if (tmp)
|
||||
gimp_parasite_list_add (pu->image->parasites, tmp);
|
||||
else
|
||||
gimp_parasite_list_remove (pu->image->parasites, pu->name);
|
||||
}
|
||||
else if (pu->item)
|
||||
{
|
||||
pu->parasite = gimp_parasite_copy (gimp_item_parasite_find (pu->item,
|
||||
pu->name));
|
||||
if (tmp)
|
||||
gimp_parasite_list_add (pu->item->parasites, tmp);
|
||||
else
|
||||
gimp_parasite_list_remove (pu->item->parasites, pu->name);
|
||||
}
|
||||
|
||||
if (tmp)
|
||||
gimp_parasite_free (tmp);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
undo_free_parasite (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode)
|
||||
{
|
||||
ParasiteUndo *pu = undo->data;
|
||||
|
||||
if (pu->parasite)
|
||||
gimp_parasite_free (pu->parasite);
|
||||
|
||||
if (pu->name)
|
||||
g_free (pu->name);
|
||||
|
||||
g_free (pu);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
/* Something for which programmer is too lazy to write an undo function for */
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -33,6 +33,12 @@ GimpUndo * gimp_image_undo_push_image_grid (GimpImage *image,
|
|||
GimpGrid *grid);
|
||||
GimpUndo * gimp_image_undo_push_image_colormap (GimpImage *image,
|
||||
const gchar *undo_desc);
|
||||
GimpUndo * gimp_image_undo_push_image_parasite (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
const GimpParasite *parasite);
|
||||
GimpUndo * gimp_image_undo_push_image_parasite_remove (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
const gchar *name);
|
||||
|
||||
|
||||
/* guide & sample point undos */
|
||||
|
@ -82,6 +88,15 @@ GimpUndo * gimp_image_undo_push_item_visibility (GimpImage *image,
|
|||
GimpUndo * gimp_image_undo_push_item_linked (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpItem *item);
|
||||
GimpUndo * gimp_image_undo_push_item_parasite (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpItem *item,
|
||||
const GimpParasite *parasite);
|
||||
GimpUndo * gimp_image_undo_push_item_parasite_remove(GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpItem *item,
|
||||
const gchar *name);
|
||||
|
||||
|
||||
|
||||
/* layer undos */
|
||||
|
@ -189,25 +204,6 @@ GimpUndo * gimp_image_undo_push_fs_relax (GimpImage *image,
|
|||
GimpLayer *floating_layer);
|
||||
|
||||
|
||||
/* parasite undos */
|
||||
|
||||
GimpUndo * gimp_image_undo_push_image_parasite (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
const GimpParasite *parasite);
|
||||
GimpUndo * gimp_image_undo_push_image_parasite_remove (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
const gchar *name);
|
||||
|
||||
GimpUndo * gimp_image_undo_push_item_parasite (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpItem *item,
|
||||
const GimpParasite *parasite);
|
||||
GimpUndo * gimp_image_undo_push_item_parasite_remove(GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpItem *item,
|
||||
const gchar *name);
|
||||
|
||||
|
||||
/* EEK undo */
|
||||
|
||||
GimpUndo * gimp_image_undo_push_cantundo (GimpImage *image,
|
||||
|
|
|
@ -18,8 +18,11 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
#include "libgimpconfig/gimpconfig.h"
|
||||
|
||||
#include "core-types.h"
|
||||
|
@ -30,12 +33,14 @@
|
|||
#include "gimpimage-colormap.h"
|
||||
#include "gimpimage-grid.h"
|
||||
#include "gimpimageundo.h"
|
||||
#include "gimpparasitelist.h"
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_GRID
|
||||
PROP_GRID,
|
||||
PROP_PARASITE_NAME
|
||||
};
|
||||
|
||||
|
||||
|
@ -87,6 +92,13 @@ gimp_image_undo_class_init (GimpImageUndoClass *klass)
|
|||
GIMP_TYPE_GRID,
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_PARASITE_NAME,
|
||||
g_param_spec_string ("parasite-name",
|
||||
NULL, NULL,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -136,6 +148,14 @@ gimp_image_undo_constructor (GType type,
|
|||
image_undo->num_colors * 3);
|
||||
break;
|
||||
|
||||
case GIMP_UNDO_PARASITE_ATTACH:
|
||||
case GIMP_UNDO_PARASITE_REMOVE:
|
||||
g_assert (image_undo->parasite_name != NULL);
|
||||
|
||||
image_undo->parasite = gimp_parasite_copy
|
||||
(gimp_image_parasite_find (image, image_undo->parasite_name));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
@ -161,6 +181,9 @@ gimp_image_undo_set_property (GObject *object,
|
|||
image_undo->grid = gimp_config_duplicate (GIMP_CONFIG (grid));
|
||||
}
|
||||
break;
|
||||
case PROP_PARASITE_NAME:
|
||||
image_undo->parasite_name = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
|
@ -181,6 +204,9 @@ gimp_image_undo_get_property (GObject *object,
|
|||
case PROP_GRID:
|
||||
g_value_set_object (value, image_undo->grid);
|
||||
break;
|
||||
case PROP_PARASITE_NAME:
|
||||
g_value_set_string (value, image_undo->parasite_name);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
|
@ -202,6 +228,14 @@ gimp_image_undo_get_memsize (GimpObject *object,
|
|||
memsize += gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid),
|
||||
gui_size);
|
||||
|
||||
if (image_undo->parasite_name)
|
||||
memsize += strlen (image_undo->parasite_name) + 1;
|
||||
|
||||
if (image_undo->parasite)
|
||||
memsize += (sizeof (GimpParasite) +
|
||||
strlen (image_undo->parasite->name) + 1 +
|
||||
image_undo->parasite->size);
|
||||
|
||||
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
||||
gui_size);
|
||||
}
|
||||
|
@ -322,6 +356,27 @@ gimp_image_undo_pop (GimpUndo *undo,
|
|||
}
|
||||
break;
|
||||
|
||||
case GIMP_UNDO_PARASITE_ATTACH:
|
||||
case GIMP_UNDO_PARASITE_REMOVE:
|
||||
{
|
||||
GimpParasite *parasite;
|
||||
|
||||
parasite = image_undo->parasite;
|
||||
|
||||
image_undo->parasite = gimp_parasite_copy
|
||||
(gimp_image_parasite_find (undo->image, image_undo->parasite_name));
|
||||
|
||||
if (parasite)
|
||||
gimp_parasite_list_add (undo->image->parasites, parasite);
|
||||
else
|
||||
gimp_parasite_list_remove (undo->image->parasites,
|
||||
image_undo->parasite_name);
|
||||
|
||||
if (parasite)
|
||||
gimp_parasite_free (parasite);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
@ -345,5 +400,17 @@ gimp_image_undo_free (GimpUndo *undo,
|
|||
image_undo->colormap = NULL;
|
||||
}
|
||||
|
||||
if (image_undo->parasite_name)
|
||||
{
|
||||
g_free (image_undo->parasite_name);
|
||||
image_undo->parasite_name = NULL;
|
||||
}
|
||||
|
||||
if (image_undo->parasite)
|
||||
{
|
||||
gimp_parasite_free (image_undo->parasite);
|
||||
image_undo->parasite = NULL;
|
||||
}
|
||||
|
||||
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ struct _GimpImageUndo
|
|||
GimpGrid *grid;
|
||||
gint num_colors;
|
||||
guchar *colormap;
|
||||
gchar *parasite_name;
|
||||
GimpParasite *parasite;
|
||||
};
|
||||
|
||||
struct _GimpImageUndoClass
|
||||
|
|
|
@ -22,24 +22,42 @@
|
|||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
|
||||
#include "core-types.h"
|
||||
|
||||
#include "gimpitem.h"
|
||||
#include "gimpitempropundo.h"
|
||||
#include "gimpparasitelist.h"
|
||||
|
||||
|
||||
static GObject * gimp_item_prop_undo_constructor (GType type,
|
||||
guint n_params,
|
||||
GObjectConstructParam *params);
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_PARASITE_NAME
|
||||
};
|
||||
|
||||
static gint64 gimp_item_prop_undo_get_memsize (GimpObject *object,
|
||||
gint64 *gui_size);
|
||||
|
||||
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);
|
||||
static GObject * gimp_item_prop_undo_constructor (GType type,
|
||||
guint n_params,
|
||||
GObjectConstructParam *params);
|
||||
static void gimp_item_prop_undo_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gimp_item_prop_undo_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static gint64 gimp_item_prop_undo_get_memsize (GimpObject *object,
|
||||
gint64 *gui_size);
|
||||
|
||||
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)
|
||||
|
@ -55,11 +73,20 @@ gimp_item_prop_undo_class_init (GimpItemPropUndoClass *klass)
|
|||
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
|
||||
|
||||
object_class->constructor = gimp_item_prop_undo_constructor;
|
||||
object_class->set_property = gimp_item_prop_undo_set_property;
|
||||
object_class->get_property = gimp_item_prop_undo_get_property;
|
||||
|
||||
gimp_object_class->get_memsize = gimp_item_prop_undo_get_memsize;
|
||||
|
||||
undo_class->pop = gimp_item_prop_undo_pop;
|
||||
undo_class->free = gimp_item_prop_undo_free;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_PARASITE_NAME,
|
||||
g_param_spec_string ("parasite-name",
|
||||
NULL, NULL,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -102,6 +129,14 @@ gimp_item_prop_undo_constructor (GType type,
|
|||
item_prop_undo->linked = gimp_item_get_linked (item);
|
||||
break;
|
||||
|
||||
case GIMP_UNDO_PARASITE_ATTACH:
|
||||
case GIMP_UNDO_PARASITE_REMOVE:
|
||||
g_assert (item_prop_undo->parasite_name != NULL);
|
||||
|
||||
item_prop_undo->parasite = gimp_parasite_copy
|
||||
(gimp_item_parasite_find (item, item_prop_undo->parasite_name));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
@ -109,6 +144,46 @@ gimp_item_prop_undo_constructor (GType type,
|
|||
return object;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_item_prop_undo_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpItemPropUndo *item_prop_undo = GIMP_ITEM_PROP_UNDO (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_PARASITE_NAME:
|
||||
item_prop_undo->parasite_name = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_item_prop_undo_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpItemPropUndo *item_prop_undo = GIMP_ITEM_PROP_UNDO (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_PARASITE_NAME:
|
||||
g_value_set_string (value, item_prop_undo->parasite_name);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gint64
|
||||
gimp_item_prop_undo_get_memsize (GimpObject *object,
|
||||
gint64 *gui_size)
|
||||
|
@ -119,6 +194,14 @@ gimp_item_prop_undo_get_memsize (GimpObject *object,
|
|||
if (item_prop_undo->name)
|
||||
memsize += strlen (item_prop_undo->name) + 1;
|
||||
|
||||
if (item_prop_undo->parasite_name)
|
||||
memsize += strlen (item_prop_undo->parasite_name) + 1;
|
||||
|
||||
if (item_prop_undo->parasite)
|
||||
memsize += (sizeof (GimpParasite) +
|
||||
strlen (item_prop_undo->parasite->name) + 1 +
|
||||
item_prop_undo->parasite->size);
|
||||
|
||||
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
||||
gui_size);
|
||||
}
|
||||
|
@ -182,6 +265,27 @@ gimp_item_prop_undo_pop (GimpUndo *undo,
|
|||
}
|
||||
break;
|
||||
|
||||
case GIMP_UNDO_PARASITE_ATTACH:
|
||||
case GIMP_UNDO_PARASITE_REMOVE:
|
||||
{
|
||||
GimpParasite *parasite;
|
||||
|
||||
parasite = item_prop_undo->parasite;
|
||||
|
||||
item_prop_undo->parasite = gimp_parasite_copy
|
||||
(gimp_item_parasite_find (item, item_prop_undo->parasite_name));
|
||||
|
||||
if (parasite)
|
||||
gimp_parasite_list_add (item->parasites, parasite);
|
||||
else
|
||||
gimp_parasite_list_remove (item->parasites,
|
||||
item_prop_undo->parasite_name);
|
||||
|
||||
if (parasite)
|
||||
gimp_parasite_free (parasite);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
@ -199,5 +303,17 @@ gimp_item_prop_undo_free (GimpUndo *undo,
|
|||
item_prop_undo->name = NULL;
|
||||
}
|
||||
|
||||
if (item_prop_undo->parasite_name)
|
||||
{
|
||||
g_free (item_prop_undo->parasite_name);
|
||||
item_prop_undo->parasite_name = NULL;
|
||||
}
|
||||
|
||||
if (item_prop_undo->parasite)
|
||||
{
|
||||
gimp_parasite_free (item_prop_undo->parasite);
|
||||
item_prop_undo->parasite = NULL;
|
||||
}
|
||||
|
||||
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ struct _GimpItemPropUndo
|
|||
gint offset_y;
|
||||
gboolean visible;
|
||||
gboolean linked;
|
||||
gchar *parasite_name;
|
||||
GimpParasite *parasite;
|
||||
};
|
||||
|
||||
struct _GimpItemPropUndoClass
|
||||
|
|
Loading…
Reference in New Issue