1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "glib-object.h"
25
#include "plug-in-types.h"
27
#include "core/gimp.h"
28
#include "core/gimpcontainer.h"
29
#include "core/gimpimage.h"
30
#include "core/gimpimage-undo.h"
31
#include "core/gimpdrawable.h"
32
#include "core/gimpundostack.h"
34
#include "gimpplugin.h"
35
#include "gimpplugin-cleanup.h"
36
#include "gimppluginmanager.h"
37
#include "gimppluginprocedure.h"
40
typedef struct _GimpPlugInCleanupImage GimpPlugInCleanupImage;
42
struct _GimpPlugInCleanupImage
45
gint undo_group_count;
49
/* local function prototypes */
51
static GimpPlugInCleanupImage *
52
gimp_plug_in_cleanup_get_image (GimpPlugInProcFrame *proc_frame,
56
/* public functions */
59
gimp_plug_in_cleanup_undo_group_start (GimpPlugIn *plug_in,
62
GimpPlugInProcFrame *proc_frame;
63
GimpPlugInCleanupImage *cleanup;
65
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
66
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
68
proc_frame = gimp_plug_in_get_proc_frame (plug_in);
69
cleanup = gimp_plug_in_cleanup_get_image (proc_frame, image);
71
g_printerr ("\n%s: procedure %s starts undo group on "
72
"image with group count %d\n",
73
G_STRFUNC, GIMP_OBJECT (proc_frame->procedure)->name,
78
g_printerr ("%s: creating new cleanup entry => SUCCESS\n", G_STRFUNC);
80
cleanup = g_new0 (GimpPlugInCleanupImage, 1);
82
cleanup->image = image;
83
cleanup->undo_group_count = image->group_count;
85
proc_frame->cleanups = g_list_prepend (proc_frame->cleanups, cleanup);
89
g_printerr ("%s: using existing cleanup entry => SUCCESS\n", G_STRFUNC);
96
gimp_plug_in_cleanup_undo_group_end (GimpPlugIn *plug_in,
99
GimpPlugInProcFrame *proc_frame;
100
GimpPlugInCleanupImage *cleanup;
102
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
103
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
105
proc_frame = gimp_plug_in_get_proc_frame (plug_in);
106
cleanup = gimp_plug_in_cleanup_get_image (proc_frame, image);
108
g_printerr ("\n%s: procedure %s ends undo group on "
109
"image with group count %d\n",
110
G_STRFUNC, GIMP_OBJECT (proc_frame->procedure)->name,
115
g_printerr ("%s: no cleanup entry found => FAILURE\n", G_STRFUNC);
119
if (cleanup->undo_group_count == image->group_count - 1)
121
g_printerr ("%s: group count balanced, deleting cleanup entry => SUCCESS\n",
124
proc_frame->cleanups = g_list_remove (proc_frame->cleanups, cleanup);
129
g_printerr ("%s: undo groups still open, keeping cleanup entry => SUCCESS\n",
137
gimp_plug_in_cleanup (GimpPlugIn *plug_in,
138
GimpPlugInProcFrame *proc_frame)
142
g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
143
g_return_if_fail (proc_frame != NULL);
145
for (list = proc_frame->cleanups; list; list = g_list_next (list))
147
GimpPlugInCleanupImage *cleanup = list->data;
148
GimpImage *image = cleanup->image;
150
if (! gimp_container_have (plug_in->manager->gimp->images,
151
(GimpObject *) image))
154
if (image->pushing_undo_group == GIMP_UNDO_GROUP_NONE)
157
g_printerr ("\n%s: checking image with group count %d\n",
158
G_STRFUNC, image->group_count);
160
if (cleanup->undo_group_count != image->group_count)
162
GimpProcedure *proc = proc_frame->procedure;
164
g_message ("Plug-In '%s' left image undo in inconsistent state, "
165
"closing open undo groups.",
166
gimp_plug_in_procedure_get_label (GIMP_PLUG_IN_PROCEDURE (proc)));
168
while (image->pushing_undo_group != GIMP_UNDO_GROUP_NONE &&
169
cleanup->undo_group_count < image->group_count)
171
if (! gimp_image_undo_group_end (image))
179
g_list_free (proc_frame->cleanups);
180
proc_frame->cleanups = NULL;
184
/* private functions */
186
static GimpPlugInCleanupImage *
187
gimp_plug_in_cleanup_get_image (GimpPlugInProcFrame *proc_frame,
192
for (list = proc_frame->cleanups; list; list = g_list_next (list))
194
GimpPlugInCleanupImage *cleanup = list->data;
196
if (cleanup->image == image)