24
24
#include <glib-object.h>
26
26
#include "pdb-types.h"
27
#include "procedural_db.h"
28
#include "gimpprocedure.h"
29
#include "core/gimpparamspecs.h"
29
31
#include "core/gimp.h"
30
32
#include "core/gimpimage-undo.h"
31
33
#include "core/gimpimage.h"
32
#include "plug-in/plug-in.h"
34
static ProcRecord image_undo_group_start_proc;
35
static ProcRecord image_undo_group_end_proc;
36
static ProcRecord image_undo_is_enabled_proc;
37
static ProcRecord image_undo_disable_proc;
38
static ProcRecord image_undo_enable_proc;
39
static ProcRecord image_undo_freeze_proc;
40
static ProcRecord image_undo_thaw_proc;
34
#include "plug-in/gimpplugin-cleanup.h"
35
#include "plug-in/gimpplugin.h"
36
#include "plug-in/gimppluginmanager.h"
38
#include "internal_procs.h"
42
image_undo_group_start_invoker (GimpProcedure *procedure,
45
GimpProgress *progress,
46
const GValueArray *args)
48
gboolean success = TRUE;
51
image = gimp_value_get_image (&args->values[0], gimp);
55
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
56
const gchar *undo_desc = NULL;
60
success = gimp_plug_in_cleanup_undo_group_start (plug_in, image);
63
undo_desc = gimp_plug_in_get_undo_desc (plug_in);
67
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_MISC, undo_desc);
70
return gimp_procedure_get_return_values (procedure, success);
74
image_undo_group_end_invoker (GimpProcedure *procedure,
77
GimpProgress *progress,
78
const GValueArray *args)
80
gboolean success = TRUE;
83
image = gimp_value_get_image (&args->values[0], gimp);
87
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
90
success = gimp_plug_in_cleanup_undo_group_end (plug_in, image);
93
gimp_image_undo_group_end (image);
96
return gimp_procedure_get_return_values (procedure, success);
100
image_undo_is_enabled_invoker (GimpProcedure *procedure,
102
GimpContext *context,
103
GimpProgress *progress,
104
const GValueArray *args)
106
gboolean success = TRUE;
107
GValueArray *return_vals;
109
gboolean enabled = FALSE;
111
image = gimp_value_get_image (&args->values[0], gimp);
115
enabled = gimp_image_undo_is_enabled (image);
118
return_vals = gimp_procedure_get_return_values (procedure, success);
121
g_value_set_boolean (&return_vals->values[1], enabled);
127
image_undo_disable_invoker (GimpProcedure *procedure,
129
GimpContext *context,
130
GimpProgress *progress,
131
const GValueArray *args)
133
gboolean success = TRUE;
134
GValueArray *return_vals;
136
gboolean disabled = FALSE;
138
image = gimp_value_get_image (&args->values[0], gimp);
143
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
146
success = gimp_plug_in_cleanup_undo_disable (plug_in, image);
150
disabled = gimp_image_undo_disable (image);
153
return_vals = gimp_procedure_get_return_values (procedure, success);
156
g_value_set_boolean (&return_vals->values[1], disabled);
162
image_undo_enable_invoker (GimpProcedure *procedure,
164
GimpContext *context,
165
GimpProgress *progress,
166
const GValueArray *args)
168
gboolean success = TRUE;
169
GValueArray *return_vals;
171
gboolean enabled = FALSE;
173
image = gimp_value_get_image (&args->values[0], gimp);
178
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
181
success = gimp_plug_in_cleanup_undo_enable (plug_in, image);
185
enabled = gimp_image_undo_enable (image);
188
return_vals = gimp_procedure_get_return_values (procedure, success);
191
g_value_set_boolean (&return_vals->values[1], enabled);
197
image_undo_freeze_invoker (GimpProcedure *procedure,
199
GimpContext *context,
200
GimpProgress *progress,
201
const GValueArray *args)
203
gboolean success = TRUE;
204
GValueArray *return_vals;
206
gboolean frozen = FALSE;
208
image = gimp_value_get_image (&args->values[0], gimp);
213
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
216
success = gimp_plug_in_cleanup_undo_freeze (plug_in, image);
220
frozen = gimp_image_undo_freeze (image);
223
return_vals = gimp_procedure_get_return_values (procedure, success);
226
g_value_set_boolean (&return_vals->values[1], frozen);
232
image_undo_thaw_invoker (GimpProcedure *procedure,
234
GimpContext *context,
235
GimpProgress *progress,
236
const GValueArray *args)
238
gboolean success = TRUE;
239
GValueArray *return_vals;
241
gboolean thawed = FALSE;
243
image = gimp_value_get_image (&args->values[0], gimp);
248
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
251
success = gimp_plug_in_cleanup_undo_thaw (plug_in, image);
255
thawed = gimp_image_undo_thaw (image);
258
return_vals = gimp_procedure_get_return_values (procedure, success);
261
g_value_set_boolean (&return_vals->values[1], thawed);
43
register_undo_procs (Gimp *gimp)
45
procedural_db_register (gimp, &image_undo_group_start_proc);
46
procedural_db_register (gimp, &image_undo_group_end_proc);
47
procedural_db_register (gimp, &image_undo_is_enabled_proc);
48
procedural_db_register (gimp, &image_undo_disable_proc);
49
procedural_db_register (gimp, &image_undo_enable_proc);
50
procedural_db_register (gimp, &image_undo_freeze_proc);
51
procedural_db_register (gimp, &image_undo_thaw_proc);
55
image_undo_group_start_invoker (Gimp *gimp,
57
GimpProgress *progress,
60
gboolean success = TRUE;
62
gchar *undo_desc = NULL;
64
gimage = gimp_image_get_by_ID (gimp, args[0].value.pdb_int);
65
if (! GIMP_IS_IMAGE (gimage))
70
if (gimp->current_plug_in)
71
undo_desc = plug_in_get_undo_desc (gimp->current_plug_in);
73
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_MISC, undo_desc);
79
return procedural_db_return_args (&image_undo_group_start_proc, success);
82
static ProcArg image_undo_group_start_inargs[] =
87
"The ID of the image in which to open an undo group"
91
static ProcRecord image_undo_group_start_proc =
93
"gimp_image_undo_group_start",
94
"Starts a group undo.",
95
"This function is used to start a group undo--necessary for logically combining two or more undo operations into a single operation. This call must be used in conjunction with a 'gimp-image-undo-group-end' call.",
96
"Spencer Kimball & Peter Mattis",
97
"Spencer Kimball & Peter Mattis",
102
image_undo_group_start_inargs,
105
{ { image_undo_group_start_invoker } }
109
image_undo_group_end_invoker (Gimp *gimp,
110
GimpContext *context,
111
GimpProgress *progress,
114
gboolean success = TRUE;
117
gimage = gimp_image_get_by_ID (gimp, args[0].value.pdb_int);
118
if (! GIMP_IS_IMAGE (gimage))
122
gimp_image_undo_group_end (gimage);
124
return procedural_db_return_args (&image_undo_group_end_proc, success);
127
static ProcArg image_undo_group_end_inargs[] =
132
"The ID of the image in which to close an undo group"
136
static ProcRecord image_undo_group_end_proc =
138
"gimp_image_undo_group_end",
139
"Finish a group undo.",
140
"This function must be called once for each 'gimp-image-undo-group-start' call that is made.",
141
"Spencer Kimball & Peter Mattis",
142
"Spencer Kimball & Peter Mattis",
147
image_undo_group_end_inargs,
150
{ { image_undo_group_end_invoker } }
154
image_undo_is_enabled_invoker (Gimp *gimp,
155
GimpContext *context,
156
GimpProgress *progress,
159
gboolean success = TRUE;
160
Argument *return_args;
162
gboolean enabled = FALSE;
164
gimage = gimp_image_get_by_ID (gimp, args[0].value.pdb_int);
165
if (! GIMP_IS_IMAGE (gimage))
169
enabled = gimp_image_undo_is_enabled (gimage);
171
return_args = procedural_db_return_args (&image_undo_is_enabled_proc, success);
174
return_args[1].value.pdb_int = enabled;
179
static ProcArg image_undo_is_enabled_inargs[] =
188
static ProcArg image_undo_is_enabled_outargs[] =
193
"True if undo is enabled for this image"
197
static ProcRecord image_undo_is_enabled_proc =
199
"gimp_image_undo_is_enabled",
200
"Check if the image's undo stack is enabled.",
201
"This procedure checks if the image's undo stack is currently enabled or disabled. This is useful when several plugins or scripts call each other and want to check if their caller has already used 'gimp_image_undo_disable' or 'gimp_image_undo_freeze'.",
208
image_undo_is_enabled_inargs,
210
image_undo_is_enabled_outargs,
211
{ { image_undo_is_enabled_invoker } }
215
image_undo_disable_invoker (Gimp *gimp,
216
GimpContext *context,
217
GimpProgress *progress,
220
gboolean success = TRUE;
221
Argument *return_args;
224
gimage = gimp_image_get_by_ID (gimp, args[0].value.pdb_int);
225
if (! GIMP_IS_IMAGE (gimage))
229
success = gimp_image_undo_disable (gimage);
231
return_args = procedural_db_return_args (&image_undo_disable_proc, success);
234
return_args[1].value.pdb_int = success ? TRUE : FALSE;
239
static ProcArg image_undo_disable_inargs[] =
248
static ProcArg image_undo_disable_outargs[] =
253
"True if the image undo has been disabled"
257
static ProcRecord image_undo_disable_proc =
259
"gimp_image_undo_disable",
260
"Disable the image's undo stack.",
261
"This procedure disables the image's undo stack, allowing subsequent operations to ignore their undo steps. This is generally called in conjunction with 'gimp_image_undo_enable' to temporarily disable an image undo stack. This is advantageous because saving undo steps can be time and memory intensive.",
262
"Spencer Kimball & Peter Mattis",
263
"Spencer Kimball & Peter Mattis",
268
image_undo_disable_inargs,
270
image_undo_disable_outargs,
271
{ { image_undo_disable_invoker } }
275
image_undo_enable_invoker (Gimp *gimp,
276
GimpContext *context,
277
GimpProgress *progress,
280
gboolean success = TRUE;
281
Argument *return_args;
284
gimage = gimp_image_get_by_ID (gimp, args[0].value.pdb_int);
285
if (! GIMP_IS_IMAGE (gimage))
289
success = gimp_image_undo_enable (gimage);
291
return_args = procedural_db_return_args (&image_undo_enable_proc, success);
294
return_args[1].value.pdb_int = success ? TRUE : FALSE;
299
static ProcArg image_undo_enable_inargs[] =
308
static ProcArg image_undo_enable_outargs[] =
313
"True if the image undo has been enabled"
317
static ProcRecord image_undo_enable_proc =
319
"gimp_image_undo_enable",
320
"Enable the image's undo stack.",
321
"This procedure enables the image's undo stack, allowing subsequent operations to store their undo steps. This is generally called in conjunction with 'gimp_image_undo_disable' to temporarily disable an image undo stack.",
322
"Spencer Kimball & Peter Mattis",
323
"Spencer Kimball & Peter Mattis",
328
image_undo_enable_inargs,
330
image_undo_enable_outargs,
331
{ { image_undo_enable_invoker } }
335
image_undo_freeze_invoker (Gimp *gimp,
336
GimpContext *context,
337
GimpProgress *progress,
340
gboolean success = TRUE;
341
Argument *return_args;
344
gimage = gimp_image_get_by_ID (gimp, args[0].value.pdb_int);
345
if (! GIMP_IS_IMAGE (gimage))
349
success = gimp_image_undo_freeze (gimage);
351
return_args = procedural_db_return_args (&image_undo_freeze_proc, success);
354
return_args[1].value.pdb_int = success ? TRUE : FALSE;
359
static ProcArg image_undo_freeze_inargs[] =
368
static ProcArg image_undo_freeze_outargs[] =
373
"True if the image undo has been frozen"
377
static ProcRecord image_undo_freeze_proc =
379
"gimp_image_undo_freeze",
380
"Freeze the image's undo stack.",
381
"This procedure freezes the image's undo stack, allowing subsequent operations to ignore their undo steps. This is generally called in conjunction with 'gimp_image_undo_thaw' to temporarily disable an image undo stack. This is advantageous because saving undo steps can be time and memory intensive. 'gimp_image_undo_{freeze,thaw}' and 'gimp_image_undo_{disable,enable}' differ in that the former does not free up all undo steps when undo is thawed, so is more suited to interactive in-situ previews. It is important in this case that the image is back to the same state it was frozen in before thawing, else 'undo' behaviour is undefined.",
388
image_undo_freeze_inargs,
390
image_undo_freeze_outargs,
391
{ { image_undo_freeze_invoker } }
395
image_undo_thaw_invoker (Gimp *gimp,
396
GimpContext *context,
397
GimpProgress *progress,
400
gboolean success = TRUE;
401
Argument *return_args;
404
gimage = gimp_image_get_by_ID (gimp, args[0].value.pdb_int);
405
if (! GIMP_IS_IMAGE (gimage))
409
success = gimp_image_undo_thaw (gimage);
411
return_args = procedural_db_return_args (&image_undo_thaw_proc, success);
414
return_args[1].value.pdb_int = success ? TRUE : FALSE;
419
static ProcArg image_undo_thaw_inargs[] =
428
static ProcArg image_undo_thaw_outargs[] =
433
"True if the image undo has been thawed"
437
static ProcRecord image_undo_thaw_proc =
439
"gimp_image_undo_thaw",
440
"Thaw the image's undo stack.",
441
"This procedure thaws the image's undo stack, allowing subsequent operations to store their undo steps. This is generally called in conjunction with 'gimp_image_undo_freeze' to temporarily freeze an image undo stack. 'gimp_image_undo_thaw' does NOT free the undo stack as 'gimp_image_undo_enable' does, so is suited for situations where one wishes to leave the undo stack in the same state in which one found it despite non-destructively playing with the image in the meantime. An example would be in-situ plugin previews. Balancing freezes and thaws and ensuring image consistancy is the responsibility of the caller.",
448
image_undo_thaw_inargs,
450
image_undo_thaw_outargs,
451
{ { image_undo_thaw_invoker } }
267
register_undo_procs (GimpPDB *pdb)
269
GimpProcedure *procedure;
272
* gimp-image-undo-group-start
274
procedure = gimp_procedure_new (image_undo_group_start_invoker);
275
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-image-undo-group-start");
276
gimp_procedure_set_static_strings (procedure,
277
"gimp-image-undo-group-start",
278
"Starts a group undo.",
279
"This function is used to start a group undo--necessary for logically combining two or more undo operations into a single operation. This call must be used in conjunction with a 'gimp-image-undo-group-end' call.",
280
"Spencer Kimball & Peter Mattis",
281
"Spencer Kimball & Peter Mattis",
284
gimp_procedure_add_argument (procedure,
285
gimp_param_spec_image_id ("image",
287
"The ID of the image in which to open an undo group",
289
GIMP_PARAM_READWRITE));
290
gimp_pdb_register_procedure (pdb, procedure);
291
g_object_unref (procedure);
294
* gimp-image-undo-group-end
296
procedure = gimp_procedure_new (image_undo_group_end_invoker);
297
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-image-undo-group-end");
298
gimp_procedure_set_static_strings (procedure,
299
"gimp-image-undo-group-end",
300
"Finish a group undo.",
301
"This function must be called once for each 'gimp-image-undo-group-start' call that is made.",
302
"Spencer Kimball & Peter Mattis",
303
"Spencer Kimball & Peter Mattis",
306
gimp_procedure_add_argument (procedure,
307
gimp_param_spec_image_id ("image",
309
"The ID of the image in which to close an undo group",
311
GIMP_PARAM_READWRITE));
312
gimp_pdb_register_procedure (pdb, procedure);
313
g_object_unref (procedure);
316
* gimp-image-undo-is-enabled
318
procedure = gimp_procedure_new (image_undo_is_enabled_invoker);
319
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-image-undo-is-enabled");
320
gimp_procedure_set_static_strings (procedure,
321
"gimp-image-undo-is-enabled",
322
"Check if the image's undo stack is enabled.",
323
"This procedure checks if the image's undo stack is currently enabled or disabled. This is useful when several plugins or scripts call each other and want to check if their caller has already used 'gimp-image-undo-disable' or 'gimp-image-undo-freeze'.",
324
"Rapha\xc3\xabl Quinet <raphael@gimp.org>",
325
"Rapha\xc3\xabl Quinet",
328
gimp_procedure_add_argument (procedure,
329
gimp_param_spec_image_id ("image",
333
GIMP_PARAM_READWRITE));
334
gimp_procedure_add_return_value (procedure,
335
g_param_spec_boolean ("enabled",
337
"TRUE if undo is enabled for this image",
339
GIMP_PARAM_READWRITE));
340
gimp_pdb_register_procedure (pdb, procedure);
341
g_object_unref (procedure);
344
* gimp-image-undo-disable
346
procedure = gimp_procedure_new (image_undo_disable_invoker);
347
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-image-undo-disable");
348
gimp_procedure_set_static_strings (procedure,
349
"gimp-image-undo-disable",
350
"Disable the image's undo stack.",
351
"This procedure disables the image's undo stack, allowing subsequent operations to ignore their undo steps. This is generally called in conjunction with 'gimp-image-undo-enable' to temporarily disable an image undo stack. This is advantageous because saving undo steps can be time and memory intensive.",
352
"Spencer Kimball & Peter Mattis",
353
"Spencer Kimball & Peter Mattis",
356
gimp_procedure_add_argument (procedure,
357
gimp_param_spec_image_id ("image",
361
GIMP_PARAM_READWRITE));
362
gimp_procedure_add_return_value (procedure,
363
g_param_spec_boolean ("disabled",
365
"TRUE if the image undo has been disabled",
367
GIMP_PARAM_READWRITE));
368
gimp_pdb_register_procedure (pdb, procedure);
369
g_object_unref (procedure);
372
* gimp-image-undo-enable
374
procedure = gimp_procedure_new (image_undo_enable_invoker);
375
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-image-undo-enable");
376
gimp_procedure_set_static_strings (procedure,
377
"gimp-image-undo-enable",
378
"Enable the image's undo stack.",
379
"This procedure enables the image's undo stack, allowing subsequent operations to store their undo steps. This is generally called in conjunction with 'gimp-image-undo-disable' to temporarily disable an image undo stack.",
380
"Spencer Kimball & Peter Mattis",
381
"Spencer Kimball & Peter Mattis",
384
gimp_procedure_add_argument (procedure,
385
gimp_param_spec_image_id ("image",
389
GIMP_PARAM_READWRITE));
390
gimp_procedure_add_return_value (procedure,
391
g_param_spec_boolean ("enabled",
393
"TRUE if the image undo has been enabled",
395
GIMP_PARAM_READWRITE));
396
gimp_pdb_register_procedure (pdb, procedure);
397
g_object_unref (procedure);
400
* gimp-image-undo-freeze
402
procedure = gimp_procedure_new (image_undo_freeze_invoker);
403
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-image-undo-freeze");
404
gimp_procedure_set_static_strings (procedure,
405
"gimp-image-undo-freeze",
406
"Freeze the image's undo stack.",
407
"This procedure freezes the image's undo stack, allowing subsequent operations to ignore their undo steps. This is generally called in conjunction with 'gimp-image-undo-thaw' to temporarily disable an image undo stack. This is advantageous because saving undo steps can be time and memory intensive. 'gimp-image-undo-freeze' / 'gimp-image-undo-thaw' and 'gimp-image-undo-disable' / 'gimp-image-undo-enable' differ in that the former does not free up all undo steps when undo is thawed, so is more suited to interactive in-situ previews. It is important in this case that the image is back to the same state it was frozen in before thawing, else 'undo' behaviour is undefined.",
412
gimp_procedure_add_argument (procedure,
413
gimp_param_spec_image_id ("image",
417
GIMP_PARAM_READWRITE));
418
gimp_procedure_add_return_value (procedure,
419
g_param_spec_boolean ("frozen",
421
"TRUE if the image undo has been frozen",
423
GIMP_PARAM_READWRITE));
424
gimp_pdb_register_procedure (pdb, procedure);
425
g_object_unref (procedure);
428
* gimp-image-undo-thaw
430
procedure = gimp_procedure_new (image_undo_thaw_invoker);
431
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-image-undo-thaw");
432
gimp_procedure_set_static_strings (procedure,
433
"gimp-image-undo-thaw",
434
"Thaw the image's undo stack.",
435
"This procedure thaws the image's undo stack, allowing subsequent operations to store their undo steps. This is generally called in conjunction with 'gimp-image-undo-freeze' to temporarily freeze an image undo stack. 'gimp-image-undo-thaw' does NOT free the undo stack as 'gimp-image-undo-enable' does, so is suited for situations where one wishes to leave the undo stack in the same state in which one found it despite non-destructively playing with the image in the meantime. An example would be in-situ plugin previews. Balancing freezes and thaws and ensuring image consistancy is the responsibility of the caller.",
440
gimp_procedure_add_argument (procedure,
441
gimp_param_spec_image_id ("image",
445
GIMP_PARAM_READWRITE));
446
gimp_procedure_add_return_value (procedure,
447
g_param_spec_boolean ("thawed",
449
"TRUE if the image undo has been thawed",
451
GIMP_PARAM_READWRITE));
452
gimp_pdb_register_procedure (pdb, procedure);
453
g_object_unref (procedure);