diff --git a/app/pdb/image-undo-cmds.c b/app/pdb/image-undo-cmds.c index 51ae7e5c83..821a3cf114 100644 --- a/app/pdb/image-undo-cmds.c +++ b/app/pdb/image-undo-cmds.c @@ -281,6 +281,70 @@ image_undo_thaw_invoker (GimpProcedure *procedure, return return_vals; } +static GimpValueArray * +image_undo_undo_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpValueArray *return_vals; + GimpImage *image; + gboolean undone = FALSE; + + image = g_value_get_object (gimp_value_array_index (args, 0)); + + if (success) + { + if (success && gimp_image_undo_is_enabled (image)) + undone = gimp_image_undo (image); + else + undone = FALSE; + } + + return_vals = gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); + + if (success) + g_value_set_boolean (gimp_value_array_index (return_vals, 1), undone); + + return return_vals; +} + +static GimpValueArray * +image_undo_redo_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpValueArray *return_vals; + GimpImage *image; + gboolean redone = FALSE; + + image = g_value_get_object (gimp_value_array_index (args, 0)); + + if (success) + { + if (success && gimp_image_undo_is_enabled (image)) + redone = gimp_image_redo (image); + else + redone = FALSE; + } + + return_vals = gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); + + if (success) + g_value_set_boolean (gimp_value_array_index (return_vals, 1), redone); + + return return_vals; +} + void register_image_undo_procs (GimpPDB *pdb) { @@ -476,4 +540,62 @@ register_image_undo_procs (GimpPDB *pdb) GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + + /* + * gimp-image-undo-undo + */ + procedure = gimp_procedure_new (image_undo_undo_invoker, FALSE); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-image-undo-undo"); + gimp_procedure_set_static_help (procedure, + "Undo the last change applied on the image.", + "This procedure reverts the last change applied to the image. It will not run if the undo stack is not enabled.", + NULL); + gimp_procedure_set_static_attribution (procedure, + "Spencer Kimball & Peter Mattis", + "Spencer Kimball & Peter Mattis", + "1995-1996"); + gimp_procedure_add_argument (procedure, + gimp_param_spec_image ("image", + "image", + "The image", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + g_param_spec_boolean ("undone", + "undone", + "TRUE if the last change was undone", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + + /* + * gimp-image-undo-redo + */ + procedure = gimp_procedure_new (image_undo_redo_invoker, FALSE); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-image-undo-redo"); + gimp_procedure_set_static_help (procedure, + "Restore the last change applied on the image.", + "This procedure restores the last change applied to the image. It will not run if the undo stack is not enabled.", + NULL); + gimp_procedure_set_static_attribution (procedure, + "Spencer Kimball & Peter Mattis", + "Spencer Kimball & Peter Mattis", + "1995-1996"); + gimp_procedure_add_argument (procedure, + gimp_param_spec_image ("image", + "image", + "The image", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + g_param_spec_boolean ("redone", + "redone", + "TRUE if the last change was restored", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); } diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index 704577eca0..f4c05e4505 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -30,7 +30,7 @@ #include "internal-procs.h" -/* 718 procedures registered total */ +/* 720 procedures registered total */ void internal_procs_init (GimpPDB *pdb) diff --git a/libgimp/gimp.def b/libgimp/gimp.def index 7ca810869a..93510b3924 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -568,7 +568,9 @@ EXPORTS gimp_image_undo_group_end gimp_image_undo_group_start gimp_image_undo_is_enabled + gimp_image_undo_redo gimp_image_undo_thaw + gimp_image_undo_undo gimp_image_unset_active_channel gimp_item_attach_parasite gimp_item_delete diff --git a/libgimp/gimpimageundo_pdb.c b/libgimp/gimpimageundo_pdb.c index 83b727369e..7596a0f01f 100644 --- a/libgimp/gimpimageundo_pdb.c +++ b/libgimp/gimpimageundo_pdb.c @@ -304,3 +304,73 @@ gimp_image_undo_thaw (GimpImage *image) return thawed; } + +/** + * gimp_image_undo_undo: + * @image: The image. + * + * Undo the last change applied on the image. + * + * This procedure reverts the last change applied to the image. It will + * not run if the undo stack is not enabled. + * + * Returns: TRUE if the last change was undone. + **/ +gboolean +gimp_image_undo_undo (GimpImage *image) +{ + GimpValueArray *args; + GimpValueArray *return_vals; + gboolean undone = FALSE; + + args = gimp_value_array_new_from_types (NULL, + GIMP_TYPE_IMAGE, image, + G_TYPE_NONE); + + return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), + "gimp-image-undo-undo", + args); + gimp_value_array_unref (args); + + if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) + undone = GIMP_VALUES_GET_BOOLEAN (return_vals, 1); + + gimp_value_array_unref (return_vals); + + return undone; +} + +/** + * gimp_image_undo_redo: + * @image: The image. + * + * Restore the last change applied on the image. + * + * This procedure restores the last change applied to the image. It + * will not run if the undo stack is not enabled. + * + * Returns: TRUE if the last change was restored. + **/ +gboolean +gimp_image_undo_redo (GimpImage *image) +{ + GimpValueArray *args; + GimpValueArray *return_vals; + gboolean redone = FALSE; + + args = gimp_value_array_new_from_types (NULL, + GIMP_TYPE_IMAGE, image, + G_TYPE_NONE); + + return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), + "gimp-image-undo-redo", + args); + gimp_value_array_unref (args); + + if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) + redone = GIMP_VALUES_GET_BOOLEAN (return_vals, 1); + + gimp_value_array_unref (return_vals); + + return redone; +} diff --git a/libgimp/gimpimageundo_pdb.h b/libgimp/gimpimageundo_pdb.h index 3caa0f2227..d2ace44547 100644 --- a/libgimp/gimpimageundo_pdb.h +++ b/libgimp/gimpimageundo_pdb.h @@ -39,6 +39,8 @@ gboolean gimp_image_undo_disable (GimpImage *image); gboolean gimp_image_undo_enable (GimpImage *image); gboolean gimp_image_undo_freeze (GimpImage *image); gboolean gimp_image_undo_thaw (GimpImage *image); +gboolean gimp_image_undo_undo (GimpImage *image); +gboolean gimp_image_undo_redo (GimpImage *image); G_END_DECLS diff --git a/pdb/groups/image_undo.pdb b/pdb/groups/image_undo.pdb index e19d31573d..377d66e8f6 100644 --- a/pdb/groups/image_undo.pdb +++ b/pdb/groups/image_undo.pdb @@ -284,6 +284,70 @@ CODE ); } +sub image_undo_undo { + $blurb = "Undo the last change applied on the image."; + + $help = <<'HELP'; +This procedure reverts the last change applied to the image. +It will not run if the undo stack is not enabled. +HELP + + &std_pdb_misc; + + @inargs = ( + { name => 'image', type => 'image', + desc => 'The image' } + ); + + @outargs = ( + { name => 'undone', type => 'boolean', + desc => 'TRUE if the last change was undone' } + ); + + %invoke = ( + code => <<'CODE' +{ + if (success && gimp_image_undo_is_enabled (image)) + undone = gimp_image_undo (image); + else + undone = FALSE; +} +CODE + ); +} + +sub image_undo_redo { + $blurb = "Restore the last change applied on the image."; + + $help = <<'HELP'; +This procedure restores the last change applied to the image. +It will not run if the undo stack is not enabled. +HELP + + &std_pdb_misc; + + @inargs = ( + { name => 'image', type => 'image', + desc => 'The image' } + ); + + @outargs = ( + { name => 'redone', type => 'boolean', + desc => 'TRUE if the last change was restored' } + ); + + %invoke = ( + code => <<'CODE' +{ + if (success && gimp_image_undo_is_enabled (image)) + redone = gimp_image_redo (image); + else + redone = FALSE; +} +CODE + ); +} + @headers = qw("core/gimp.h" "core/gimpimage-undo.h" @@ -294,7 +358,8 @@ CODE @procs = qw(image_undo_group_start image_undo_group_end image_undo_is_enabled image_undo_disable image_undo_enable - image_undo_freeze image_undo_thaw); + image_undo_freeze image_undo_thaw + image_undo_undo image_undo_redo); %exports = (app => [@procs], lib => [@procs]);