plug-ins: port script-fu to GimpPlugIn

This probably has some bugs, but worked flawlessly in my tests...
This commit is contained in:
Michael Natterer 2019-08-12 20:11:45 +02:00
parent 85d9a291a2
commit 103a7e4fc3
15 changed files with 1125 additions and 1054 deletions

File diff suppressed because it is too large Load Diff

View File

@ -62,7 +62,6 @@ enum
/*
* Local Functions
*/
static void script_fu_console_interface (void);
static void script_fu_console_response (GtkWidget *widget,
gint response_id,
ConsoleInterface *console);
@ -92,27 +91,9 @@ static void script_fu_output_to_console (TsOutputType type,
* Function definitions
*/
void
script_fu_console_run (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[1];
ts_set_print_flag (1);
script_fu_console_interface ();
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = GIMP_PDB_SUCCESS;
}
static void
script_fu_console_interface (void)
GimpValueArray *
script_fu_console_run (GimpProcedure *procedure,
const GimpValueArray *args)
{
ConsoleInterface console = { 0, };
GtkWidget *vbox;
@ -120,6 +101,8 @@ script_fu_console_interface (void)
GtkWidget *scrolled_window;
GtkWidget *hbox;
ts_set_print_flag (1);
gimp_ui_init ("script-fu", FALSE);
console.history_max = 50;
@ -254,6 +237,8 @@ script_fu_console_interface (void)
if (console.dialog)
gtk_widget_destroy (console.dialog);
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
}
static void
@ -402,17 +387,10 @@ script_fu_browse_response (GtkWidget *widget,
ConsoleInterface *console)
{
GimpProcBrowserDialog *dialog = GIMP_PROC_BROWSER_DIALOG (widget);
GimpProcedure *procedure;
gchar *proc_name;
gchar *proc_blurb;
gchar *proc_help;
gchar *proc_author;
gchar *proc_copyright;
gchar *proc_date;
GimpPDBProcType proc_type;
gint n_params;
gint n_return_vals;
GimpParamDef *params;
GimpParamDef *return_vals;
GParamSpec **pspecs;
gint n_pspecs;
gint i;
GString *text;
@ -427,25 +405,17 @@ script_fu_browse_response (GtkWidget *widget,
if (proc_name == NULL)
return;
gimp_pdb_proc_info (proc_name,
&proc_blurb,
&proc_help,
&proc_author,
&proc_copyright,
&proc_date,
&proc_type,
&n_params,
&n_return_vals,
&params,
&return_vals);
procedure = gimp_pdb_lookup_procedure (gimp_get_pdb (), proc_name);
pspecs = gimp_procedure_get_arguments (procedure, &n_pspecs);
text = g_string_new ("(");
text = g_string_append (text, proc_name);
for (i = 0; i < n_params; i++)
for (i = 0; i < n_pspecs; i++)
{
text = g_string_append_c (text, ' ');
text = g_string_append (text, params[i].name);
text = g_string_append (text, pspecs[i]->name);
}
text = g_string_append_c (text, ')');
@ -463,14 +433,6 @@ script_fu_browse_response (GtkWidget *widget,
gtk_window_present (GTK_WINDOW (console->dialog));
g_free (proc_name);
g_free (proc_blurb);
g_free (proc_help);
g_free (proc_author);
g_free (proc_copyright);
g_free (proc_date);
gimp_destroy_paramdefs (params, n_params);
gimp_destroy_paramdefs (return_vals, n_return_vals);
}
static void
@ -606,7 +568,8 @@ script_fu_cc_key_function (GtkWidget *widget,
output = g_string_new (NULL);
ts_register_output_func (ts_gstring_output_func, output);
gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_PLUGIN);
gimp_plug_in_set_pdb_error_handler (gimp_get_plug_in (),
GIMP_PDB_ERROR_HANDLER_PLUGIN);
if (ts_interpret_string (list->data) != 0)
{
@ -623,7 +586,8 @@ script_fu_cc_key_function (GtkWidget *widget,
console);
}
gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_INTERNAL);
gimp_plug_in_set_pdb_error_handler (gimp_get_plug_in (),
GIMP_PDB_ERROR_HANDLER_INTERNAL);
g_string_free (output, TRUE);

View File

@ -19,11 +19,8 @@
#define __SCRIPT_FU_CONSOLE_H__
void script_fu_console_run (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals);
GimpValueArray * script_fu_console_run (GimpProcedure *procedure,
const GimpValueArray *args);
#endif /* __SCRIPT_FU_CONSOLE_H__ */

View File

@ -25,24 +25,17 @@
#include "script-fu-intl.h"
void
script_fu_eval_run (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals)
GimpValueArray *
script_fu_eval_run (GimpProcedure *procedure,
const GimpValueArray *args)
{
static GimpParam values[2];
GString *output = g_string_new (NULL);
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpRunMode run_mode;
const gchar *code;
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
run_mode = params[0].data.d_int32;
run_mode = g_value_get_enum (gimp_value_array_index (args, 0));
code = g_value_get_string (gimp_value_array_index (args, 1));
ts_set_run_mode (run_mode);
ts_register_output_func (ts_gstring_output_func, output);
@ -50,7 +43,7 @@ script_fu_eval_run (const gchar *name,
switch (run_mode)
{
case GIMP_RUN_NONINTERACTIVE:
if (ts_interpret_string (params[1].data.d_string) != 0)
if (ts_interpret_string (code) != 0)
status = GIMP_PDB_EXECUTION_ERROR;
break;
@ -65,16 +58,15 @@ script_fu_eval_run (const gchar *name,
break;
}
values[0].data.d_status = status;
if (status != GIMP_PDB_SUCCESS && output->len > 0)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_STRING;
values[1].data.d_string = g_string_free (output, FALSE);
GError *error = g_error_new_literal (0, 0,
g_string_free (output, FALSE));
return gimp_procedure_new_return_values (procedure, status, error);
}
else
{
g_string_free (output, TRUE);
}
return gimp_procedure_new_return_values (procedure, status, NULL);
}

View File

@ -19,11 +19,8 @@
#define __SCRIPT_FU_EVAL_H__
void script_fu_eval_run (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals);
GimpValueArray * script_fu_eval_run (GimpProcedure *procedure,
const GimpValueArray *args);
#endif /* __SCRIPT_FU_EVAL_H__ */

View File

@ -880,7 +880,8 @@ script_fu_ok (SFScript *script)
output = g_string_new (NULL);
ts_register_output_func (ts_gstring_output_func, output);
gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_PLUGIN);
gimp_plug_in_set_pdb_error_handler (gimp_get_plug_in (),
GIMP_PDB_ERROR_HANDLER_PLUGIN);
if (ts_interpret_string (command))
{
@ -891,7 +892,8 @@ script_fu_ok (SFScript *script)
g_free (message);
}
gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_INTERNAL);
gimp_plug_in_set_pdb_error_handler (gimp_get_plug_in (),
GIMP_PDB_ERROR_HANDLER_INTERNAL);
g_string_free (output, TRUE);

View File

@ -38,8 +38,7 @@
*/
static gboolean script_fu_script_param_init (SFScript *script,
gint nparams,
const GimpParam *params,
const GimpValueArray *args,
SFArgType type,
gint n);
@ -167,162 +166,237 @@ script_fu_script_free (SFScript *script)
}
void
script_fu_script_install_proc (SFScript *script,
GimpRunProc run_proc)
script_fu_script_install_proc (GimpPlugIn *plug_in,
SFScript *script,
GimpRunFunc run_func)
{
GimpProcedure *procedure;
const gchar *menu_label = NULL;
GimpParamDef *args;
gint i;
g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
g_return_if_fail (script != NULL);
g_return_if_fail (run_proc != NULL);
g_return_if_fail (run_func != NULL);
/* Allow scripts with no menus */
if (strncmp (script->menu_label, "<None>", 6) != 0)
menu_label = script->menu_label;
args = g_new0 (GimpParamDef, script->n_args + 1);
procedure = gimp_procedure_new (plug_in, script->name,
GIMP_TEMPORARY,
run_func, script, NULL);
args[0].type = GIMP_PDB_INT32;
args[0].name = "run-mode";
args[0].description = "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }";
gimp_procedure_set_image_types (procedure, script->image_types);
gimp_procedure_set_menu_label (procedure, menu_label);
gimp_procedure_set_documentation (procedure,
script->blurb,
NULL,
script->name);
gimp_procedure_set_attribution (procedure,
script->author,
script->copyright,
script->date);
gimp_procedure_add_argument (procedure,
g_param_spec_enum ("run-mode",
"Run mode",
"The run mode",
GIMP_TYPE_RUN_MODE,
GIMP_RUN_INTERACTIVE,
G_PARAM_READWRITE));
for (i = 0; i < script->n_args; i++)
{
GimpPDBArgType type = 0;
const gchar *name = NULL;
GParamSpec *pspec = NULL;
switch (script->args[i].type)
{
case SF_IMAGE:
type = GIMP_PDB_IMAGE;
name = "image";
pspec = gimp_param_spec_image_id ("image",
"Image",
script->args[i].label,
TRUE,
G_PARAM_READWRITE);
break;
case SF_DRAWABLE:
type = GIMP_PDB_DRAWABLE;
name = "drawable";
pspec = gimp_param_spec_drawable_id ("drawable",
"Drawable",
script->args[i].label,
TRUE,
G_PARAM_READWRITE);
break;
case SF_LAYER:
type = GIMP_PDB_LAYER;
name = "layer";
pspec = gimp_param_spec_layer_id ("layer",
"Layer",
script->args[i].label,
TRUE,
G_PARAM_READWRITE);
break;
case SF_CHANNEL:
type = GIMP_PDB_CHANNEL;
name = "channel";
pspec = gimp_param_spec_channel_id ("channel",
"Channel",
script->args[i].label,
TRUE,
G_PARAM_READWRITE);
break;
case SF_VECTORS:
type = GIMP_PDB_VECTORS;
name = "vectors";
pspec = gimp_param_spec_vectors_id ("vectors",
"Vectors",
script->args[i].label,
TRUE,
G_PARAM_READWRITE);
break;
case SF_DISPLAY:
type = GIMP_PDB_DISPLAY;
name = "display";
pspec = gimp_param_spec_display_id ("display",
"Display",
script->args[i].label,
TRUE,
G_PARAM_READWRITE);
break;
case SF_COLOR:
type = GIMP_PDB_COLOR;
name = "color";
pspec = gimp_param_spec_rgb ("color",
"Color",
script->args[i].label,
TRUE, NULL,
G_PARAM_READWRITE);
break;
case SF_TOGGLE:
type = GIMP_PDB_INT32;
name = "toggle";
pspec = g_param_spec_boolean ("toggle",
"Toggle",
script->args[i].label,
FALSE,
G_PARAM_READWRITE);
break;
case SF_VALUE:
type = GIMP_PDB_STRING;
name = "value";
pspec = g_param_spec_string ("value",
"Value",
script->args[i].label,
NULL,
G_PARAM_READWRITE);
break;
case SF_STRING:
case SF_TEXT:
type = GIMP_PDB_STRING;
name = "string";
pspec = g_param_spec_string ("string",
"String",
script->args[i].label,
NULL,
G_PARAM_READWRITE);
break;
case SF_ADJUSTMENT:
type = GIMP_PDB_FLOAT;
name = "value";
pspec = g_param_spec_double ("value",
"Value",
script->args[i].label,
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
break;
case SF_FILENAME:
type = GIMP_PDB_STRING;
name = "filename";
pspec = gimp_param_spec_string ("filename",
"Filename",
script->args[i].label,
TRUE, TRUE, FALSE,
NULL,
G_PARAM_READWRITE);
break;
case SF_DIRNAME:
type = GIMP_PDB_STRING;
name = "dirname";
pspec = gimp_param_spec_string ("dirname",
"Dirname",
script->args[i].label,
TRUE, TRUE, FALSE,
NULL,
G_PARAM_READWRITE);
break;
case SF_FONT:
type = GIMP_PDB_STRING;
name = "font";
pspec = gimp_param_spec_string ("Font",
"font",
script->args[i].label,
FALSE, TRUE, FALSE,
NULL,
G_PARAM_READWRITE);
break;
case SF_PALETTE:
type = GIMP_PDB_STRING;
name = "palette";
pspec = gimp_param_spec_string ("palette",
"Palette",
script->args[i].label,
FALSE, TRUE, FALSE,
NULL,
G_PARAM_READWRITE);
break;
case SF_PATTERN:
type = GIMP_PDB_STRING;
name = "pattern";
pspec = gimp_param_spec_string ("pattern",
"Pattern",
script->args[i].label,
FALSE, TRUE, FALSE,
NULL,
G_PARAM_READWRITE);
break;
case SF_BRUSH:
type = GIMP_PDB_STRING;
name = "brush";
pspec = gimp_param_spec_string ("brush",
"Brush",
script->args[i].label,
FALSE, TRUE, FALSE,
NULL,
G_PARAM_READWRITE);
break;
case SF_GRADIENT:
type = GIMP_PDB_STRING;
name = "gradient";
pspec = gimp_param_spec_string ("gradient",
"Gradient",
script->args[i].label,
FALSE, TRUE, FALSE,
NULL,
G_PARAM_READWRITE);
break;
case SF_OPTION:
type = GIMP_PDB_INT32;
name = "option";
pspec = g_param_spec_int ("option",
"Option",
script->args[i].label,
G_MININT, G_MAXINT, 0,
G_PARAM_READWRITE);
break;
case SF_ENUM:
type = GIMP_PDB_INT32;
name = "enum";
pspec = g_param_spec_int ("enum",
"Enum",
script->args[i].label,
G_MININT, G_MAXINT, 0,
G_PARAM_READWRITE);
break;
}
args[i + 1].type = type;
args[i + 1].name = (gchar *) name;
args[i + 1].description = script->args[i].label;
gimp_procedure_add_argument (procedure, pspec);
}
gimp_install_temp_proc (script->name,
script->blurb,
"",
script->author,
script->copyright,
script->date,
menu_label,
script->image_types,
GIMP_TEMPORARY,
script->n_args + 1, 0,
args, NULL,
run_proc);
g_free (args);
gimp_plug_in_add_temp_procedure (plug_in, procedure);
g_object_unref (procedure);
}
void
script_fu_script_uninstall_proc (SFScript *script)
script_fu_script_uninstall_proc (GimpPlugIn *plug_in,
SFScript *script)
{
g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
g_return_if_fail (script != NULL);
gimp_uninstall_temp_proc (script->name);
gimp_plug_in_remove_temp_procedure (plug_in, script->name);
}
gchar *
@ -448,8 +522,7 @@ script_fu_script_reset (SFScript *script,
gint
script_fu_script_collect_standard_args (SFScript *script,
gint n_params,
const GimpParam *params)
const GimpValueArray *args)
{
gint params_consumed = 0;
@ -457,7 +530,7 @@ script_fu_script_collect_standard_args (SFScript *script,
/* the first parameter may be a DISPLAY id */
if (script_fu_script_param_init (script,
n_params, params, SF_DISPLAY,
args, SF_DISPLAY,
params_consumed))
{
params_consumed++;
@ -465,7 +538,7 @@ script_fu_script_collect_standard_args (SFScript *script,
/* an IMAGE id may come first or after the DISPLAY id */
if (script_fu_script_param_init (script,
n_params, params, SF_IMAGE,
args, SF_IMAGE,
params_consumed))
{
params_consumed++;
@ -474,16 +547,16 @@ script_fu_script_collect_standard_args (SFScript *script,
* VECTORS id
*/
if (script_fu_script_param_init (script,
n_params, params, SF_DRAWABLE,
args, SF_DRAWABLE,
params_consumed) ||
script_fu_script_param_init (script,
n_params, params, SF_LAYER,
args, SF_LAYER,
params_consumed) ||
script_fu_script_param_init (script,
n_params, params, SF_CHANNEL,
args, SF_CHANNEL,
params_consumed) ||
script_fu_script_param_init (script,
n_params, params, SF_VECTORS,
args, SF_VECTORS,
params_consumed))
{
params_consumed++;
@ -618,7 +691,7 @@ script_fu_script_get_command (SFScript *script)
gchar *
script_fu_script_get_command_from_params (SFScript *script,
const GimpParam *params)
const GimpValueArray *args)
{
GString *s;
gint i;
@ -630,7 +703,7 @@ script_fu_script_get_command_from_params (SFScript *script,
for (i = 0; i < script->n_args; i++)
{
const GimpParam *param = &params[i + 1];
GValue *value = gimp_value_array_index (args, i + 1);
g_string_append_c (s, ' ');
@ -642,25 +715,28 @@ script_fu_script_get_command_from_params (SFScript *script,
case SF_CHANNEL:
case SF_VECTORS:
case SF_DISPLAY:
g_string_append_printf (s, "%d", param->data.d_int32);
g_string_append_printf (s, "%d", g_value_get_int (value));
break;
case SF_COLOR:
{
GimpRGB color;
guchar r, g, b;
gimp_rgb_get_uchar (&param->data.d_color, &r, &g, &b);
gimp_value_get_rgb (value, &color);
gimp_rgb_get_uchar (&color, &r, &g, &b);
g_string_append_printf (s, "'(%d %d %d)",
(gint) r, (gint) g, (gint) b);
}
break;
case SF_TOGGLE:
g_string_append_printf (s, (param->data.d_int32 ? "TRUE" : "FALSE"));
g_string_append_printf (s, (g_value_get_boolean (value) ?
"TRUE" : "FALSE"));
break;
case SF_VALUE:
g_string_append (s, param->data.d_string);
g_string_append (s, g_value_get_string (value));
break;
case SF_STRING:
@ -670,7 +746,7 @@ script_fu_script_get_command_from_params (SFScript *script,
{
gchar *tmp;
tmp = script_fu_strescape (param->data.d_string);
tmp = script_fu_strescape (g_value_get_string (value));
g_string_append_printf (s, "\"%s\"", tmp);
g_free (tmp);
}
@ -680,7 +756,7 @@ script_fu_script_get_command_from_params (SFScript *script,
{
gchar buffer[G_ASCII_DTOSTR_BUF_SIZE];
g_ascii_dtostr (buffer, sizeof (buffer), param->data.d_float);
g_ascii_dtostr (buffer, sizeof (buffer), g_value_get_double (value));
g_string_append (s, buffer);
}
break;
@ -690,12 +766,12 @@ script_fu_script_get_command_from_params (SFScript *script,
case SF_PATTERN:
case SF_GRADIENT:
case SF_BRUSH:
g_string_append_printf (s, "\"%s\"", param->data.d_string);
g_string_append_printf (s, "\"%s\"", g_value_get_string (value));
break;
case SF_OPTION:
case SF_ENUM:
g_string_append_printf (s, "%d", param->data.d_int32);
g_string_append_printf (s, "%d", g_value_get_int (value));
break;
}
}
@ -712,61 +788,64 @@ script_fu_script_get_command_from_params (SFScript *script,
static gboolean
script_fu_script_param_init (SFScript *script,
gint nparams,
const GimpParam *params,
const GimpValueArray *args,
SFArgType type,
gint n)
{
SFArg *arg = &script->args[n];
if (script->n_args > n && arg->type == type && nparams > n + 1)
if (script->n_args > n &&
arg->type == type &&
gimp_value_array_length (args) > n + 1)
{
GValue *value = gimp_value_array_index (args, n + 1);
switch (type)
{
case SF_IMAGE:
if (params[n + 1].type == GIMP_PDB_IMAGE)
if (GIMP_VALUE_HOLDS_IMAGE_ID (value))
{
arg->value.sfa_image = params[n + 1].data.d_image;
arg->value.sfa_image = gimp_value_get_image_id (value);
return TRUE;
}
break;
case SF_DRAWABLE:
if (params[n + 1].type == GIMP_PDB_DRAWABLE)
if (GIMP_VALUE_HOLDS_DRAWABLE_ID (value))
{
arg->value.sfa_drawable = params[n + 1].data.d_drawable;
arg->value.sfa_drawable = gimp_value_get_drawable_id (value);
return TRUE;
}
break;
case SF_LAYER:
if (params[n + 1].type == GIMP_PDB_LAYER)
if (GIMP_VALUE_HOLDS_LAYER_ID (value))
{
arg->value.sfa_layer = params[n + 1].data.d_layer;
arg->value.sfa_layer = gimp_value_get_layer_id (value);
return TRUE;
}
break;
case SF_CHANNEL:
if (params[n + 1].type == GIMP_PDB_CHANNEL)
if (GIMP_VALUE_HOLDS_CHANNEL_ID (value))
{
arg->value.sfa_channel = params[n + 1].data.d_channel;
arg->value.sfa_channel = gimp_value_get_channel_id (value);
return TRUE;
}
break;
case SF_VECTORS:
if (params[n + 1].type == GIMP_PDB_VECTORS)
if (GIMP_VALUE_HOLDS_VECTORS_ID (value))
{
arg->value.sfa_vectors = params[n + 1].data.d_vectors;
arg->value.sfa_vectors = gimp_value_get_vectors_id (value);
return TRUE;
}
break;
case SF_DISPLAY:
if (params[n + 1].type == GIMP_PDB_DISPLAY)
if (GIMP_VALUE_HOLDS_DISPLAY_ID (value))
{
arg->value.sfa_display = params[n + 1].data.d_display;
arg->value.sfa_display = gimp_value_get_display_id (value);
return TRUE;
}
break;

View File

@ -22,28 +22,29 @@
SFScript * script_fu_script_new (const gchar *name,
const gchar *menu_label,
const gchar *blurb,
const gchar *author,
const gchar *authors,
const gchar *copyright,
const gchar *date,
const gchar *image_types,
gint n_args);
void script_fu_script_free (SFScript *script);
void script_fu_script_install_proc (SFScript *script,
GimpRunProc run_proc);
void script_fu_script_uninstall_proc (SFScript *script);
void script_fu_script_install_proc (GimpPlugIn *plug_in,
SFScript *script,
GimpRunFunc run_func);
void script_fu_script_uninstall_proc (GimpPlugIn *plug_in,
SFScript *script);
gchar * script_fu_script_get_title (SFScript *script);
void script_fu_script_reset (SFScript *script,
gboolean reset_ids);
gint script_fu_script_collect_standard_args (SFScript *script,
gint n_params,
const GimpParam *params);
const GimpValueArray *args);
gchar * script_fu_script_get_command (SFScript *script);
gchar * script_fu_script_get_command_from_params (SFScript *script,
const GimpParam *params);
const GimpValueArray *args);
#endif /* __SCRIPT_FU_SCRIPT__ */

View File

@ -60,18 +60,16 @@ static void script_fu_load_directory (GFile *directory);
static void script_fu_load_script (GFile *file);
static gboolean script_fu_install_script (gpointer foo,
GList *scripts,
gpointer bar);
gpointer data);
static void script_fu_install_menu (SFMenu *menu);
static gboolean script_fu_remove_script (gpointer foo,
GList *scripts,
gpointer bar);
static void script_fu_script_proc (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals);
gpointer data);
static GimpValueArray * script_fu_script_proc (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer data);
static SFScript *script_fu_find_script (const gchar *name);
static SFScript * script_fu_find_script (const gchar *name);
static gchar * script_fu_menu_map (const gchar *menu_path);
static gint script_fu_menu_compare (gconstpointer a,
@ -91,7 +89,8 @@ static GList *script_menu_list = NULL;
*/
void
script_fu_find_scripts (GList *path)
script_fu_find_scripts (GimpPlugIn *plug_in,
GList *path)
{
GList *list;
@ -100,7 +99,7 @@ script_fu_find_scripts (GList *path)
{
g_tree_foreach (script_tree,
(GTraverseFunc) script_fu_remove_script,
NULL);
plug_in);
g_tree_destroy (script_tree);
}
@ -117,7 +116,7 @@ script_fu_find_scripts (GList *path)
/* Now that all scripts are read in and sorted, tell gimp about them */
g_tree_foreach (script_tree,
(GTraverseFunc) script_fu_install_script,
NULL);
plug_in);
script_menu_list = g_list_sort (script_menu_list,
(GCompareFunc) script_fu_menu_compare);
@ -672,15 +671,17 @@ script_fu_load_script (GFile *file)
static gboolean
script_fu_install_script (gpointer foo G_GNUC_UNUSED,
GList *scripts,
gpointer bar G_GNUC_UNUSED)
gpointer data)
{
GimpPlugIn *plug_in = data;
GList *list;
for (list = scripts; list; list = g_list_next (list))
{
SFScript *script = list->data;
script_fu_script_install_proc (script, script_fu_script_proc);
script_fu_script_install_proc (plug_in, script,
script_fu_script_proc);
}
return FALSE;
@ -689,7 +690,13 @@ script_fu_install_script (gpointer foo G_GNUC_UNUSED,
static void
script_fu_install_menu (SFMenu *menu)
{
gimp_plugin_menu_register (menu->script->name, menu->menu_path);
GimpPlugIn *plug_in = gimp_get_plug_in ();
GimpProcedure *procedure;
procedure = gimp_plug_in_get_temp_procedure (plug_in,
menu->script->name);
gimp_procedure_add_menu_path (procedure, menu->menu_path);
g_free (menu->menu_path);
g_slice_free (SFMenu, menu);
@ -701,15 +708,16 @@ script_fu_install_menu (SFMenu *menu)
static gboolean
script_fu_remove_script (gpointer foo G_GNUC_UNUSED,
GList *scripts,
gpointer bar G_GNUC_UNUSED)
gpointer data)
{
GimpPlugIn *plug_in = data;
GList *list;
for (list = scripts; list; list = g_list_next (list))
{
SFScript *script = list->data;
script_fu_script_uninstall_proc (script);
script_fu_script_uninstall_proc (plug_in, script);
script_fu_script_free (script);
}
@ -718,37 +726,24 @@ script_fu_remove_script (gpointer foo G_GNUC_UNUSED,
return FALSE;
}
static void
script_fu_script_proc (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals)
static GimpValueArray *
script_fu_script_proc (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer data)
{
static GimpParam values[2] = { { 0, }, { 0, } };
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
SFScript *script;
GimpRunMode run_mode;
GError *error = NULL;
if (values[1].type == GIMP_PDB_STRING && values[1].data.d_string)
{
g_free (values[1].data.d_string);
values[1].data.d_string = NULL;
}
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
script = script_fu_find_script (name);
script = script_fu_find_script (gimp_procedure_get_name (procedure));
if (! script)
status = GIMP_PDB_CALLING_ERROR;
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CALLING_ERROR,
NULL);
if (status == GIMP_PDB_SUCCESS)
{
GimpRunMode run_mode = params[0].data.d_int32;
run_mode = g_value_get_enum (gimp_value_array_index (args, 0));
ts_set_run_mode (run_mode);
@ -759,8 +754,7 @@ script_fu_script_proc (const gchar *name,
gint min_args = 0;
/* First, try to collect the standard script arguments... */
min_args = script_fu_script_collect_standard_args (script,
nparams, params);
min_args = script_fu_script_collect_standard_args (script, args);
/* ...then acquire the rest of arguments (if any) with a dialog */
if (script->n_args > min_args)
@ -775,26 +769,21 @@ script_fu_script_proc (const gchar *name,
case GIMP_RUN_NONINTERACTIVE:
/* Make sure all the arguments are there */
if (nparams != (script->n_args + 1))
if (gimp_value_array_length (args) != (script->n_args + 1))
status = GIMP_PDB_CALLING_ERROR;
if (status == GIMP_PDB_SUCCESS)
{
gchar *command;
command = script_fu_script_get_command_from_params (script,
params);
command = script_fu_script_get_command_from_params (script, args);
/* run the command through the interpreter */
if (! script_fu_run_command (command, &error))
{
status = GIMP_PDB_EXECUTION_ERROR;
*nreturn_vals = 2;
values[1].type = GIMP_PDB_STRING;
values[1].data.d_string = error->message;
error->message = NULL;
g_error_free (error);
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR,
error);
}
g_free (command);
@ -806,20 +795,16 @@ script_fu_script_proc (const gchar *name,
gchar *command;
/* First, try to collect the standard script arguments */
script_fu_script_collect_standard_args (script, nparams, params);
script_fu_script_collect_standard_args (script, args);
command = script_fu_script_get_command (script);
/* run the command through the interpreter */
if (! script_fu_run_command (command, &error))
{
status = GIMP_PDB_EXECUTION_ERROR;
*nreturn_vals = 2;
values[1].type = GIMP_PDB_STRING;
values[1].data.d_string = error->message;
error->message = NULL;
g_error_free (error);
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR,
error);
}
g_free (command);
@ -829,9 +814,8 @@ script_fu_script_proc (const gchar *name,
default:
break;
}
}
values[0].data.d_status = status;
return gimp_procedure_new_return_values (procedure, status, NULL);
}
/* this is a GTraverseFunction */

View File

@ -19,7 +19,8 @@
#define __SCRIPT_FU_SCRIPTS_H__
void script_fu_find_scripts (GList *path);
void script_fu_find_scripts (GimpPlugIn *plug_in,
GList *path);
pointer script_fu_add_script (scheme *sc,
pointer a);
pointer script_fu_add_menu (scheme *sc,

View File

@ -219,18 +219,20 @@ script_fu_server_get_mode (void)
return server_mode;
}
void
script_fu_server_run (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals)
GimpValueArray *
script_fu_server_run (GimpProcedure *procedure,
const GimpValueArray *args)
{
static GimpParam values[1];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpRunMode run_mode;
const gchar *ip;
gint port;
const gchar *logfile;
run_mode = params[0].data.d_int32;
run_mode = g_value_get_enum (gimp_value_array_index (args, 0));
ip = g_value_get_string (gimp_value_array_index (args, 1));
port = g_value_get_int (gimp_value_array_index (args, 2));
logfile = g_value_get_string (gimp_value_array_index (args, 3));
ts_set_run_mode (run_mode);
ts_set_print_flag (1);
@ -252,26 +254,19 @@ script_fu_server_run (const gchar *name,
server_mode = TRUE;
/* Start the server */
server_start ((params[1].data.d_string &&
strlen (params[1].data.d_string)) ?
params[1].data.d_string : "127.0.0.1",
params[2].data.d_int32,
params[3].data.d_string);
server_start (ip ? ip : "127.0.0.1", port, logfile);
break;
case GIMP_RUN_WITH_LAST_VALS:
status = GIMP_PDB_CALLING_ERROR;
g_warning ("Script-Fu server does not handle \"GIMP_RUN_WITH_LAST_VALS\"");
g_printerr ("Script-Fu server does not handle "
"\"GIMP_RUN_WITH_LAST_VALS\"\n");
default:
break;
}
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
return gimp_procedure_new_return_values (procedure, status, NULL);
}
static void

View File

@ -19,11 +19,8 @@
#define __SCRIPT_FU_SERVER_H__
void script_fu_server_run (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals);
GimpValueArray * script_fu_server_run (GimpProcedure *procedure,
const GimpValueArray *args);
void script_fu_server_listen (gint timeout);
gint script_fu_server_get_mode (void);
void script_fu_server_quit (void);

View File

@ -31,30 +31,23 @@
#include "script-fu-intl.h"
void
script_fu_text_console_run (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals)
GimpValueArray *
script_fu_text_console_run (GimpProcedure *procedure,
const GimpValueArray *args)
{
static GimpParam values[1];
/* Enable Script-Fu output */
ts_register_output_func (ts_stdout_output_func, NULL);
ts_print_welcome ();
gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_PLUGIN);
gimp_plug_in_set_pdb_error_handler (gimp_procedure_get_plug_in (procedure),
GIMP_PDB_ERROR_HANDLER_PLUGIN);
/* Run the interface */
ts_interpret_stdin ();
gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_INTERNAL);
gimp_plug_in_set_pdb_error_handler (gimp_procedure_get_plug_in (procedure),
GIMP_PDB_ERROR_HANDLER_INTERNAL);
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = GIMP_PDB_SUCCESS;
*nreturn_vals = 1;
*return_vals = values;
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
}

View File

@ -19,11 +19,8 @@
#define __SCRIPT_FU_TEXT_CONSOLE_H__
void script_fu_text_console_run (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals);
GimpValueArray * script_fu_text_console_run (GimpProcedure *procedure,
const GimpValueArray *args);
#endif /* __SCRIPT_FU_TEXT_CONSOLE_H__ */

View File

@ -38,146 +38,245 @@
#include "script-fu-intl.h"
/* Declare local functions. */
typedef struct _ScriptFu ScriptFu;
typedef struct _ScriptFuClass ScriptFuClass;
static void script_fu_query (void);
static void script_fu_run (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals);
static GList * script_fu_search_path (void);
static void script_fu_extension_init (void);
static void script_fu_refresh_proc (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals);
const GimpPlugInInfo PLUG_IN_INFO =
struct _ScriptFu
{
NULL, /* init_proc */
NULL, /* quit_proc */
script_fu_query, /* query_proc */
script_fu_run /* run_proc */
GimpPlugIn parent_instance;
};
struct _ScriptFuClass
{
GimpPlugInClass parent_class;
};
MAIN ()
#define SCRIPT_FU_TYPE (script_fu_get_type ())
#define SCRIPT_FU (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SCRIPT_FU_TYPE, ScriptFu))
GType script_fu_get_type (void) G_GNUC_CONST;
static GList * script_fu_query_procedures (GimpPlugIn *plug_in);
static GimpProcedure * script_fu_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
static GimpValueArray * script_fu_run (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data);
static GList * script_fu_search_path (void);
static void script_fu_extension_init (GimpPlugIn *plug_in);
static GimpValueArray * script_fu_refresh_proc (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data);
G_DEFINE_TYPE (ScriptFu, script_fu, GIMP_TYPE_PLUG_IN)
GIMP_MAIN (SCRIPT_FU_TYPE)
static void
script_fu_query (void)
script_fu_class_init (ScriptFuClass *klass)
{
static const GimpParamDef console_args[] =
{
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0) }" }
};
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
static const GimpParamDef textconsole_args[] =
{
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0) }" }
};
static const GimpParamDef eval_args[] =
{
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-NONINTERACTIVE (1) }" },
{ GIMP_PDB_STRING, "code", "The code to evaluate" }
};
static const GimpParamDef server_args[] =
{
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-NONINTERACTIVE (1) }" },
{ GIMP_PDB_STRING, "ip", "The ip on which to listen for requests" },
{ GIMP_PDB_INT32, "port", "The port on which to listen for requests" },
{ GIMP_PDB_STRING, "logfile", "The file to log server activity to" }
};
gimp_plugin_domain_register (GETTEXT_PACKAGE "-script-fu", NULL);
gimp_install_procedure ("extension-script-fu",
"A scheme interpreter for scripting GIMP operations",
"More help here later",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997",
NULL,
NULL,
GIMP_EXTENSION,
0, 0, NULL, NULL);
gimp_install_procedure ("plug-in-script-fu-console",
N_("Interactive console for Script-Fu development"),
"Provides an interface which allows interactive "
"scheme development.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997",
N_("_Console"),
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (console_args), 0,
console_args, NULL);
gimp_plugin_menu_register ("plug-in-script-fu-console",
"<Image>/Filters/Development/Script-Fu");
gimp_install_procedure ("plug-in-script-fu-text-console",
"Provides a text console mode for script-fu "
"development",
"Provides an interface which allows interactive "
"scheme development.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997",
NULL,
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (textconsole_args), 0,
textconsole_args, NULL);
gimp_install_procedure ("plug-in-script-fu-server",
N_("Server for remote Script-Fu operation"),
"Provides a server for remote script-fu operation. "
"NOTE that for security reasons this procedure's "
"API was changed in an incompatible way since "
"GIMP 2.8.12. You now have to pass the IP to listen "
"on as first parameter. Calling this procedure with "
"the old API will fail on purpose.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997",
N_("_Start Server..."),
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (server_args), 0,
server_args, NULL);
gimp_plugin_menu_register ("plug-in-script-fu-server",
"<Image>/Filters/Development/Script-Fu");
gimp_install_procedure ("plug-in-script-fu-eval",
"Evaluate scheme code",
"Evaluate the code under the scheme interpreter "
"(primarily for batch mode)",
"Manish Singh",
"Manish Singh",
"1998",
NULL,
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (eval_args), 0,
eval_args, NULL);
plug_in_class->query_procedures = script_fu_query_procedures;
plug_in_class->create_procedure = script_fu_create_procedure;
}
static void
script_fu_run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
script_fu_init (ScriptFu *script_fu)
{
}
static GList *
script_fu_query_procedures (GimpPlugIn *plug_in)
{
GList *list = NULL;
gimp_plug_in_set_translation_domain (plug_in,
GETTEXT_PACKAGE "-script-fu", NULL);
list = g_list_append (list, g_strdup ("extension-script-fu"));
list = g_list_append (list, g_strdup ("plug-in-script-fu-console"));
list = g_list_append (list, g_strdup ("plug-in-script-fu-text-console"));
list = g_list_append (list, g_strdup ("plug-in-script-fu-server"));
list = g_list_append (list, g_strdup ("plug-in-script-fu-eval"));
return list;
}
static GimpProcedure *
script_fu_create_procedure (GimpPlugIn *plug_in,
const gchar *name)
{
GimpProcedure *procedure = NULL;
if (! strcmp (name, "extension-script-fu"))
{
procedure = gimp_procedure_new (plug_in, name, GIMP_EXTENSION,
script_fu_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"A scheme interpreter for scripting "
"GIMP operations",
"More help here later",
NULL);
gimp_procedure_set_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997");
}
else if (! strcmp (name, "plug-in-script-fu-console"))
{
procedure = gimp_procedure_new (plug_in, name, GIMP_PLUGIN,
script_fu_run, NULL, NULL);
gimp_procedure_set_menu_label (procedure, N_("_Console"));
gimp_procedure_add_menu_path (procedure,
"<Image>/Filters/Development/Script-Fu");
gimp_procedure_set_documentation (procedure,
N_("Interactive console for Script-Fu "
"development"),
"Provides an interface which allows "
"interactive scheme development.",
name);
gimp_procedure_set_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997");
gimp_procedure_add_argument (procedure,
g_param_spec_enum ("run-mode",
"Run mode",
"The run mode",
GIMP_TYPE_RUN_MODE,
GIMP_RUN_INTERACTIVE,
G_PARAM_READWRITE));
}
else if (! strcmp (name, "plug-in-script-fu-text-console"))
{
procedure = gimp_procedure_new (plug_in, name, GIMP_PLUGIN,
script_fu_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"Provides a text console mode for "
"script-fu development",
"Provides an interface which allows "
"interactive scheme development.",
name);
gimp_procedure_set_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997");
gimp_procedure_add_argument (procedure,
g_param_spec_enum ("run-mode",
"Run mode",
"The run mode",
GIMP_TYPE_RUN_MODE,
GIMP_RUN_INTERACTIVE,
G_PARAM_READWRITE));
}
else if (! strcmp (name, "plug-in-script-fu-server"))
{
procedure = gimp_procedure_new (plug_in, name, GIMP_PLUGIN,
script_fu_run, NULL, NULL);
gimp_procedure_set_menu_label (procedure, N_("_Start Server..."));
gimp_procedure_add_menu_path (procedure,
"<Image>/Filters/Development/Script-Fu");
gimp_procedure_set_documentation (procedure,
N_("Server for remote Script-Fu "
"operation"),
"Provides a server for remote "
"script-fu operation. NOTE that for "
"security reasons this procedure's "
"API was changed in an incompatible "
"way since GIMP 2.8.12. You now have "
"to pass the IP to listen on as "
"first parameter. Calling this "
"procedure with the old API will "
"fail on purpose.",
name);
gimp_procedure_set_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997");
gimp_procedure_add_argument (procedure,
g_param_spec_enum ("run-mode",
"Run mode",
"The run mode",
GIMP_TYPE_RUN_MODE,
GIMP_RUN_INTERACTIVE,
G_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_string ("ip",
"IP",
"The IP on which to "
"listen for requests",
NULL,
G_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_int ("port",
"Port",
"The port on which to "
"listen for requests",
0, G_MAXINT, 0,
G_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_string ("logfile",
"Log File",
"The file to log "
"activity to",
NULL,
G_PARAM_READWRITE));
}
else if (! strcmp (name, "plug-in-script-fu-eval"))
{
procedure = gimp_procedure_new (plug_in, name, GIMP_PLUGIN,
script_fu_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"Evaluate scheme code",
"Evaluate the code under the scheme "
"interpreter (primarily for batch mode)",
name);
gimp_procedure_set_attribution (procedure,
"Manish Singh",
"Manish Singh",
"1998");
gimp_procedure_add_argument (procedure,
g_param_spec_enum ("run-mode",
"Run mode",
"The run mode",
GIMP_TYPE_RUN_MODE,
GIMP_RUN_INTERACTIVE,
G_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_string ("code",
"Code",
"The code to run",
NULL,
G_PARAM_READWRITE));
}
return procedure;
}
static GimpValueArray *
script_fu_run (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data)
{
GimpPlugIn *plug_in = gimp_procedure_get_plug_in (procedure);
const gchar *name = gimp_procedure_get_name (procedure);
GimpValueArray *return_vals = NULL;
GList *path;
INIT_I18N();
@ -190,7 +289,7 @@ script_fu_run (const gchar *name,
if (strcmp (name, "extension-script-fu") == 0)
{
/* Setup auxiliary temporary procedures for the base extension */
script_fu_extension_init ();
script_fu_extension_init (plug_in);
/* Init the interpreter and register scripts */
tinyscheme_init (path, TRUE);
@ -201,11 +300,11 @@ script_fu_run (const gchar *name,
tinyscheme_init (path, FALSE);
}
if (param != NULL)
ts_set_run_mode ((GimpRunMode) param[0].data.d_int32);
if (gimp_value_array_length (args) > 0)
ts_set_run_mode (g_value_get_enum (gimp_value_array_index (args, 0)));
/* Load all of the available scripts */
script_fu_find_scripts (path);
script_fu_find_scripts (plug_in, path);
g_list_free_full (path, (GDestroyNotify) g_object_unref);
@ -215,21 +314,12 @@ script_fu_run (const gchar *name,
* The main script-fu extension.
*/
static GimpParam values[1];
/* Acknowledge that the extension is properly initialized */
gimp_extension_ack ();
gimp_procedure_extension_ready (procedure);
/* Go into an endless loop */
while (TRUE)
gimp_extension_process (0);
/* Set return values; pointless because we never get out of the loop */
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = GIMP_PDB_SUCCESS;
gimp_plug_in_extension_process (plug_in, 0);
}
else if (strcmp (name, "plug-in-script-fu-text-console") == 0)
{
@ -237,8 +327,7 @@ script_fu_run (const gchar *name,
* The script-fu text console for interactive Scheme development
*/
script_fu_text_console_run (name, nparams, param,
nreturn_vals, return_vals);
return_vals = script_fu_text_console_run (procedure, args);
}
else if (strcmp (name, "plug-in-script-fu-console") == 0)
{
@ -246,8 +335,7 @@ script_fu_run (const gchar *name,
* The script-fu console for interactive Scheme development
*/
script_fu_console_run (name, nparams, param,
nreturn_vals, return_vals);
return_vals = script_fu_console_run (procedure, args);
}
else if (strcmp (name, "plug-in-script-fu-server") == 0)
{
@ -255,8 +343,7 @@ script_fu_run (const gchar *name,
* The script-fu server for remote operation
*/
script_fu_server_run (name, nparams, param,
nreturn_vals, return_vals);
return_vals = script_fu_server_run (procedure, args);
}
else if (strcmp (name, "plug-in-script-fu-eval") == 0)
{
@ -264,9 +351,15 @@ script_fu_run (const gchar *name,
* A non-interactive "console" (for batch mode)
*/
script_fu_eval_run (name, nparams, param,
nreturn_vals, return_vals);
return_vals = script_fu_eval_run (procedure, args);
}
if (! return_vals)
return_vals = gimp_procedure_new_return_values (procedure,
GIMP_PDB_SUCCESS,
NULL);
return return_vals;
}
static GList *
@ -296,90 +389,90 @@ script_fu_search_path (void)
}
static void
script_fu_extension_init (void)
script_fu_extension_init (GimpPlugIn *plug_in)
{
static const GimpParamDef args[] =
{
{ GIMP_PDB_INT32, "run-mode", "[Interactive], non-interactive" }
};
GimpProcedure *procedure;
gimp_plugin_menu_branch_register ("<Image>/Help", N_("_GIMP Online"));
gimp_plugin_menu_branch_register ("<Image>/Help", N_("_User Manual"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/Help", N_("_GIMP Online"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/Help", N_("_User Manual"));
gimp_plugin_menu_branch_register ("<Image>/Filters/Development",
gimp_plug_in_add_menu_branch (plug_in, "<Image>/Filters/Development",
N_("_Script-Fu"));
gimp_plugin_menu_branch_register ("<Image>/Filters/Development/Script-Fu",
gimp_plug_in_add_menu_branch (plug_in, "<Image>/Filters/Development/Script-Fu",
N_("_Test"));
gimp_plugin_menu_branch_register ("<Image>/File/Create",
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create",
N_("_Buttons"));
gimp_plugin_menu_branch_register ("<Image>/File/Create",
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create",
N_("_Logos"));
gimp_plugin_menu_branch_register ("<Image>/File/Create",
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create",
N_("_Patterns"));
gimp_plugin_menu_branch_register ("<Image>/File/Create",
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create",
N_("_Web Page Themes"));
gimp_plugin_menu_branch_register ("<Image>/File/Create/Web Page Themes",
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create/Web Page Themes",
N_("_Alien Glow"));
gimp_plugin_menu_branch_register ("<Image>/File/Create/Web Page Themes",
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create/Web Page Themes",
N_("_Beveled Pattern"));
gimp_plugin_menu_branch_register ("<Image>/File/Create/Web Page Themes",
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create/Web Page Themes",
N_("_Classic.Gimp.Org"));
gimp_plugin_menu_branch_register ("<Image>/Filters",
gimp_plug_in_add_menu_branch (plug_in, "<Image>/Filters",
N_("Alpha to _Logo"));
gimp_install_temp_proc ("script-fu-refresh",
procedure = gimp_procedure_new (plug_in, "script-fu-refresh",
GIMP_TEMPORARY,
script_fu_refresh_proc, NULL, NULL);
gimp_procedure_set_menu_label (procedure, N_("_Refresh Scripts"));
gimp_procedure_add_menu_path (procedure,
"<Image>/Filters/Development/Script-Fu");
gimp_procedure_set_documentation (procedure,
N_("Re-read all available Script-Fu scripts"),
"Re-read all available Script-Fu scripts",
"script-fu-refresh");
gimp_procedure_set_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997",
N_("_Refresh Scripts"),
NULL,
GIMP_TEMPORARY,
G_N_ELEMENTS (args), 0,
args, NULL,
script_fu_refresh_proc);
"1997");
gimp_plugin_menu_register ("script-fu-refresh",
"<Image>/Filters/Development/Script-Fu");
gimp_procedure_add_argument (procedure,
g_param_spec_enum ("run-mode",
"Run mode",
"The run mode",
GIMP_TYPE_RUN_MODE,
GIMP_RUN_INTERACTIVE,
G_PARAM_READWRITE));
gimp_plug_in_add_temp_procedure (plug_in, procedure);
g_object_unref (procedure);
}
static void
script_fu_refresh_proc (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals)
static GimpValueArray *
script_fu_refresh_proc (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data)
{
static GimpParam values[1];
GimpPDBStatusType status;
if (script_fu_interface_is_active ())
{
g_message (_("You can not use \"Refresh Scripts\" while a "
"Script-Fu dialog box is open. Please close "
"all Script-Fu windows and try again."));
status = GIMP_PDB_EXECUTION_ERROR;
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR,
NULL);
}
else
{
/* Reload all of the available scripts */
GList *path = script_fu_search_path ();
script_fu_find_scripts (path);
script_fu_find_scripts (gimp_procedure_get_plug_in (procedure), path);
g_list_free_full (path, (GDestroyNotify) g_object_unref);
status = GIMP_PDB_SUCCESS;
}
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
}