mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 09:23:24 +00:00
Merge branch 'alxsa-undo-redo-pdb' into 'master'
Issue #999: Add PDB to undo/redo actions Closes #999 See merge request GNOME/gimp!2288
This commit is contained in:
commit
cae8a5c9da
6 changed files with 263 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "internal-procs.h"
|
||||
|
||||
|
||||
/* 718 procedures registered total */
|
||||
/* 720 procedures registered total */
|
||||
|
||||
void
|
||||
internal_procs_init (GimpPDB *pdb)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue