
2003-02-12 Michael Natterer <mitch@gimp.org> Moved the undo system to the core: Keep GimpUndoStack objects as undo and redo stack. Use GimpUndo objects as members of the stacks. GimpUndoStack is derived from GimpUndo and keeps undo groups, so undo group handling is much simpler than before (the whole group is just a single GimpUndo object on the stack and not everything between group boundary markers). * app/Makefile.am * app/undo_types.h: removed. * app/config/gimpcoreconfig.[ch]: added "gulong undo_size". * app/config/gimprc-blurbs.h: and its blurb. * app/core/core-enums.[ch]: added GimpUndoMode and GimpUndoType. * app/core/core-types.h: removed UndoType, added GimpUndoAccumulator, GimpUndoPopFunc and GimpUndoFreeFunc. * app/core/gimpundo.[ch]: do everything the old "Undo" struct did. Removed the virtual push() function and added free(). * app/core/gimpundostack.[ch]: keeps the new undo/redo stacks and also acts as undo group. * app/core/gimpimage-undo.[ch]: moved the undo apparatus here. * app/core/gimpimage.[ch]: removed the old stuff. * app/core/gimpmarshal.list: added marshaller needed for GimpUndo. * app/undo.[ch]: removed the whole undo mechanism. Only the actual undo pushing functions are left. * app/undo_history.c * app/gui/edit-commands.c * app/gui/file-commands.c * app/gui/image-menu.c * app/gui/preferences-dialog.c * app/tools/gimpeditselectiontool.c: changed accordingly.
311 lines
8.2 KiB
C
311 lines
8.2 KiB
C
/* The GIMP -- an 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 <glib-object.h>
|
|
|
|
#include "core-types.h"
|
|
|
|
#include "gimpimage.h"
|
|
#include "gimplist.h"
|
|
#include "gimpundo.h"
|
|
#include "gimpundostack.h"
|
|
|
|
|
|
static void gimp_undo_stack_class_init (GimpUndoStackClass *klass);
|
|
static void gimp_undo_stack_init (GimpUndoStack *stack);
|
|
|
|
static void gimp_undo_stack_finalize (GObject *object);
|
|
|
|
static gsize gimp_undo_stack_get_memsize (GimpObject *object);
|
|
|
|
static void gimp_undo_stack_pop (GimpUndo *undo,
|
|
GimpImage *gimage,
|
|
GimpUndoMode undo_mode,
|
|
GimpUndoAccumulator *accum);
|
|
static void gimp_undo_stack_free (GimpUndo *undo,
|
|
GimpImage *gimage,
|
|
GimpUndoMode undo_mode);
|
|
|
|
static void gimp_undo_stack_add_callback (GimpContainer *container,
|
|
GimpObject *object,
|
|
gpointer data);
|
|
static void gimp_undo_stack_remove_callback (GimpContainer *container,
|
|
GimpObject *object,
|
|
gpointer data);
|
|
|
|
|
|
static GimpUndoClass *parent_class = NULL;
|
|
|
|
|
|
GType
|
|
gimp_undo_stack_get_type (void)
|
|
{
|
|
static GType undo_stack_type = 0;
|
|
|
|
if (! undo_stack_type)
|
|
{
|
|
static const GTypeInfo undo_stack_info =
|
|
{
|
|
sizeof (GimpUndoStackClass),
|
|
(GBaseInitFunc) NULL,
|
|
(GBaseFinalizeFunc) NULL,
|
|
(GClassInitFunc) gimp_undo_stack_class_init,
|
|
NULL, /* class_finalize */
|
|
NULL, /* class_data */
|
|
sizeof (GimpUndoStack),
|
|
0, /* n_preallocs */
|
|
(GInstanceInitFunc) gimp_undo_stack_init,
|
|
};
|
|
|
|
undo_stack_type = g_type_register_static (GIMP_TYPE_UNDO,
|
|
"GimpUndoStack",
|
|
&undo_stack_info, 0);
|
|
}
|
|
|
|
return undo_stack_type;
|
|
}
|
|
|
|
static void
|
|
gimp_undo_stack_class_init (GimpUndoStackClass *klass)
|
|
{
|
|
GObjectClass *object_class;
|
|
GimpObjectClass *gimp_object_class;
|
|
GimpUndoClass *undo_class;
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
undo_class = GIMP_UNDO_CLASS (klass);
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
object_class->finalize = gimp_undo_stack_finalize;
|
|
|
|
gimp_object_class->get_memsize = gimp_undo_stack_get_memsize;
|
|
|
|
undo_class->pop = gimp_undo_stack_pop;
|
|
undo_class->free = gimp_undo_stack_free;
|
|
}
|
|
|
|
static void
|
|
gimp_undo_stack_init (GimpUndoStack *stack)
|
|
{
|
|
GimpContainer *undos;
|
|
|
|
undos = gimp_list_new (GIMP_TYPE_UNDO,
|
|
GIMP_CONTAINER_POLICY_STRONG);
|
|
|
|
stack->undos = undos;
|
|
|
|
g_signal_connect (undos, "add",
|
|
G_CALLBACK (gimp_undo_stack_add_callback),
|
|
stack);
|
|
g_signal_connect (undos, "remove",
|
|
G_CALLBACK (gimp_undo_stack_remove_callback),
|
|
stack);
|
|
|
|
stack->gimage = NULL;
|
|
}
|
|
|
|
static void
|
|
gimp_undo_stack_finalize (GObject *object)
|
|
{
|
|
GimpUndoStack *stack;
|
|
|
|
stack = GIMP_UNDO_STACK (object);
|
|
|
|
if (stack->undos)
|
|
{
|
|
g_object_unref (stack->undos);
|
|
stack->undos = NULL;
|
|
}
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
}
|
|
|
|
static gsize
|
|
gimp_undo_stack_get_memsize (GimpObject *object)
|
|
{
|
|
GimpUndoStack *stack;
|
|
gsize memsize = 0;
|
|
|
|
stack = GIMP_UNDO_STACK (object);
|
|
|
|
if (stack->undos)
|
|
memsize += gimp_object_get_memsize (GIMP_OBJECT (stack->undos));
|
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
|
|
}
|
|
|
|
static void
|
|
gimp_undo_stack_pop (GimpUndo *undo,
|
|
GimpImage *gimage,
|
|
GimpUndoMode undo_mode,
|
|
GimpUndoAccumulator *accum)
|
|
{
|
|
GimpUndoStack *stack;
|
|
GList *list;
|
|
|
|
stack = GIMP_UNDO_STACK (undo);
|
|
|
|
for (list = GIMP_LIST (stack->undos)->list;
|
|
list;
|
|
list = g_list_next (list))
|
|
{
|
|
GimpUndo *child;
|
|
|
|
child = GIMP_UNDO (list->data);
|
|
|
|
gimp_undo_pop (child, gimage, undo_mode, accum);
|
|
}
|
|
}
|
|
|
|
static void
|
|
gimp_undo_stack_free (GimpUndo *undo,
|
|
GimpImage *gimage,
|
|
GimpUndoMode undo_mode)
|
|
{
|
|
GimpUndoStack *stack;
|
|
GList *list;
|
|
|
|
stack = GIMP_UNDO_STACK (undo);
|
|
|
|
for (list = GIMP_LIST (stack->undos)->list;
|
|
list;
|
|
list = g_list_next (list))
|
|
{
|
|
GimpUndo *child;
|
|
|
|
child = GIMP_UNDO (list->data);
|
|
|
|
gimp_undo_free (child, gimage, undo_mode);
|
|
g_object_unref (child);
|
|
}
|
|
|
|
while (GIMP_LIST (stack->undos)->list)
|
|
gimp_container_remove (GIMP_CONTAINER (stack->undos),
|
|
GIMP_OBJECT (GIMP_LIST (stack->undos)->list->data));
|
|
}
|
|
|
|
GimpUndoStack *
|
|
gimp_undo_stack_new (GimpImage *gimage)
|
|
{
|
|
GimpUndoStack *stack;
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
stack = GIMP_UNDO_STACK (g_object_new (GIMP_TYPE_UNDO_STACK, NULL));
|
|
|
|
stack->gimage = gimage;
|
|
|
|
return stack;
|
|
}
|
|
|
|
void
|
|
gimp_undo_stack_push_undo (GimpUndoStack *stack,
|
|
GimpUndo *undo)
|
|
{
|
|
g_return_if_fail (GIMP_IS_UNDO_STACK (stack));
|
|
g_return_if_fail (GIMP_IS_UNDO (undo));
|
|
|
|
gimp_container_add (GIMP_CONTAINER (stack->undos), GIMP_OBJECT (undo));
|
|
}
|
|
|
|
GimpUndo *
|
|
gimp_undo_stack_pop_undo (GimpUndoStack *stack,
|
|
GimpUndoMode undo_mode,
|
|
GimpUndoAccumulator *accum)
|
|
{
|
|
GimpObject *object;
|
|
|
|
g_return_val_if_fail (GIMP_IS_UNDO_STACK (stack), NULL);
|
|
g_return_val_if_fail (accum != NULL, NULL);
|
|
|
|
object = gimp_container_get_child_by_index (GIMP_CONTAINER (stack->undos),0);
|
|
|
|
if (object)
|
|
{
|
|
gimp_container_remove (GIMP_CONTAINER (stack->undos), object);
|
|
gimp_undo_pop (GIMP_UNDO (object), stack->gimage, undo_mode, accum);
|
|
|
|
return GIMP_UNDO (object);
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void
|
|
gimp_undo_stack_free_bottom (GimpUndoStack *stack,
|
|
GimpUndoMode undo_mode)
|
|
{
|
|
GimpObject *object;
|
|
gint n_children;
|
|
|
|
g_return_if_fail (GIMP_IS_UNDO_STACK (stack));
|
|
|
|
n_children = gimp_container_num_children (GIMP_CONTAINER (stack->undos));
|
|
|
|
object = gimp_container_get_child_by_index (GIMP_CONTAINER (stack->undos),
|
|
n_children - 1);
|
|
|
|
if (object)
|
|
{
|
|
gimp_container_remove (GIMP_CONTAINER (stack->undos), object);
|
|
gimp_undo_free (GIMP_UNDO (object), stack->gimage, undo_mode);
|
|
|
|
g_object_unref (object);
|
|
}
|
|
}
|
|
|
|
GimpUndo *
|
|
gimp_undo_stack_peek (GimpUndoStack *stack)
|
|
{
|
|
GimpObject *object;
|
|
|
|
g_return_val_if_fail (GIMP_IS_UNDO_STACK (stack), NULL);
|
|
|
|
object = gimp_container_get_child_by_index (GIMP_CONTAINER (stack->undos), 0);
|
|
|
|
return (object ? GIMP_UNDO (object) : NULL);
|
|
}
|
|
|
|
static void
|
|
gimp_undo_stack_add_callback (GimpContainer *container,
|
|
GimpObject *object,
|
|
gpointer data)
|
|
{
|
|
GimpUndo *undo;
|
|
GimpUndo *stack;
|
|
|
|
undo = GIMP_UNDO (object);
|
|
stack = GIMP_UNDO (data);
|
|
}
|
|
|
|
static void
|
|
gimp_undo_stack_remove_callback (GimpContainer *container,
|
|
GimpObject *object,
|
|
gpointer data)
|
|
{
|
|
GimpUndo *undo;
|
|
GimpUndo *stack;
|
|
|
|
undo = GIMP_UNDO (object);
|
|
stack = GIMP_UNDO (data);
|
|
}
|