1997-11-25 06:05:25 +08:00
|
|
|
/* 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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
1999-05-29 09:28:24 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2004-11-17 23:24:07 +08:00
|
|
|
#include <glib.h> /* Include early for obscure Win32 build reasons */
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1999-04-26 03:30:31 +08:00
|
|
|
#include <sys/types.h>
|
1999-05-29 09:28:24 +08:00
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
#include <gtk/gtk.h>
|
1999-05-29 09:28:24 +08:00
|
|
|
|
2002-02-17 23:55:54 +08:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
1999-05-29 09:28:24 +08:00
|
|
|
|
2003-11-27 01:14:58 +08:00
|
|
|
#include "siod/siod.h"
|
|
|
|
|
2004-09-01 01:54:46 +08:00
|
|
|
#include "script-fu-types.h"
|
|
|
|
|
|
|
|
#include "script-fu-interface.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "script-fu-scripts.h"
|
2003-11-27 01:14:58 +08:00
|
|
|
#include "siod-wrapper.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-28 03:35:39 +08:00
|
|
|
#include "script-fu-intl.h"
|
2000-02-01 04:47:44 +08:00
|
|
|
|
1999-05-29 09:28:24 +08:00
|
|
|
|
2004-11-17 23:24:07 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gchar *pdb_name;
|
|
|
|
gchar *menu_path;
|
|
|
|
} SFMenu;
|
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* External functions
|
|
|
|
*/
|
2000-02-01 04:47:44 +08:00
|
|
|
extern long nlength (LISP obj);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local Functions
|
|
|
|
*/
|
|
|
|
|
2004-09-01 01:54:46 +08:00
|
|
|
static void script_fu_load_script (const GimpDatafileData *file_data,
|
|
|
|
gpointer user_data);
|
|
|
|
static gboolean script_fu_install_script (gpointer foo,
|
2004-11-18 09:57:13 +08:00
|
|
|
GList *scripts,
|
2004-09-01 01:54:46 +08:00
|
|
|
gpointer bar);
|
2004-11-17 23:24:07 +08:00
|
|
|
static void script_fu_install_menu (SFMenu *menu,
|
|
|
|
gpointer foo);
|
2004-09-01 01:54:46 +08:00
|
|
|
static gboolean script_fu_remove_script (gpointer foo,
|
2004-11-18 09:57:13 +08:00
|
|
|
GList *scripts,
|
2004-09-01 01:54:46 +08:00
|
|
|
gpointer bar);
|
|
|
|
static void script_fu_script_proc (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *params,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
|
|
|
|
|
|
|
static SFScript * script_fu_find_script (const gchar *script_name);
|
|
|
|
static void script_fu_free_script (SFScript *script);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2004-11-18 09:57:13 +08:00
|
|
|
static gint script_fu_menu_compare (gconstpointer a,
|
|
|
|
gconstpointer b);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables
|
|
|
|
*/
|
|
|
|
|
2004-11-20 22:55:51 +08:00
|
|
|
static GTree *script_tree = NULL;
|
2004-11-18 09:57:13 +08:00
|
|
|
static GList *script_menu_list = NULL;
|
2003-09-05 07:12:32 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function definitions
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2000-02-01 04:47:44 +08:00
|
|
|
script_fu_find_scripts (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-06-16 19:31:10 +08:00
|
|
|
gchar *path_str;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Make sure to clear any existing scripts */
|
2004-11-20 22:55:51 +08:00
|
|
|
if (script_tree != NULL)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-11-20 22:55:51 +08:00
|
|
|
g_tree_foreach (script_tree,
|
2003-09-05 07:12:32 +08:00
|
|
|
(GTraverseFunc) script_fu_remove_script,
|
2001-11-29 23:54:39 +08:00
|
|
|
NULL);
|
2004-11-20 22:55:51 +08:00
|
|
|
g_tree_destroy (script_tree);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2004-11-20 22:55:51 +08:00
|
|
|
script_tree = g_tree_new ((GCompareFunc) g_utf8_collate);
|
2000-05-08 06:04:51 +08:00
|
|
|
|
2000-08-01 08:38:38 +08:00
|
|
|
path_str = gimp_gimprc_query ("script-fu-path");
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-01 08:38:38 +08:00
|
|
|
if (path_str == NULL)
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-06-16 19:31:10 +08:00
|
|
|
gimp_datafiles_read_directories (path_str, G_FILE_TEST_IS_REGULAR,
|
|
|
|
script_fu_load_script,
|
|
|
|
NULL);
|
2000-11-08 22:35:50 +08:00
|
|
|
|
2000-08-01 08:38:38 +08:00
|
|
|
g_free (path_str);
|
2000-05-08 06:04:51 +08:00
|
|
|
|
2004-11-18 09:57:13 +08:00
|
|
|
/* Now that all scripts are read in and sorted, tell gimp about them */
|
2004-11-20 22:55:51 +08:00
|
|
|
g_tree_foreach (script_tree,
|
2003-09-05 07:12:32 +08:00
|
|
|
(GTraverseFunc) script_fu_install_script,
|
2001-11-29 23:54:39 +08:00
|
|
|
NULL);
|
2004-11-18 09:57:13 +08:00
|
|
|
|
|
|
|
script_menu_list = g_list_sort (script_menu_list,
|
|
|
|
(GCompareFunc) script_fu_menu_compare);
|
|
|
|
|
|
|
|
g_list_foreach (script_menu_list,
|
|
|
|
(GFunc) script_fu_install_menu,
|
|
|
|
NULL);
|
2004-11-17 23:24:07 +08:00
|
|
|
|
|
|
|
/* Now we are done with the list of menu entries */
|
2004-11-18 09:57:13 +08:00
|
|
|
g_list_free (script_menu_list);
|
2004-11-17 23:24:07 +08:00
|
|
|
script_menu_list = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LISP
|
|
|
|
script_fu_add_script (LISP a)
|
|
|
|
{
|
2000-08-08 05:30:35 +08:00
|
|
|
GimpParamDef *args;
|
2000-11-08 22:35:50 +08:00
|
|
|
SFScript *script;
|
|
|
|
gchar *val;
|
|
|
|
gint i;
|
2001-01-15 04:25:46 +08:00
|
|
|
guchar r, g, b;
|
2000-11-08 22:35:50 +08:00
|
|
|
LISP color_list;
|
|
|
|
LISP adj_list;
|
|
|
|
LISP brush_list;
|
|
|
|
LISP option_list;
|
|
|
|
gchar *s;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Check the length of a */
|
|
|
|
if (nlength (a) < 7)
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("Too few arguments to script-fu-register", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Create a new script */
|
2000-11-08 22:35:50 +08:00
|
|
|
script = g_new0 (SFScript, 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Find the script name */
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
script->script_name = g_strdup (val);
|
|
|
|
a = cdr (a);
|
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
/* transform the function name into a name containing "_" for each "-".
|
|
|
|
* this does not hurt anybody, yet improves the life of many... ;)
|
|
|
|
*/
|
|
|
|
script->pdb_name = g_strdup (val);
|
|
|
|
for (s = script->pdb_name; *s; s++)
|
|
|
|
if (*s == '-')
|
|
|
|
*s = '_';
|
|
|
|
|
2004-09-30 20:37:42 +08:00
|
|
|
/* Find the script menu_path */
|
1997-11-25 06:05:25 +08:00
|
|
|
val = get_c_string (car (a));
|
2004-09-30 20:37:42 +08:00
|
|
|
script->menu_path = g_strdup (val);
|
1997-11-25 06:05:25 +08:00
|
|
|
a = cdr (a);
|
|
|
|
|
|
|
|
/* Find the script help */
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
script->help = g_strdup (val);
|
|
|
|
a = cdr (a);
|
|
|
|
|
|
|
|
/* Find the script author */
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
script->author = g_strdup (val);
|
|
|
|
a = cdr (a);
|
|
|
|
|
|
|
|
/* Find the script copyright */
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
script->copyright = g_strdup (val);
|
|
|
|
a = cdr (a);
|
|
|
|
|
|
|
|
/* Find the script date */
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
script->date = g_strdup (val);
|
|
|
|
a = cdr (a);
|
|
|
|
|
|
|
|
/* Find the script image types */
|
|
|
|
if (TYPEP (a, tc_cons))
|
|
|
|
{
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
a = cdr (a);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val = get_c_string (a);
|
|
|
|
a = NIL;
|
|
|
|
}
|
|
|
|
script->img_types = g_strdup (val);
|
|
|
|
|
|
|
|
/* Check the supplied number of arguments */
|
|
|
|
script->num_args = nlength (a) / 3;
|
|
|
|
|
2004-09-01 01:54:46 +08:00
|
|
|
args = g_new0 (GimpParamDef, script->num_args + 1);
|
2001-01-22 04:06:26 +08:00
|
|
|
args[0].type = GIMP_PDB_INT32;
|
|
|
|
args[0].name = "run_mode";
|
1998-02-25 18:48:59 +08:00
|
|
|
args[0].description = "Interactive, non-interactive";
|
|
|
|
|
2004-09-01 01:54:46 +08:00
|
|
|
script->arg_types = g_new0 (SFArgType, script->num_args);
|
|
|
|
script->arg_labels = g_new0 (gchar *, script->num_args);
|
1999-10-21 20:37:18 +08:00
|
|
|
script->arg_defaults = g_new0 (SFArgValue, script->num_args);
|
|
|
|
script->arg_values = g_new0 (SFArgValue, script->num_args);
|
1998-02-25 18:48:59 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (script->num_args > 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < script->num_args; i++)
|
|
|
|
{
|
|
|
|
if (a != NIL)
|
|
|
|
{
|
|
|
|
if (!TYPEP (car (a), tc_flonum))
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: argument types must be integer values", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
script->arg_types[i] = get_c_long (car (a));
|
|
|
|
a = cdr (a);
|
|
|
|
}
|
|
|
|
else
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: missing type specifier", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (a != NIL)
|
|
|
|
{
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: argument labels must be strings", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
script->arg_labels[i] = g_strdup (get_c_string (car (a)));
|
|
|
|
a = cdr (a);
|
|
|
|
}
|
|
|
|
else
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: missing arguments label", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (a != NIL)
|
|
|
|
{
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
|
|
|
case SF_DRAWABLE:
|
|
|
|
case SF_LAYER:
|
|
|
|
case SF_CHANNEL:
|
|
|
|
if (!TYPEP (car (a), tc_flonum))
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: drawable defaults must be integer values", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
|
|
|
script->arg_defaults[i].sfa_image =
|
|
|
|
get_c_long (car (a));
|
|
|
|
script->arg_values[i].sfa_image =
|
|
|
|
script->arg_defaults[i].sfa_image;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_IMAGE;
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].name = "image";
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_DRAWABLE:
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_DRAWABLE;
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].name = "drawable";
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_LAYER:
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_LAYER;
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].name = "layer";
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_CHANNEL:
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_CHANNEL;
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].name = "channel";
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SF_COLOR:
|
|
|
|
if (!TYPEP (car (a), tc_cons))
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: color defaults must be a list of 3 integers", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
color_list = car (a);
|
2001-01-15 04:25:46 +08:00
|
|
|
r = CLAMP (get_c_long (car (color_list)), 0, 255);
|
1997-11-25 06:05:25 +08:00
|
|
|
color_list = cdr (color_list);
|
2001-01-15 04:25:46 +08:00
|
|
|
g = CLAMP (get_c_long (car (color_list)), 0, 255);
|
1997-11-25 06:05:25 +08:00
|
|
|
color_list = cdr (color_list);
|
2001-01-15 04:25:46 +08:00
|
|
|
b = CLAMP (get_c_long (car (color_list)), 0, 255);
|
2003-09-05 07:12:32 +08:00
|
|
|
|
|
|
|
gimp_rgb_set_uchar (&script->arg_defaults[i].sfa_color,
|
2001-01-15 04:25:46 +08:00
|
|
|
r, g, b);
|
2001-01-11 06:49:45 +08:00
|
|
|
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_values[i].sfa_color =
|
2001-01-11 06:49:45 +08:00
|
|
|
script->arg_defaults[i].sfa_color;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_COLOR;
|
|
|
|
args[i + 1].name = "color";
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SF_TOGGLE:
|
|
|
|
if (!TYPEP (car (a), tc_flonum))
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: toggle default must be an integer value", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_toggle =
|
2000-11-08 22:35:50 +08:00
|
|
|
(get_c_long (car (a))) ? TRUE : FALSE;
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_values[i].sfa_toggle =
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_toggle;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_INT32;
|
|
|
|
args[i + 1].name = "toggle";
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
2003-09-05 07:12:32 +08:00
|
|
|
case SF_VALUE:
|
1997-11-25 06:05:25 +08:00
|
|
|
if (!TYPEP (car (a), tc_string))
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: value defaults must be string values", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_value =
|
2000-11-08 22:35:50 +08:00
|
|
|
g_strdup (get_c_string (car (a)));
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_values[i].sfa_value =
|
2000-11-08 22:35:50 +08:00
|
|
|
g_strdup (script->arg_defaults[i].sfa_value);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
|
|
|
args[i + 1].name = "value";
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
1998-08-06 03:58:10 +08:00
|
|
|
|
|
|
|
case SF_STRING:
|
2004-09-24 02:19:24 +08:00
|
|
|
case SF_TEXT:
|
1998-08-06 03:58:10 +08:00
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: string defaults must be string values", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_value =
|
2000-11-08 22:35:50 +08:00
|
|
|
g_strdup (get_c_string (car (a)));
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_values[i].sfa_value =
|
2000-11-08 22:35:50 +08:00
|
|
|
g_strdup (script->arg_defaults[i].sfa_value);
|
1998-08-06 03:58:10 +08:00
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
|
|
|
args[i + 1].name = "string";
|
1998-08-06 03:58:10 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
case SF_ADJUSTMENT:
|
|
|
|
if (!TYPEP (car (a), tc_cons))
|
|
|
|
return my_err ("script-fu-register: adjustment defaults must be a list", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = car (a);
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.value =
|
2000-11-08 22:35:50 +08:00
|
|
|
get_c_double (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = cdr (adj_list);
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.lower =
|
2000-11-08 22:35:50 +08:00
|
|
|
get_c_double (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = cdr (adj_list);
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.upper =
|
2000-11-08 22:35:50 +08:00
|
|
|
get_c_double (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = cdr (adj_list);
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.step =
|
2000-11-08 22:35:50 +08:00
|
|
|
get_c_double (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = cdr (adj_list);
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.page =
|
2000-11-08 22:35:50 +08:00
|
|
|
get_c_double (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = cdr (adj_list);
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.digits =
|
2000-11-08 22:35:50 +08:00
|
|
|
get_c_long (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = cdr (adj_list);
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.type =
|
2000-11-08 22:35:50 +08:00
|
|
|
get_c_long (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
script->arg_values[i].sfa_adjustment.adj = NULL;
|
2004-09-01 21:51:51 +08:00
|
|
|
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_values[i].sfa_adjustment.value =
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.value;
|
1998-08-06 22:58:39 +08:00
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_FLOAT;
|
|
|
|
args[i + 1].name = "value";
|
1998-08-06 22:58:39 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
case SF_FILENAME:
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: filename defaults must be string values", NIL);
|
2001-11-22 02:50:50 +08:00
|
|
|
/* fallthrough */
|
2004-09-01 21:51:51 +08:00
|
|
|
|
2001-11-22 02:50:50 +08:00
|
|
|
case SF_DIRNAME:
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: dirname defaults must be string values", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_file.filename =
|
2000-11-08 22:35:50 +08:00
|
|
|
g_strdup (get_c_string (car (a)));
|
1999-05-29 09:28:24 +08:00
|
|
|
|
1999-10-05 03:26:07 +08:00
|
|
|
#ifdef G_OS_WIN32
|
1999-05-29 09:28:24 +08:00
|
|
|
/* Replace POSIX slashes with Win32 backslashes. This
|
|
|
|
* is just so script-fus can be written with only
|
|
|
|
* POSIX directory separators.
|
|
|
|
*/
|
|
|
|
val = script->arg_defaults[i].sfa_file.filename;
|
|
|
|
while (*val)
|
|
|
|
{
|
|
|
|
if (*val == '/')
|
|
|
|
*val = '\\';
|
|
|
|
val++;
|
|
|
|
}
|
|
|
|
#endif
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_values[i].sfa_file.filename =
|
2000-11-08 22:35:50 +08:00
|
|
|
g_strdup (script->arg_defaults[i].sfa_file.filename);
|
2003-11-21 23:53:57 +08:00
|
|
|
script->arg_values[i].sfa_file.file_entry = NULL;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
|
|
|
args[i + 1].name = (script->arg_types[i] == SF_FILENAME ?
|
|
|
|
"filename" : "dirname");
|
1999-05-19 01:33:39 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
1998-11-06 08:51:39 +08:00
|
|
|
break;
|
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
case SF_FONT:
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: font defaults must be string values", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
2003-03-28 22:13:54 +08:00
|
|
|
script->arg_defaults[i].sfa_font =
|
|
|
|
g_strdup (get_c_string (car (a)));
|
|
|
|
script->arg_values[i].sfa_font =
|
|
|
|
g_strdup (script->arg_defaults[i].sfa_font);
|
2003-09-05 07:12:32 +08:00
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
|
|
|
args[i + 1].name = "font";
|
1998-08-10 23:06:58 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2004-07-27 23:15:58 +08:00
|
|
|
case SF_PALETTE:
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: palette defaults must be string values", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
2004-07-27 23:15:58 +08:00
|
|
|
script->arg_defaults[i].sfa_palette =
|
|
|
|
g_strdup (get_c_string (car (a)));
|
|
|
|
script->arg_values[i].sfa_palette =
|
|
|
|
g_strdup (script->arg_defaults[i].sfa_palette);
|
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
|
|
|
args[i + 1].name = "palette";
|
2004-07-27 23:15:58 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
1998-10-02 06:09:01 +08:00
|
|
|
case SF_PATTERN:
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: pattern defaults must be string values", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_pattern =
|
2000-11-08 22:35:50 +08:00
|
|
|
g_strdup (get_c_string (car (a)));
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_values[i].sfa_pattern =
|
2000-11-08 22:35:50 +08:00
|
|
|
g_strdup (script->arg_defaults[i].sfa_pattern);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
|
|
|
args[i + 1].name = "pattern";
|
1998-10-02 06:09:01 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
case SF_BRUSH:
|
|
|
|
if (!TYPEP (car (a), tc_cons))
|
|
|
|
return my_err ("script-fu-register: brush defaults must be a list", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
brush_list = car (a);
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_brush.name =
|
2000-11-08 22:35:50 +08:00
|
|
|
g_strdup (get_c_string (car (brush_list)));
|
2004-09-01 01:54:46 +08:00
|
|
|
script->arg_values[i].sfa_brush.name =
|
|
|
|
g_strdup (script->arg_defaults[i].sfa_brush.name);
|
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
brush_list = cdr (brush_list);
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_brush.opacity =
|
2000-11-08 22:35:50 +08:00
|
|
|
get_c_double (car (brush_list));
|
2004-09-01 01:54:46 +08:00
|
|
|
script->arg_values[i].sfa_brush.opacity =
|
|
|
|
script->arg_defaults[i].sfa_brush.opacity;
|
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
brush_list = cdr (brush_list);
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_brush.spacing =
|
2000-11-08 22:35:50 +08:00
|
|
|
get_c_long (car (brush_list));
|
2004-09-01 01:54:46 +08:00
|
|
|
script->arg_values[i].sfa_brush.spacing =
|
|
|
|
script->arg_defaults[i].sfa_brush.spacing;
|
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
brush_list = cdr (brush_list);
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_brush.paint_mode =
|
2000-11-08 22:35:50 +08:00
|
|
|
get_c_long (car (brush_list));
|
2004-09-01 01:54:46 +08:00
|
|
|
script->arg_values[i].sfa_brush.paint_mode =
|
|
|
|
script->arg_defaults[i].sfa_brush.paint_mode;
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
|
|
|
args[i + 1].name = "brush";
|
1998-10-21 06:36:52 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
1998-08-10 23:06:58 +08:00
|
|
|
break;
|
1998-10-21 06:36:52 +08:00
|
|
|
|
1998-11-01 00:22:37 +08:00
|
|
|
case SF_GRADIENT:
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: gradient defaults must be string values", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_gradient =
|
2000-11-08 22:35:50 +08:00
|
|
|
g_strdup (get_c_string (car (a)));
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_values[i].sfa_gradient =
|
2000-11-08 22:35:50 +08:00
|
|
|
g_strdup (script->arg_defaults[i].sfa_pattern);
|
2003-09-05 07:12:32 +08:00
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
|
|
|
args[i + 1].name = "gradient";
|
1998-11-01 00:22:37 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
case SF_OPTION:
|
|
|
|
if (!TYPEP (car (a), tc_cons))
|
|
|
|
return my_err ("script-fu-register: option defaults must be a list", NIL);
|
2004-09-01 21:51:51 +08:00
|
|
|
|
2003-09-05 07:12:32 +08:00
|
|
|
for (option_list = car (a);
|
|
|
|
option_list;
|
2000-11-08 22:35:50 +08:00
|
|
|
option_list = cdr (option_list))
|
2000-04-28 08:02:11 +08:00
|
|
|
{
|
2003-09-05 07:12:32 +08:00
|
|
|
script->arg_defaults[i].sfa_option.list =
|
|
|
|
g_slist_append (script->arg_defaults[i].sfa_option.list,
|
2000-04-28 08:02:11 +08:00
|
|
|
g_strdup (get_c_string (car (option_list))));
|
|
|
|
}
|
|
|
|
script->arg_defaults[i].sfa_option.history = 0;
|
|
|
|
script->arg_values[i].sfa_option.history = 0;
|
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_INT32;
|
|
|
|
args[i + 1].name = "option";
|
2000-04-28 08:02:11 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
a = cdr (a);
|
|
|
|
}
|
|
|
|
else
|
2004-09-01 21:51:51 +08:00
|
|
|
{
|
|
|
|
return my_err ("script-fu-register: missing default argument",
|
|
|
|
NIL);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-08 06:04:51 +08:00
|
|
|
script->args = args;
|
2004-11-18 09:57:13 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
gchar *key = gettext (script->menu_path);
|
2004-11-20 22:55:51 +08:00
|
|
|
GList *list = g_tree_lookup (script_tree, key);
|
2004-11-18 09:57:13 +08:00
|
|
|
|
2004-11-20 22:55:51 +08:00
|
|
|
g_tree_insert (script_tree, key, g_list_append (list, script));
|
2004-11-18 09:57:13 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return NIL;
|
|
|
|
}
|
|
|
|
|
2004-11-17 23:24:07 +08:00
|
|
|
LISP
|
|
|
|
script_fu_add_menu (LISP a)
|
|
|
|
{
|
|
|
|
SFMenu *menu;
|
|
|
|
gchar *val;
|
|
|
|
gchar *s;
|
|
|
|
|
|
|
|
/* Check the length of a */
|
|
|
|
if (nlength (a) != 2)
|
|
|
|
return my_err ("Incorrect number of arguments for script-fu-menu-register",
|
|
|
|
NIL);
|
|
|
|
|
|
|
|
/* Create a new list of menus */
|
|
|
|
menu = g_new0 (SFMenu, 1);
|
|
|
|
|
|
|
|
/* Find the script PDB entry name */
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
menu->pdb_name = g_strdup (val);
|
|
|
|
for (s = menu->pdb_name; *s; s++)
|
|
|
|
if (*s == '-')
|
|
|
|
*s = '_';
|
|
|
|
a = cdr (a);
|
|
|
|
|
|
|
|
/* Find the script menu path */
|
|
|
|
val = get_c_string (car (a));
|
2004-11-18 09:57:13 +08:00
|
|
|
menu->menu_path = g_strdup (val);
|
2004-11-17 23:24:07 +08:00
|
|
|
|
2004-11-18 09:57:13 +08:00
|
|
|
script_menu_list = g_list_prepend (script_menu_list, menu);
|
2004-11-17 23:24:07 +08:00
|
|
|
|
|
|
|
return NIL;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
2004-09-01 01:54:46 +08:00
|
|
|
script_fu_error_msg (const gchar *command)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-09-01 01:54:46 +08:00
|
|
|
g_message (_("Error while executing\n%s\n%s"),
|
|
|
|
command, siod_get_error_msg ());
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-05-08 06:04:51 +08:00
|
|
|
|
2003-06-16 19:31:10 +08:00
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2003-07-03 01:11:00 +08:00
|
|
|
script_fu_load_script (const GimpDatafileData *file_data,
|
|
|
|
gpointer user_data)
|
2003-06-16 19:31:10 +08:00
|
|
|
{
|
|
|
|
if (gimp_datafiles_check_extension (file_data->filename, ".scm"))
|
|
|
|
{
|
|
|
|
gchar *command;
|
2004-09-01 21:51:51 +08:00
|
|
|
gchar *escaped = g_strescape (file_data->filename, NULL);
|
2003-06-16 19:31:10 +08:00
|
|
|
|
2004-09-01 21:51:51 +08:00
|
|
|
command = g_strdup_printf ("(load \"%s\")", escaped);
|
|
|
|
g_free (escaped);
|
2003-06-16 19:31:10 +08:00
|
|
|
|
|
|
|
if (repl_c_string (command, 0, 0, 1) != 0)
|
|
|
|
script_fu_error_msg (command);
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
2003-09-05 07:12:32 +08:00
|
|
|
/* No, I don't know why, but this is
|
2003-06-16 19:31:10 +08:00
|
|
|
* necessary on NT 4.0.
|
|
|
|
*/
|
2004-11-17 23:24:07 +08:00
|
|
|
Sleep (0);
|
2003-06-16 19:31:10 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
g_free (command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-05 07:12:32 +08:00
|
|
|
/*
|
|
|
|
* The following function is a GTraverseFunction. Please
|
|
|
|
* note that it frees the script->args structure. --Sven
|
2000-05-08 06:04:51 +08:00
|
|
|
*/
|
2001-01-22 04:06:26 +08:00
|
|
|
static gboolean
|
2000-05-08 06:04:51 +08:00
|
|
|
script_fu_install_script (gpointer foo,
|
2004-11-18 09:57:13 +08:00
|
|
|
GList *scripts,
|
2000-05-08 06:04:51 +08:00
|
|
|
gpointer bar)
|
|
|
|
{
|
2004-11-18 09:57:13 +08:00
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = scripts; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
SFScript *script = list->data;
|
|
|
|
gchar *menu_path = NULL;
|
|
|
|
|
|
|
|
/* Allow scripts with no menus */
|
|
|
|
if (strncmp (script->menu_path, "<None>", 6) != 0)
|
|
|
|
menu_path = script->menu_path;
|
|
|
|
|
|
|
|
gimp_install_temp_proc (script->pdb_name,
|
|
|
|
script->help,
|
|
|
|
"",
|
|
|
|
script->author,
|
|
|
|
script->copyright,
|
|
|
|
script->date,
|
|
|
|
menu_path,
|
|
|
|
script->img_types,
|
|
|
|
GIMP_TEMPORARY,
|
|
|
|
script->num_args + 1, 0,
|
|
|
|
script->args, NULL,
|
|
|
|
script_fu_script_proc);
|
|
|
|
|
|
|
|
g_free (script->args);
|
|
|
|
script->args = NULL;
|
|
|
|
}
|
2000-05-08 06:04:51 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-11-17 23:24:07 +08:00
|
|
|
/*
|
|
|
|
* The following function is a GFunc.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
script_fu_install_menu (SFMenu *menu,
|
|
|
|
gpointer foo)
|
|
|
|
{
|
|
|
|
gimp_plugin_menu_register (menu->pdb_name, menu->menu_path);
|
|
|
|
|
|
|
|
g_free (menu->pdb_name);
|
|
|
|
g_free (menu->menu_path);
|
|
|
|
g_free (menu);
|
|
|
|
}
|
|
|
|
|
2003-09-05 07:12:32 +08:00
|
|
|
/*
|
2000-05-08 06:04:51 +08:00
|
|
|
* The following function is a GTraverseFunction.
|
|
|
|
*/
|
2001-01-22 04:06:26 +08:00
|
|
|
static gboolean
|
2000-05-08 06:04:51 +08:00
|
|
|
script_fu_remove_script (gpointer foo,
|
2004-11-18 09:57:13 +08:00
|
|
|
GList *scripts,
|
2000-05-08 06:04:51 +08:00
|
|
|
gpointer bar)
|
|
|
|
{
|
2004-11-18 09:57:13 +08:00
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = scripts; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
SFScript *script = list->data;
|
|
|
|
|
|
|
|
script_fu_free_script (script);
|
|
|
|
}
|
|
|
|
|
2004-11-20 22:55:51 +08:00
|
|
|
g_list_free (scripts);
|
2000-05-08 06:04:51 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2003-07-02 08:15:09 +08:00
|
|
|
script_fu_script_proc (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *params,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-05-25 03:44:37 +08:00
|
|
|
static GimpParam values[1];
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
SFScript *script;
|
|
|
|
gint min_args;
|
|
|
|
gchar *escaped;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
run_mode = params[0].data.d_int32;
|
|
|
|
|
|
|
|
if (! (script = script_fu_find_script (name)))
|
2001-01-22 04:06:26 +08:00
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
1998-02-25 18:48:59 +08:00
|
|
|
if (script->num_args == 0)
|
2000-08-22 11:27:14 +08:00
|
|
|
run_mode = GIMP_RUN_NONINTERACTIVE;
|
1998-02-25 18:48:59 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
switch (run_mode)
|
|
|
|
{
|
2000-08-22 11:27:14 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2000-11-08 22:35:50 +08:00
|
|
|
/* Determine whether the script is image based (runs on an image) */
|
2004-09-30 20:37:42 +08:00
|
|
|
if (strncmp (script->menu_path, "<Image>", 7) == 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-04-28 08:02:11 +08:00
|
|
|
script->arg_values[0].sfa_image = params[1].data.d_image;
|
1997-11-25 06:05:25 +08:00
|
|
|
script->arg_values[1].sfa_drawable = params[2].data.d_drawable;
|
|
|
|
script->image_based = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
script->image_based = FALSE;
|
|
|
|
|
|
|
|
/* First acquire information with a dialog */
|
2003-09-05 07:12:32 +08:00
|
|
|
/* Skip this part if the script takes no parameters */
|
1998-01-25 17:29:29 +08:00
|
|
|
min_args = (script->image_based) ? 2 : 0;
|
2003-09-05 07:12:32 +08:00
|
|
|
if (script->num_args > min_args)
|
1999-10-21 20:37:18 +08:00
|
|
|
{
|
2003-09-05 07:12:32 +08:00
|
|
|
script_fu_interface (script);
|
1999-10-21 20:37:18 +08:00
|
|
|
break;
|
2003-09-05 07:12:32 +08:00
|
|
|
}
|
2000-11-08 22:35:50 +08:00
|
|
|
/* else fallthrough */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 11:27:14 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Make sure all the arguments are there! */
|
|
|
|
if (nparams != (script->num_args + 1))
|
2004-08-30 22:57:24 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
|
2000-08-22 11:27:14 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-09-02 21:04:47 +08:00
|
|
|
GString *s;
|
|
|
|
gchar *command;
|
|
|
|
gchar buffer[G_ASCII_DTOSTR_BUF_SIZE];
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
s = g_string_new ("(");
|
|
|
|
g_string_append (s, script->script_name);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-02-25 18:48:59 +08:00
|
|
|
if (script->num_args)
|
1999-12-06 04:48:06 +08:00
|
|
|
{
|
|
|
|
for (i = 0; i < script->num_args; i++)
|
|
|
|
{
|
2004-09-02 21:04:47 +08:00
|
|
|
const GimpParam *param = ¶ms[i + 1];
|
|
|
|
|
|
|
|
g_string_append_c (s, ' ');
|
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
|
|
|
case SF_DRAWABLE:
|
|
|
|
case SF_LAYER:
|
|
|
|
case SF_CHANNEL:
|
2004-09-02 21:04:47 +08:00
|
|
|
g_string_append_printf (s, "%d", param->data.d_image);
|
1999-12-06 04:48:06 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_COLOR:
|
2004-09-02 21:04:47 +08:00
|
|
|
{
|
|
|
|
guchar r, g, b;
|
|
|
|
|
|
|
|
gimp_rgb_get_uchar (¶m->data.d_color,
|
|
|
|
&r, &g, &b);
|
|
|
|
g_string_append_printf (s, "'(%d %d %d)",
|
|
|
|
(gint) r, (gint) g,
|
|
|
|
(gint) b);
|
|
|
|
}
|
1999-12-06 04:48:06 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_TOGGLE:
|
2004-09-02 21:04:47 +08:00
|
|
|
g_string_append_printf (s, (param->data.d_int32 ?
|
|
|
|
"TRUE" : "FALSE"));
|
1999-12-06 04:48:06 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_VALUE:
|
2004-09-02 21:04:47 +08:00
|
|
|
g_string_append (s, param->data.d_string);
|
1999-12-06 04:48:06 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_STRING:
|
2004-09-24 02:19:24 +08:00
|
|
|
case SF_TEXT:
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_FILENAME:
|
2001-11-22 02:50:50 +08:00
|
|
|
case SF_DIRNAME:
|
2004-09-02 21:04:47 +08:00
|
|
|
escaped = g_strescape (param->data.d_string, NULL);
|
|
|
|
g_string_append_printf (s, "\"%s\"", escaped);
|
1999-12-06 04:48:06 +08:00
|
|
|
g_free (escaped);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_ADJUSTMENT:
|
2004-09-02 21:04:47 +08:00
|
|
|
g_ascii_dtostr (buffer, sizeof (buffer),
|
|
|
|
param->data.d_float);
|
|
|
|
g_string_append (s, buffer);
|
1999-12-06 04:48:06 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_FONT:
|
2004-07-27 23:15:58 +08:00
|
|
|
case SF_PALETTE:
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_PATTERN:
|
|
|
|
case SF_GRADIENT:
|
|
|
|
case SF_BRUSH:
|
2004-09-02 21:04:47 +08:00
|
|
|
g_string_append_printf (s, "\"%s\"",
|
|
|
|
param->data.d_string);
|
1999-12-06 04:48:06 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
case SF_OPTION:
|
2004-09-02 21:04:47 +08:00
|
|
|
g_string_append_printf (s, "%d",
|
|
|
|
param->data.d_int32);
|
2000-04-28 08:02:11 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-02 21:04:47 +08:00
|
|
|
|
|
|
|
g_string_append_c (s, ')');
|
|
|
|
|
|
|
|
command = g_string_free (s, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* run the command through the interpreter */
|
2000-11-08 22:35:50 +08:00
|
|
|
if (repl_c_string (command, 0, 0, 1) != 0)
|
|
|
|
script_fu_error_msg (command);
|
2003-09-05 07:12:32 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (command);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
2004-08-30 22:57:24 +08:00
|
|
|
*return_vals = values;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-30 22:57:24 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
1997-11-25 06:05:25 +08:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
}
|
|
|
|
|
2000-05-08 06:04:51 +08:00
|
|
|
/* this is a GTraverseFunction */
|
2001-01-22 04:06:26 +08:00
|
|
|
static gboolean
|
2003-07-02 19:07:41 +08:00
|
|
|
script_fu_lookup_script (gpointer *foo,
|
2004-11-18 09:57:13 +08:00
|
|
|
GList *scripts,
|
2003-07-02 19:07:41 +08:00
|
|
|
gconstpointer *name)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-11-18 09:57:13 +08:00
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = scripts; list; list = g_list_next (list))
|
2003-09-05 07:12:32 +08:00
|
|
|
{
|
2004-11-18 09:57:13 +08:00
|
|
|
SFScript *script = list->data;
|
|
|
|
|
|
|
|
if (strcmp (script->pdb_name, *name) == 0)
|
|
|
|
{
|
|
|
|
/* store the script in the name pointer and stop the traversal */
|
|
|
|
*name = script;
|
|
|
|
return TRUE;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2004-09-01 21:51:51 +08:00
|
|
|
|
|
|
|
return FALSE;
|
2000-05-08 06:04:51 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-08 06:04:51 +08:00
|
|
|
static SFScript *
|
2003-07-02 19:07:41 +08:00
|
|
|
script_fu_find_script (const gchar *pdb_name)
|
2000-05-08 06:04:51 +08:00
|
|
|
{
|
2003-07-02 19:07:41 +08:00
|
|
|
gconstpointer script = pdb_name;
|
|
|
|
|
2004-11-20 22:55:51 +08:00
|
|
|
g_tree_foreach (script_tree,
|
2003-09-05 07:12:32 +08:00
|
|
|
(GTraverseFunc) script_fu_lookup_script,
|
2001-11-29 23:54:39 +08:00
|
|
|
&script);
|
2001-01-22 04:06:26 +08:00
|
|
|
|
2000-05-08 06:04:51 +08:00
|
|
|
if (script == pdb_name)
|
|
|
|
return NULL;
|
2004-09-01 21:51:51 +08:00
|
|
|
|
|
|
|
return (SFScript *) script;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
script_fu_free_script (SFScript *script)
|
|
|
|
{
|
2000-04-28 08:02:11 +08:00
|
|
|
gint i;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Uninstall the temporary procedure for this script */
|
2004-02-03 19:37:03 +08:00
|
|
|
gimp_uninstall_temp_proc (script->pdb_name);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (script)
|
|
|
|
{
|
|
|
|
g_free (script->script_name);
|
2004-09-30 20:37:42 +08:00
|
|
|
g_free (script->menu_path);
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (script->help);
|
|
|
|
g_free (script->author);
|
|
|
|
g_free (script->copyright);
|
|
|
|
g_free (script->date);
|
|
|
|
g_free (script->img_types);
|
|
|
|
|
|
|
|
for (i = 0; i < script->num_args; i++)
|
|
|
|
{
|
|
|
|
g_free (script->arg_labels[i]);
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
|
|
|
case SF_DRAWABLE:
|
|
|
|
case SF_LAYER:
|
|
|
|
case SF_CHANNEL:
|
|
|
|
case SF_COLOR:
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_VALUE:
|
1998-08-10 23:06:58 +08:00
|
|
|
case SF_STRING:
|
2004-09-24 02:19:24 +08:00
|
|
|
case SF_TEXT:
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (script->arg_defaults[i].sfa_value);
|
1998-08-09 20:17:51 +08:00
|
|
|
g_free (script->arg_values[i].sfa_value);
|
1998-08-06 03:58:10 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
case SF_ADJUSTMENT:
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
case SF_FILENAME:
|
2001-11-22 02:50:50 +08:00
|
|
|
case SF_DIRNAME:
|
1998-11-06 08:51:39 +08:00
|
|
|
g_free (script->arg_defaults[i].sfa_file.filename);
|
|
|
|
g_free (script->arg_values[i].sfa_file.filename);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
case SF_FONT:
|
2003-03-28 22:13:54 +08:00
|
|
|
g_free (script->arg_defaults[i].sfa_font);
|
|
|
|
g_free (script->arg_values[i].sfa_font);
|
1998-08-10 23:06:58 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
2004-07-27 23:15:58 +08:00
|
|
|
case SF_PALETTE:
|
|
|
|
g_free (script->arg_defaults[i].sfa_palette);
|
|
|
|
g_free (script->arg_values[i].sfa_palette);
|
|
|
|
break;
|
|
|
|
|
1998-10-02 06:09:01 +08:00
|
|
|
case SF_PATTERN:
|
|
|
|
g_free (script->arg_defaults[i].sfa_pattern);
|
|
|
|
g_free (script->arg_values[i].sfa_pattern);
|
1998-10-21 06:36:52 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-11-01 00:22:37 +08:00
|
|
|
case SF_GRADIENT:
|
|
|
|
g_free (script->arg_defaults[i].sfa_gradient);
|
|
|
|
g_free (script->arg_values[i].sfa_gradient);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
case SF_BRUSH:
|
|
|
|
g_free (script->arg_defaults[i].sfa_brush.name);
|
|
|
|
g_free (script->arg_values[i].sfa_brush.name);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
case SF_OPTION:
|
2003-09-05 07:12:32 +08:00
|
|
|
g_slist_foreach (script->arg_defaults[i].sfa_option.list,
|
2004-08-31 22:20:38 +08:00
|
|
|
(GFunc) g_free, NULL);
|
|
|
|
g_slist_free (script->arg_defaults[i].sfa_option.list);
|
2000-04-28 08:02:11 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (script->arg_labels);
|
|
|
|
g_free (script->arg_defaults);
|
2004-07-29 06:39:49 +08:00
|
|
|
g_free (script->arg_types);
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (script->arg_values);
|
|
|
|
|
|
|
|
g_free (script);
|
|
|
|
}
|
|
|
|
}
|
2004-11-18 09:57:13 +08:00
|
|
|
|
|
|
|
static gint
|
|
|
|
script_fu_menu_compare (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
2004-11-20 06:13:58 +08:00
|
|
|
const SFMenu *menu_a = a;
|
|
|
|
const SFMenu *menu_b = b;
|
|
|
|
|
|
|
|
if (menu_a->menu_path && menu_b->menu_path)
|
2004-11-21 01:18:37 +08:00
|
|
|
return g_utf8_collate (gettext (menu_a->menu_path),
|
|
|
|
gettext (menu_b->menu_path));
|
2004-11-20 06:13:58 +08:00
|
|
|
|
|
|
|
return 0;
|
2004-11-18 09:57:13 +08:00
|
|
|
}
|