if a plug-in or script registered with a DISPLAY argument after the

2007-04-12  Sven Neumann  <sven@gimp.org>

	* app/actions/plug-in-commands.c: if a plug-in or script
	registered with a DISPLAY argument after the run-mode argument,
	then pass the ID of the active display to the script, optionally
	followed by image and drawable IDs.

	* plug-ins/script-fu/scheme-wrapper.c
	* plug-ins/script-fu/script-fu-enums.h
	* plug-ins/script-fu/script-fu-interface.c
	* plug-ins/script-fu/script-fu-scripts.c
	* plug-ins/script-fu/script-fu-types.h: added SF-DISPLAY parameter.

svn path=/trunk/; revision=22241
This commit is contained in:
Sven Neumann 2007-04-12 15:56:57 +00:00 committed by Sven Neumann
parent 328181185a
commit 65f2809545
7 changed files with 161 additions and 50 deletions

View File

@ -1,3 +1,16 @@
2007-04-12 Sven Neumann <sven@gimp.org>
* app/actions/plug-in-commands.c: if a plug-in or script
registered with a DISPLAY argument after the run-mode argument,
then pass the ID of the active display to the script, optionally
followed by image and drawable IDs.
* plug-ins/script-fu/scheme-wrapper.c
* plug-ins/script-fu/script-fu-enums.h
* plug-ins/script-fu/script-fu-interface.c
* plug-ins/script-fu/script-fu-scripts.c
* plug-ins/script-fu/script-fu-types.h: added SF-DISPLAY parameter.
2007-04-12 Sven Neumann <sven@gimp.org>
* plug-ins/sel2path/*.[ch]: updated copyright header.

View File

@ -84,8 +84,8 @@ static gint plug_in_collect_item_args (GtkAction *action,
GParamSpec **pspecs,
GValueArray *args,
gint n_args);
static gint plug_in_collect_drawable_args (GtkAction *action,
GimpImage *image,
static gint plug_in_collect_display_args (GtkAction *action,
GimpDisplay *display,
GParamSpec **pspecs,
GValueArray *args,
gint n_args);
@ -172,11 +172,10 @@ plug_in_run_cmd_callback (GtkAction *action,
{
display = action_data_get_display (data);
n_args = plug_in_collect_drawable_args (action,
display ?
display->image : NULL,
procedure->args,
args, n_args);
n_args = plug_in_collect_display_args (action,
display,
procedure->args,
args, n_args);
}
break;
@ -217,9 +216,9 @@ plug_in_repeat_cmd_callback (GtkAction *action,
g_value_set_int (&args->values[0], run_mode);
n_args = plug_in_collect_drawable_args (action, display->image,
GIMP_PROCEDURE (procedure)->args,
args, 1);
n_args = plug_in_collect_display_args (action, display,
GIMP_PROCEDURE (procedure)->args,
args, 1);
plug_in_procedure_execute (procedure, gimp, display, args, n_args);
@ -243,9 +242,9 @@ plug_in_history_cmd_callback (GtkAction *action,
g_value_set_int (&args->values[0], GIMP_RUN_INTERACTIVE);
n_args = plug_in_collect_drawable_args (action, display->image,
GIMP_PROCEDURE (procedure)->args,
args, 1);
n_args = plug_in_collect_display_args (action, display,
GIMP_PROCEDURE (procedure)->args,
args, 1);
plug_in_procedure_execute (procedure, gimp, display, args, n_args);
@ -401,15 +400,32 @@ plug_in_collect_item_args (GtkAction *action,
}
static gint
plug_in_collect_drawable_args (GtkAction *action,
GimpImage *image,
GParamSpec **pspecs,
GValueArray *args,
gint n_args)
plug_in_collect_display_args (GtkAction *action,
GimpDisplay *display,
GParamSpec **pspecs,
GValueArray *args,
gint n_args)
{
if (args->n_values > n_args &&
GIMP_IS_PARAM_SPEC_DISPLAY_ID (pspecs[n_args]))
{
if (display)
{
gimp_value_set_display (&args->values[n_args], GIMP_OBJECT (display));
n_args++;
}
else
{
g_warning ("Uh-oh, no active display for the plug-in!");
return -1;
}
}
if (args->n_values > n_args &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (pspecs[n_args]))
{
GimpImage *image = display ? display->image : NULL;
if (image)
{
gimp_value_set_image (&args->values[n_args], image);

View File

@ -92,6 +92,7 @@ struct named_constant const script_constants[] =
{ "SF-PALETTE", SF_PALETTE },
{ "SF-TEXT", SF_TEXT },
{ "SF-ENUM", SF_ENUM },
{ "SF-DISPLAY", SF_DISPLAY },
/* For SF-ADJUSTMENT */
{ "SF-SLIDER", SF_SLIDER },

