Files
gimp/app/actions/plug-in-commands.c
Michael Natterer 49da8cb2d1 added gimp_procedure_new() and gimp_procedure_free() functions.
2006-03-31  Michael Natterer  <mitch@gimp.org>

	* app/pdb/gimpprocedure.[ch]: added gimp_procedure_new() and
	gimp_procedure_free() functions.

	* app/plug-in/plug-in-proc-def.h (struct PlugInProcDef): use a
	ProcRecord pointer instead of including the entire struct.

	* app/plug-in/plug-in-proc-def.c: use the new() and free()
	functions above to allocate/free the ProcRecord.

	* app/actions/plug-in-actions.c
	* app/actions/plug-in-commands.c
	* app/menus/plug-in-menus.c
	* app/plug-in/plug-in-message.c
	* app/plug-in/plug-in-rc.c
	* app/plug-in/plug-in-run.c
	* app/plug-in/plug-in.c
	* app/plug-in/plug-ins-query.c
	* app/plug-in/plug-ins.c
	* app/xcf/xcf.c: changed accordingly.

	Unrelated:

	* app/pdb/gimpprocedure.c (gimp_procedure_execute): be more verbose
	when warning about out-of-bounds parameter values.

	* tools/pdbgen/pdb/fileops.pdb: allow GIMP_RUN_WITH_LAST_VALS for
	file_save because indirect saving (e.g. remote or compressed)
	needs it.

	* app/pdb/fileops_cmds.c: regenerated.
2006-03-31 11:49:22 +00:00

228 lines
6.4 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h"
#include "core/gimp.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpitem.h"
#include "core/gimpparamspecs.h"
#include "core/gimpprogress.h"
#include "plug-in/plug-in-data.h"
#include "plug-in/plug-in-run.h"
#include "plug-in/plug-in-proc-def.h"
#include "pdb/gimpprocedure.h"
#include "pdb/procedural_db.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"
#include "display/gimpdisplay.h"
#include "actions.h"
#include "plug-in-commands.h"
#include "gimp-intl.h"
/* local function prototypes */
static void plug_in_reset_all_response (GtkWidget *dialog,
gint response_id,
Gimp *gimp);
/* public functions */
void
plug_in_run_cmd_callback (GtkAction *action,
PlugInProcDef *proc_def,
gpointer data)
{
Gimp *gimp;
ProcRecord *procedure;
Argument *args;
gint n_args = 0;
GimpDisplay *display = NULL;
gimp = action_data_get_gimp (data);
if (! gimp)
return;
procedure = proc_def->procedure;
args = gimp_procedure_get_arguments (procedure);
/* initialize the first argument */
g_value_set_int (&args[n_args].value, GIMP_RUN_INTERACTIVE);
n_args++;
switch (procedure->proc_type)
{
case GIMP_EXTENSION:
break;
case GIMP_PLUGIN:
case GIMP_TEMPORARY:
if (procedure->num_args > n_args &&
procedure->args[n_args].type == GIMP_PDB_IMAGE)
{
display = action_data_get_display (data);
if (display)
{
gimp_value_set_image (&args[n_args].value, display->image);
n_args++;
if (procedure->num_args > n_args &&
procedure->args[n_args].type == GIMP_PDB_DRAWABLE)
{
GimpDrawable *drawable;
drawable = gimp_image_active_drawable (display->image);
if (drawable)
{
gimp_value_set_item (&args[n_args].value,
GIMP_ITEM (drawable));
n_args++;
}
else
{
g_warning ("Uh-oh, no active drawable for the plug-in!");
goto error;
}
}
}
}
break;
default:
g_error ("Unknown procedure type.");
goto error;
}
/* run the plug-in procedure */
plug_in_run (gimp, gimp_get_user_context (gimp),
GIMP_PROGRESS (display),
procedure, args, n_args, FALSE, TRUE,
display ? gimp_display_get_ID (display) : -1);
/* remember only "standard" plug-ins */
if (procedure->proc_type == GIMP_PLUGIN &&
procedure->num_args >= 3 &&
procedure->args[1].type == GIMP_PDB_IMAGE &&
procedure->args[2].type == GIMP_PDB_DRAWABLE)
{
gimp_set_last_plug_in (gimp, proc_def);
}
error:
procedural_db_destroy_args (args, procedure->num_args, TRUE);
}
void
plug_in_repeat_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpDisplay *display;
GimpDrawable *drawable;
gboolean interactive = TRUE;
display = action_data_get_display (data);
if (! display)
return;
drawable = gimp_image_active_drawable (display->image);
if (! drawable)
return;
if (strcmp (gtk_action_get_name (action), "plug-in-repeat") == 0)
interactive = FALSE;
plug_in_repeat (display->image->gimp, value,
gimp_get_user_context (display->image->gimp),
GIMP_PROGRESS (display),
gimp_display_get_ID (display),
gimp_image_get_ID (display->image),
gimp_item_get_ID (GIMP_ITEM (drawable)),
interactive);
}
void
plug_in_reset_all_cmd_callback (GtkAction *action,
gpointer data)
{
Gimp *gimp = action_data_get_gimp (data);
GtkWidget *dialog;
if (! gimp)
return;
dialog = gimp_message_dialog_new (_("Reset all Filters"), GIMP_STOCK_QUESTION,
NULL, 0,
gimp_standard_help_func, NULL,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GIMP_STOCK_RESET, GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
g_signal_connect (dialog, "response",
G_CALLBACK (plug_in_reset_all_response),
gimp);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Do you really want to reset all "
"filters to default values?"));
gtk_widget_show (dialog);
}
/* private functions */
static void
plug_in_reset_all_response (GtkWidget *dialog,
gint response_id,
Gimp *gimp)
{
gtk_widget_destroy (dialog);
if (response_id == GTK_RESPONSE_OK)
plug_in_data_free (gimp);
}