libgimp: add a "status" parameter to gimp_procedure_config_end_run()

and require it to be always called paired with begin_run(), which is
more straightforward and makes the resulting code more future-proof.
This commit is contained in:
Michael Natterer 2019-09-25 12:09:03 +02:00
parent 1793a08548
commit 58bf1d431d
8 changed files with 20 additions and 32 deletions

View File

@ -380,11 +380,11 @@ gimp_procedure_config_begin_run (GimpProcedureConfig *config,
* @config: a #GimpProcedureConfig
* @image: a #GimpImage or %NULL
* @run_mode: the #GimpRunMode passed to a #GimpProcedure's run()
* @status: the return status of the #GimpProcedure's run()
*
* This function is the counterpart of
* gimp_procedure_conig_begin_run() and should be used upon successful
* completion of a procedure's run(), before returning
* %GIMP_PDB_SUCCESS return values.
* gimp_procedure_conig_begin_run() and must always be called in pairs
* in a procedure's run(), before returning return values.
*
* If @run_mode is %GIMP_RUN_INTERACTIVE, @config is saved as last
* used values to be used when the procedure runs again. Additionally,
@ -403,7 +403,8 @@ gimp_procedure_config_begin_run (GimpProcedureConfig *config,
void
gimp_procedure_config_end_run (GimpProcedureConfig *config,
GimpImage *image,
GimpRunMode run_mode)
GimpRunMode run_mode,
GimpPDBStatusType status)
{
g_return_if_fail (GIMP_IS_PROCEDURE_CONFIG (config));
g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
@ -411,7 +412,8 @@ gimp_procedure_config_end_run (GimpProcedureConfig *config,
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush ();
if (run_mode == GIMP_RUN_INTERACTIVE)
if (status == GIMP_PDB_SUCCESS &&
run_mode == GIMP_RUN_INTERACTIVE)
{
GError *error = NULL;

View File

@ -81,7 +81,8 @@ void gimp_procedure_config_begin_run (GimpProcedureConfig *config,
const GimpValueArray *args);
void gimp_procedure_config_end_run (GimpProcedureConfig *config,
GimpImage *image,
GimpRunMode run_mode);
GimpRunMode run_mode,
GimpPDBStatusType status);
G_END_DECLS

View File

@ -252,7 +252,7 @@ despeckle_run (GimpProcedure *procedure,
despeckle (drawable, G_OBJECT (config));
gimp_procedure_config_end_run (config, NULL, run_mode);
gimp_procedure_config_end_run (config, NULL, run_mode, GIMP_PDB_SUCCESS);
g_object_unref (config);
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);

View File

@ -226,10 +226,7 @@ gbr_save (GimpProcedure *procedure,
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (procedure, G_OBJECT (config)))
{
status = GIMP_PDB_CANCEL;
goto out;
}
status = GIMP_PDB_CANCEL;
}
if (status == GIMP_PDB_SUCCESS)
@ -255,11 +252,7 @@ gbr_save (GimpProcedure *procedure,
g_free (description);
if (GIMP_VALUES_GET_ENUM (save_retvals, 0) == GIMP_PDB_SUCCESS)
{
gimp_procedure_config_end_run (config, orig_image, run_mode);
}
else
if (GIMP_VALUES_GET_ENUM (save_retvals, 0) != GIMP_PDB_SUCCESS)
{
g_set_error (&error, 0, 0,
"Running procedure 'file-gbr-save-internal' "
@ -272,7 +265,7 @@ gbr_save (GimpProcedure *procedure,
gimp_value_array_unref (save_retvals);
}
out:
gimp_procedure_config_end_run (config, orig_image, run_mode, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)

View File

@ -310,8 +310,6 @@ heif_save (GimpProcedure *procedure,
file, NULL);
g_object_unref (metadata);
}
gimp_procedure_config_end_run (config, orig_image, run_mode);
}
else
{
@ -319,6 +317,7 @@ heif_save (GimpProcedure *procedure,
}
}
gimp_procedure_config_end_run (config, orig_image, run_mode, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)

View File

@ -225,11 +225,7 @@ pat_save (GimpProcedure *procedure,
G_TYPE_STRING, description,
G_TYPE_NONE);
if (GIMP_VALUES_GET_ENUM (save_retvals, 0) == GIMP_PDB_SUCCESS)
{
gimp_procedure_config_end_run (config, orig_image, run_mode);
}
else
if (GIMP_VALUES_GET_ENUM (save_retvals, 0) != GIMP_PDB_SUCCESS)
{
g_set_error (&error, 0, 0,
"Running procedure 'file-pat-save-internal' "
@ -242,6 +238,7 @@ pat_save (GimpProcedure *procedure,
gimp_value_array_unref (save_retvals);
}
gimp_procedure_config_end_run (config, orig_image, run_mode, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)

View File

@ -543,8 +543,6 @@ png_save (GimpProcedure *procedure,
g_object_unref (metadata);
}
gimp_procedure_config_end_run (config, orig_image, run_mode);
}
else
{
@ -552,6 +550,7 @@ png_save (GimpProcedure *procedure,
}
}
gimp_procedure_config_end_run (config, orig_image, run_mode, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)

View File

@ -274,17 +274,14 @@ sgi_save (GimpProcedure *procedure,
if (status == GIMP_PDB_SUCCESS)
{
if (save_image (file, image, drawable, G_OBJECT (config),
&error))
{
gimp_procedure_config_end_run (config, orig_image, run_mode);
}
else
if (! save_image (file, image, drawable, G_OBJECT (config),
&error))
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
gimp_procedure_config_end_run (config, orig_image, run_mode, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)