View File

@ -42,7 +42,8 @@ typedef enum
SF_OPTION,
SF_PALETTE,
SF_TEXT,
SF_ENUM
SF_ENUM,
SF_DISPLAY
} SFArgType;
typedef enum

View File

@ -544,6 +544,9 @@ script_fu_interface (SFScript *script,
G_CALLBACK (gimp_int_combo_box_get_active),
&script->arg_values[i].sfa_enum.history);
break;
case SF_DISPLAY:
break;
}
if (widget)
@ -780,6 +783,7 @@ script_fu_ok (SFScript *script)
case SF_LAYER:
case SF_CHANNEL:
case SF_VECTORS:
case SF_DISPLAY:
g_string_append_printf (s, "%d", arg_value->sfa_image);
break;
@ -915,6 +919,7 @@ script_fu_reset (SFScript *script)
case SF_LAYER:
case SF_CHANNEL:
case SF_VECTORS:
case SF_DISPLAY:
break;
case SF_COLOR:

View File

@ -249,8 +249,9 @@ script_fu_add_script (scheme *sc, pointer a)
case SF_LAYER:
case SF_CHANNEL:
case SF_VECTORS:
case SF_DISPLAY:
if (!sc->vptr->is_integer (sc->vptr->pair_car (a)))
return my_err (sc, "script-fu-register: drawable defaults must be integer values");
return my_err (sc, "script-fu-register: default IDs must be integer values");
script->arg_defaults[i].sfa_image =
sc->vptr->ivalue (sc->vptr->pair_car (a));
script->arg_values[i].sfa_image =
@ -283,6 +284,11 @@ script_fu_add_script (scheme *sc, pointer a)
args[i + 1].name = "vectors";
break;
case SF_DISPLAY:
args[i + 1].type = GIMP_PDB_DISPLAY;
args[i + 1].name = "display";
break;
default:
break;
}
@ -592,9 +598,6 @@ script_fu_add_script (scheme *sc, pointer a)
args[i + 1].name = "enum";
args[i + 1].description = script->arg_labels[i];
break;
default:
break;
}
a = sc->vptr->pair_cdr (a);
@ -762,6 +765,73 @@ script_fu_remove_script (gpointer foo G_GNUC_UNUSED,
return FALSE;
}
static gboolean
script_fu_param_init (SFScript *script,
gint nparams,
const GimpParam *params,
SFArgType type,
gint n)
{
if (script->num_args > n && script->arg_types[n] == type && nparams > n + 1)
{
switch (type)
{
case SF_IMAGE:
if (params[n + 1].type == GIMP_PDB_IMAGE)
{
script->arg_values[n].sfa_image = params[n + 1].data.d_image;
return TRUE;
}
break;
case SF_DRAWABLE:
if (params[n + 1].type == GIMP_PDB_DRAWABLE)
{
script->arg_values[n].sfa_drawable = params[n + 1].data.d_drawable;
return TRUE;
}
break;
case SF_LAYER:
if (params[n + 1].type == GIMP_PDB_LAYER)
{
script->arg_values[n].sfa_layer = params[n + 1].data.d_layer;
return TRUE;
}
break;
case SF_CHANNEL:
if (params[n + 1].type == GIMP_PDB_CHANNEL)
{
script->arg_values[n].sfa_channel = params[n + 1].data.d_channel;
return TRUE;
}
break;
case SF_VECTORS:
if (params[n + 1].type == GIMP_PDB_VECTORS)
{
script->arg_values[n].sfa_vectors = params[n + 1].data.d_vectors;
return TRUE;
}
break;
case SF_DISPLAY:
if (params[n + 1].type == GIMP_PDB_DISPLAY)
{
script->arg_values[n].sfa_display = params[n + 1].data.d_display;
return TRUE;
}
break;
default:
break;
}
}
return FALSE;
}
static void
script_fu_script_proc (const gchar *name,
gint nparams,
@ -770,7 +840,7 @@ script_fu_script_proc (const gchar *name,
GimpParam **return_vals)
{
static GimpParam values[1];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpRunMode run_mode;
SFScript *script;
gint min_args = 0;
@ -789,39 +859,46 @@ script_fu_script_proc (const gchar *name,
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
case GIMP_RUN_WITH_LAST_VALS:
if (nparams > 1 && params[1].type == GIMP_PDB_IMAGE &&
script->num_args > 0 && script->arg_types[0] == SF_IMAGE)
/* the first parameter may be a DISPLAY id */
if (script_fu_param_init (script,
nparams, params, SF_DISPLAY, min_args))
{
script->arg_values[0].sfa_image = params[1].data.d_image;
min_args++;
}
if (nparams > 2 && params[2].type == GIMP_PDB_DRAWABLE &&
script->num_args > 1 && script->arg_types[1] == SF_DRAWABLE)
/* an IMAGE id may come first or after the DISPLAY id */
if (script_fu_param_init (script,
nparams, params, SF_IMAGE, min_args))
{
min_args++;
/* and may be followed by a DRAWABLE id */
if (script_fu_param_init (script,
nparams, params, SF_DRAWABLE, min_args))
min_args++;
}
/* the first parameter may be a LAYER id */
if (min_args == 0 &&
script_fu_param_init (script,
nparams, params, SF_LAYER, min_args))
{
script->arg_values[1].sfa_drawable = params[2].data.d_drawable;
min_args++;
}
if (nparams > 2 && params[2].type == GIMP_PDB_LAYER &&
script->num_args > 1 && script->arg_types[1] == SF_LAYER)
/* the first parameter may be a CHANNEL id */
if (min_args == 0 &&
script_fu_param_init (script,
nparams, params, SF_CHANNEL, min_args))
{
script->arg_values[1].sfa_layer = params[2].data.d_layer;
min_args++;
}
if (nparams > 2 && params[2].type == GIMP_PDB_CHANNEL &&
script->num_args > 1 && script->arg_types[1] == SF_CHANNEL)
/* the first parameter may be a VECTORS id */
if (min_args == 0 &&
script_fu_param_init (script,
nparams, params, SF_VECTORS, min_args))
{
script->arg_values[1].sfa_channel = params[2].data.d_channel;
min_args++;
}
if (nparams > 2 && params[2].type == GIMP_PDB_VECTORS &&
script->num_args > 1 && script->arg_types[1] == SF_VECTORS)
{
script->arg_values[1].sfa_vectors = params[2].data.d_vectors;
min_args++;
}
@ -862,6 +939,7 @@ script_fu_script_proc (const gchar *name,
case SF_LAYER:
case SF_CHANNEL:
case SF_VECTORS:
case SF_DISPLAY:
g_string_append_printf (s, "%d", param->data.d_int32);
break;
@ -915,9 +993,6 @@ script_fu_script_proc (const gchar *name,
case SF_ENUM:
g_string_append_printf (s, "%d", param->data.d_int32);
break;
default:
break;
}
}
@ -1011,7 +1086,9 @@ script_fu_free_script (SFScript *script)
case SF_LAYER:
case SF_CHANNEL:
case SF_VECTORS:
case SF_DISPLAY:
case SF_COLOR:
case SF_TOGGLE:
break;
case SF_VALUE:
@ -1064,9 +1141,6 @@ script_fu_free_script (SFScript *script)
case SF_ENUM:
g_free (script->arg_defaults[i].sfa_enum.type_name);
break;
default:
break;
}
}

View File

@ -67,6 +67,7 @@ typedef union
gint32 sfa_layer;
gint32 sfa_channel;
gint32 sfa_vectors;
gint32 sfa_display;
GimpRGB sfa_color;
gint32 sfa_toggle;
gchar *sfa_value;