2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-24 22:05:25 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-24 22:05:25 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-24 22:05:25 +00:00
|
|
|
* (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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
|
|
|
|
1999-05-29 01:28:24 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
#include <string.h>
|
2005-03-04 13:23:32 +00:00
|
|
|
#include <glib.h>
|
1999-05-29 01:28:24 +00:00
|
|
|
|
2002-02-17 15:55:54 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2000-01-31 20:47:44 +00:00
|
|
|
#include <libgimp/gimp.h>
|
1999-05-29 01:28:24 +00:00
|
|
|
|
2006-10-16 01:08:54 +00:00
|
|
|
#include "tinyscheme/scheme-private.h"
|
2006-10-19 13:08:47 +00:00
|
|
|
|
2004-08-31 17:54:46 +00:00
|
|
|
#include "script-fu-types.h"
|
2008-09-17 21:39:44 +00:00
|
|
|
#include "script-fu-script.h"
|
1997-11-24 22:05:25 +00:00
|
|
|
#include "script-fu-scripts.h"
|
2008-09-20 09:58:30 +00:00
|
|
|
#include "script-fu-utils.h"
|
2022-07-15 13:50:36 -04:00
|
|
|
#include "script-fu-register.h"
|
|
|
|
#include "script-fu-command.h"
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2000-02-27 19:35:39 +00:00
|
|
|
#include "script-fu-intl.h"
|
2000-01-31 20:47:44 +00:00
|
|
|
|
2007-09-07 14:43:26 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
/*
|
|
|
|
* Local Functions
|
|
|
|
*/
|
|
|
|
|
2019-08-12 20:11:45 +02:00
|
|
|
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 data);
|
|
|
|
static void script_fu_install_menu (SFMenu *menu);
|
|
|
|
static gboolean script_fu_remove_script (gpointer foo,
|
|
|
|
GList *scripts,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static gchar * script_fu_menu_map (const gchar *menu_path);
|
|
|
|
static gint script_fu_menu_compare (gconstpointer a,
|
|
|
|
gconstpointer b);
|
2004-11-18 01:57:13 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
static void script_fu_try_map_menu (SFScript *script);
|
|
|
|
static void script_fu_append_script_to_tree (SFScript *script);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables
|
|
|
|
*/
|
|
|
|
|
2004-11-20 14:55:51 +00:00
|
|
|
static GTree *script_tree = NULL;
|
2004-11-18 01:57:13 +00:00
|
|
|
static GList *script_menu_list = NULL;
|
2003-09-04 23:12:32 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function definitions
|
|
|
|
*/
|
|
|
|
|
2022-06-19 16:03:06 -04:00
|
|
|
/* Traverse list of paths, finding .scm files.
|
|
|
|
* Load and eval any found script texts.
|
2022-07-15 13:50:36 -04:00
|
|
|
* Script texts will call Scheme functions script-fu-register
|
|
|
|
* and script-fu-menu-register,
|
2022-06-19 16:03:06 -04:00
|
|
|
* which insert a SFScript record into script_tree,
|
|
|
|
* and insert a SFMenu record into script_menu_list.
|
|
|
|
* These are side effects on the state of the outer (SF) interpreter.
|
|
|
|
*
|
|
|
|
* Return the tree of scripts, as well as keeping a local pointer to the tree.
|
2022-07-15 13:50:36 -04:00
|
|
|
* The other result (script_menu_list) is not returned, see script_fu_get_menu_list.
|
2022-06-19 16:03:06 -04:00
|
|
|
*
|
|
|
|
* Caller should free script_tree and script_menu_list,
|
|
|
|
* This should only be called once.
|
|
|
|
*/
|
|
|
|
GTree *
|
|
|
|
script_fu_find_scripts_into_tree ( GimpPlugIn *plug_in,
|
|
|
|
GList *paths)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2022-06-19 16:03:06 -04:00
|
|
|
/* Clear any existing scripts */
|
2004-11-20 14:55:51 +00:00
|
|
|
if (script_tree != NULL)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2004-11-20 14:55:51 +00:00
|
|
|
g_tree_foreach (script_tree,
|
2003-09-04 23:12:32 +00:00
|
|
|
(GTraverseFunc) script_fu_remove_script,
|
2019-08-12 20:11:45 +02:00
|
|
|
plug_in);
|
2004-11-20 14:55:51 +00:00
|
|
|
g_tree_destroy (script_tree);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2006-10-19 13:51:42 +00:00
|
|
|
script_tree = g_tree_new ((GCompareFunc) g_utf8_collate);
|
2005-03-04 16:27:59 +00:00
|
|
|
|
2022-06-19 16:03:06 -04:00
|
|
|
if (paths)
|
2014-08-03 21:49:20 +02:00
|
|
|
{
|
2022-06-19 16:03:06 -04:00
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = paths; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
script_fu_load_directory (list->data);
|
|
|
|
}
|
2014-08-03 21:49:20 +02:00
|
|
|
}
|
2000-11-08 14:35:50 +00:00
|
|
|
|
2022-06-19 16:03:06 -04:00
|
|
|
/*
|
|
|
|
* Assert result is not NULL, but may be an empty tree.
|
|
|
|
* When paths is NULL, or no scripts found at paths.
|
|
|
|
*/
|
|
|
|
|
|
|
|
g_debug ("script_fu_find_scripts_into_tree found %i scripts", g_tree_nnodes (script_tree));
|
|
|
|
return script_tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return list of SFMenu for recently loaded scripts.
|
2022-07-15 13:50:36 -04:00
|
|
|
* List is non-empty only after a call to script_fu_find_scripts_into_tree.
|
2022-06-19 16:03:06 -04:00
|
|
|
*/
|
|
|
|
GList *
|
|
|
|
script_fu_get_menu_list (void)
|
|
|
|
{
|
|
|
|
return script_menu_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find scripts, create and install TEMPORARY PDB procedures,
|
|
|
|
* owned by self PDB procedure (e.g. extension-script-fu.)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
script_fu_find_scripts (GimpPlugIn *plug_in,
|
|
|
|
GList *path)
|
|
|
|
{
|
|
|
|
script_fu_find_scripts_into_tree (plug_in, path);
|
|
|
|
|
2004-11-18 01:57:13 +00:00
|
|
|
/* Now that all scripts are read in and sorted, tell gimp about them */
|
2004-11-20 14:55:51 +00:00
|
|
|
g_tree_foreach (script_tree,
|
2003-09-04 23:12:32 +00:00
|
|
|
(GTraverseFunc) script_fu_install_script,
|
2019-08-12 20:11:45 +02:00
|
|
|
plug_in);
|
2004-11-18 01:57:13 +00:00
|
|
|
|
|
|
|
script_menu_list = g_list_sort (script_menu_list,
|
|
|
|
(GCompareFunc) script_fu_menu_compare);
|
|
|
|
|
2011-03-07 17:10:18 +01:00
|
|
|
/* Install and nuke the list of menu entries */
|
|
|
|
g_list_free_full (script_menu_list,
|
|
|
|
(GDestroyNotify) script_fu_install_menu);
|
2004-11-17 15:24:07 +00:00
|
|
|
script_menu_list = NULL;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* For a script's call to script-fu-register.
|
|
|
|
* Traverse Scheme argument list creating a new SFScript
|
|
|
|
* whose drawable_arity is SF_PROC_ORDINARY.
|
|
|
|
*
|
|
|
|
* Return NIL or a foreign_error
|
|
|
|
*/
|
2006-10-16 01:08:54 +00:00
|
|
|
pointer
|
2008-04-09 08:54:01 +00:00
|
|
|
script_fu_add_script (scheme *sc,
|
|
|
|
pointer a)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2008-09-17 21:39:44 +00:00
|
|
|
SFScript *script;
|
2022-07-15 13:50:36 -04:00
|
|
|
pointer args_error;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
/* Check metadata args args are present */
|
2006-10-16 01:08:54 +00:00
|
|
|
if (sc->vptr->list_length (sc, a) < 7)
|
2022-07-15 13:50:36 -04:00
|
|
|
return foreign_error (sc, "script-fu-register: Not enough arguments", 0);
|
2008-09-17 21:39:44 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
/* pass handle to pointer into script (on the stack) */
|
|
|
|
script = script_fu_script_new_from_metadata_args (sc, &a);
|
2008-09-17 21:39:44 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
/* Require drawable_arity defaults to SF_PROC_ORDINARY.
|
|
|
|
* script-fu-register specifies an ordinary GimpProcedure.
|
|
|
|
* We may go on to infer a different arity.
|
|
|
|
*/
|
|
|
|
g_assert (script->drawable_arity == SF_NO_DRAWABLE);
|
2008-09-17 21:39:44 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
args_error = script_fu_script_create_formal_args (sc, &a, script);
|
|
|
|
if (args_error != sc->NIL)
|
|
|
|
return args_error;
|
2001-01-10 22:49:45 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
/* fill all values from defaults */
|
|
|
|
script_fu_script_reset (script, TRUE);
|
2008-09-17 21:39:44 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
/* Infer whether the script really requires one drawable,
|
|
|
|
* so that later we can set the sensitivity.
|
|
|
|
* For backward compatibility:
|
|
|
|
* v2 script-fu-register does not require author to declare drawable arity.
|
|
|
|
*/
|
|
|
|
script_fu_script_infer_drawable_arity (script);
|
2008-09-17 21:39:44 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
script->proc_class = GIMP_TYPE_PROCEDURE;
|
2008-09-17 21:39:44 +00:00
|
|
|
|
2024-09-21 12:03:42 -04:00
|
|
|
script_fu_script_set_is_old_style (script);
|
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
script_fu_try_map_menu (script);
|
|
|
|
script_fu_append_script_to_tree (script);
|
|
|
|
return sc->NIL;
|
|
|
|
}
|
1999-05-29 01:28:24 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
/* For a script's call to script-fu-register-filter.
|
|
|
|
* Traverse Scheme argument list creating a new SFScript
|
|
|
|
* whose drawable_arity is SF_PROC_IMAGE_MULTIPLE_DRAWABLE or
|
|
|
|
* SF_PROC_IMAGE_SINGLE_DRAWABLE
|
|
|
|
*
|
|
|
|
* Same as script-fu-register, except one more arg for drawable_arity.
|
|
|
|
*
|
|
|
|
* Return NIL or a foreign_error
|
|
|
|
*/
|
|
|
|
pointer
|
|
|
|
script_fu_add_script_filter (scheme *sc,
|
|
|
|
pointer a)
|
|
|
|
{
|
|
|
|
SFScript *script;
|
|
|
|
pointer args_error; /* a foreign_error or NIL. */
|
2008-09-17 21:39:44 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
/* Check metadata args args are present.
|
|
|
|
* Has one more arg than script-fu-register.
|
|
|
|
*/
|
|
|
|
if (sc->vptr->list_length (sc, a) < 8)
|
|
|
|
return foreign_error (sc, "script-fu-register-filter: Not enough arguments", 0);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
/* pass handle i.e. "&a" ("a" of type "pointer" is on the stack) */
|
|
|
|
script = script_fu_script_new_from_metadata_args (sc, &a);
|
2008-09-19 09:34:35 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
/* Check semantic error: a script declaring it takes an image must specify
|
|
|
|
* image types. Otherwise the script's menu item will be enabled
|
|
|
|
* even when no images exist.
|
|
|
|
*/
|
|
|
|
if (g_strcmp0(script->image_types, "")==0)
|
|
|
|
return foreign_error (sc, "script-fu-register-filter: A filter must declare image types.", 0);
|
2008-09-19 19:17:12 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
args_error = script_fu_script_parse_drawable_arity_arg (sc, &a, script);
|
|
|
|
if (args_error != sc->NIL)
|
|
|
|
return args_error;
|
2007-08-03 19:39:41 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
args_error = script_fu_script_create_formal_args (sc, &a, script);
|
|
|
|
if (args_error != sc->NIL)
|
|
|
|
return args_error;
|
2004-11-18 01:57:13 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
script->proc_class = GIMP_TYPE_IMAGE_PROCEDURE;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2022-07-15 13:50:36 -04:00
|
|
|
script_fu_try_map_menu (script);
|
|
|
|
script_fu_append_script_to_tree (script);
|
2006-10-16 01:08:54 +00:00
|
|
|
return sc->NIL;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2024-09-21 12:03:42 -04:00
|
|
|
/* For a script's call to script-fu-register-regular.
|
|
|
|
* Traverse Scheme argument list creating a new SFScript
|
|
|
|
* whose drawable_arity is SF_NO_DRAWABLE
|
|
|
|
*
|
|
|
|
* Return NIL or a foreign_error
|
|
|
|
*/
|
|
|
|
pointer
|
|
|
|
script_fu_add_script_regular (scheme *sc,
|
|
|
|
pointer a)
|
|
|
|
{
|
|
|
|
SFScript *script;
|
|
|
|
pointer args_error; /* a foreign_error or NIL. */
|
|
|
|
|
|
|
|
/* Check metadata args args are present.
|
|
|
|
* Has two less arg than script-fu-register.
|
|
|
|
* Last metadata arg is "copyright date"
|
|
|
|
*/
|
|
|
|
if (sc->vptr->list_length (sc, a) < 5)
|
|
|
|
return foreign_error (sc, "script-fu-register-filter: Not enough arguments", 0);
|
|
|
|
|
|
|
|
/* pass handle i.e. "&a" ("a" of type "pointer" is on the stack) */
|
|
|
|
script = script_fu_script_new_from_metadata_regular (sc, &a);
|
|
|
|
|
|
|
|
script_fu_script_set_drawable_arity_none (script);
|
|
|
|
|
|
|
|
/* Parse the args to this function that are formal declarations of
|
|
|
|
* the args to the PDB procedure being defined.
|
|
|
|
*/
|
|
|
|
args_error = script_fu_script_create_formal_args (sc, &a, script);
|
|
|
|
if (args_error != sc->NIL)
|
|
|
|
return args_error;
|
|
|
|
|
|
|
|
script->proc_class = GIMP_TYPE_PROCEDURE;
|
|
|
|
|
|
|
|
script_fu_try_map_menu (script);
|
|
|
|
script_fu_append_script_to_tree (script);
|
|
|
|
return sc->NIL;
|
|
|
|
}
|
|
|
|
|
2006-10-16 01:08:54 +00:00
|
|
|
pointer
|
2008-09-11 18:00:18 +00:00
|
|
|
script_fu_add_menu (scheme *sc,
|
|
|
|
pointer a)
|
2004-11-17 15:24:07 +00:00
|
|
|
{
|
2005-08-02 23:45:24 +00:00
|
|
|
SFScript *script;
|
|
|
|
SFMenu *menu;
|
|
|
|
const gchar *name;
|
2008-09-19 15:42:02 +00:00
|
|
|
const gchar *path;
|
2004-11-17 15:24:07 +00:00
|
|
|
|
|
|
|
/* Check the length of a */
|
2006-10-16 01:08:54 +00:00
|
|
|
if (sc->vptr->list_length (sc, a) != 2)
|
2007-08-31 19:35:26 +00:00
|
|
|
return foreign_error (sc, "Incorrect number of arguments for script-fu-menu-register", 0);
|
2004-11-17 15:24:07 +00:00
|
|
|
|
|
|
|
/* Find the script PDB entry name */
|
2006-10-16 01:08:54 +00:00
|
|
|
name = sc->vptr->string_value (sc->vptr->pair_car (a));
|
|
|
|
a = sc->vptr->pair_cdr (a);
|
2004-11-17 15:24:07 +00:00
|
|
|
|
2005-08-02 23:45:24 +00:00
|
|
|
script = script_fu_find_script (name);
|
2004-11-22 21:01:28 +00:00
|
|
|
|
|
|
|
if (! script)
|
2008-09-17 21:39:44 +00:00
|
|
|
{
|
2008-09-19 15:42:02 +00:00
|
|
|
g_message ("Procedure %s in script-fu-menu-register does not exist",
|
|
|
|
name);
|
2008-09-17 21:39:44 +00:00
|
|
|
return sc->NIL;
|
|
|
|
}
|
2004-11-22 21:01:28 +00:00
|
|
|
|
|
|
|
/* Create a new list of menus */
|
2007-05-22 14:20:08 +00:00
|
|
|
menu = g_slice_new0 (SFMenu);
|
2004-11-22 21:01:28 +00:00
|
|
|
|
|
|
|
menu->script = script;
|
|
|
|
|
2004-11-17 15:24:07 +00:00
|
|
|
/* Find the script menu path */
|
2008-09-19 15:42:02 +00:00
|
|
|
path = sc->vptr->string_value (sc->vptr->pair_car (a));
|
|
|
|
|
|
|
|
menu->menu_path = script_fu_menu_map (path);
|
|
|
|
|
|
|
|
if (! menu->menu_path)
|
|
|
|
menu->menu_path = g_strdup (path);
|
2004-11-17 15:24:07 +00:00
|
|
|
|
2004-11-18 01:57:13 +00:00
|
|
|
script_menu_list = g_list_prepend (script_menu_list, menu);
|
2004-11-17 15:24:07 +00:00
|
|
|
|
2006-10-16 01:08:54 +00:00
|
|
|
return sc->NIL;
|
2004-11-17 15:24:07 +00:00
|
|
|
}
|
|
|
|
|
2000-05-07 22:04:51 +00:00
|
|
|
|
2003-06-16 11:31:10 +00:00
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2014-08-03 21:49:20 +02:00
|
|
|
script_fu_load_directory (GFile *directory)
|
|
|
|
{
|
|
|
|
GFileEnumerator *enumerator;
|
|
|
|
|
2022-06-19 16:03:06 -04:00
|
|
|
g_debug ("Load dir: %s", g_file_get_parse_name (directory));
|
|
|
|
|
2014-08-03 21:49:20 +02:00
|
|
|
enumerator = g_file_enumerate_children (directory,
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_NAME ","
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
if (enumerator)
|
|
|
|
{
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)))
|
|
|
|
{
|
2023-09-19 14:38:42 +02:00
|
|
|
GFileType file_type = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE);
|
2014-08-03 21:49:20 +02:00
|
|
|
|
2015-08-30 23:34:41 +02:00
|
|
|
if ((file_type == G_FILE_TYPE_REGULAR ||
|
|
|
|
file_type == G_FILE_TYPE_DIRECTORY) &&
|
2023-09-19 14:38:42 +02:00
|
|
|
! g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN))
|
2014-08-03 21:49:20 +02:00
|
|
|
{
|
|
|
|
GFile *child = g_file_enumerator_get_child (enumerator, info);
|
|
|
|
|
2015-08-30 23:34:41 +02:00
|
|
|
if (file_type == G_FILE_TYPE_DIRECTORY)
|
|
|
|
script_fu_load_directory (child);
|
|
|
|
else
|
|
|
|
script_fu_load_script (child);
|
2014-08-03 21:49:20 +02:00
|
|
|
|
|
|
|
g_object_unref (child);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (enumerator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
script_fu_load_script (GFile *file)
|
2003-06-16 11:31:10 +00:00
|
|
|
{
|
2014-08-03 21:49:20 +02:00
|
|
|
if (gimp_file_has_extension (file, ".scm"))
|
2003-06-16 11:31:10 +00:00
|
|
|
{
|
2014-08-03 21:49:20 +02:00
|
|
|
gchar *path = g_file_get_path (file);
|
|
|
|
gchar *escaped = script_fu_strescape (path);
|
2008-09-10 20:33:50 +00:00
|
|
|
gchar *command;
|
|
|
|
GError *error = NULL;
|
2003-06-16 11:31:10 +00:00
|
|
|
|
2004-09-01 13:51:51 +00:00
|
|
|
command = g_strdup_printf ("(load \"%s\")", escaped);
|
|
|
|
g_free (escaped);
|
2003-06-16 11:31:10 +00:00
|
|
|
|
2008-09-10 20:33:50 +00:00
|
|
|
if (! script_fu_run_command (command, &error))
|
|
|
|
{
|
2014-08-03 21:49:20 +02:00
|
|
|
gchar *message = g_strdup_printf (_("Error while loading %s:"),
|
|
|
|
gimp_file_get_utf8_name (file));
|
2008-09-17 11:18:53 +00:00
|
|
|
|
|
|
|
g_message ("%s\n\n%s", message, error->message);
|
2008-09-11 08:49:49 +00:00
|
|
|
|
2008-09-10 20:33:50 +00:00
|
|
|
g_clear_error (&error);
|
2008-09-17 11:18:53 +00:00
|
|
|
g_free (message);
|
2008-09-10 20:33:50 +00:00
|
|
|
}
|
2003-06-16 11:31:10 +00:00
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
2003-09-04 23:12:32 +00:00
|
|
|
/* No, I don't know why, but this is
|
2003-06-16 11:31:10 +00:00
|
|
|
* necessary on NT 4.0.
|
|
|
|
*/
|
2004-11-17 15:24:07 +00:00
|
|
|
Sleep (0);
|
2003-06-16 11:31:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
g_free (command);
|
2014-08-03 21:49:20 +02:00
|
|
|
g_free (path);
|
2003-06-16 11:31:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 16:03:06 -04:00
|
|
|
/* This is-a GTraverseFunction.
|
|
|
|
*
|
|
|
|
* Traverse. For each, install TEMPORARY PDB proc.
|
|
|
|
* Returning FALSE means entire list was traversed.
|
2000-05-07 22:04:51 +00:00
|
|
|
*/
|
2001-01-21 20:06:26 +00:00
|
|
|
static gboolean
|
2006-06-06 18:50:21 +00:00
|
|
|
script_fu_install_script (gpointer foo G_GNUC_UNUSED,
|
2006-06-16 09:55:13 +00:00
|
|
|
GList *scripts,
|
2019-08-12 20:11:45 +02:00
|
|
|
gpointer data)
|
2000-05-07 22:04:51 +00:00
|
|
|
{
|
2019-08-12 20:11:45 +02:00
|
|
|
GimpPlugIn *plug_in = data;
|
|
|
|
GList *list;
|
2004-11-18 01:57:13 +00:00
|
|
|
|
|
|
|
for (list = scripts; list; list = g_list_next (list))
|
2008-09-18 13:10:07 +00:00
|
|
|
{
|
|
|
|
SFScript *script = list->data;
|
|
|
|
|
2022-06-19 16:03:06 -04:00
|
|
|
const gchar* name = script->name;
|
|
|
|
if (script_fu_is_defined (name))
|
2022-07-15 13:50:36 -04:00
|
|
|
script_fu_script_install_proc (plug_in, script);
|
2022-06-19 16:03:06 -04:00
|
|
|
else
|
|
|
|
g_warning ("Run function not defined, or does not match PDB procedure name: %s", name);
|
2008-09-18 13:10:07 +00:00
|
|
|
}
|
2000-05-07 22:04:51 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-11-17 15:24:07 +00:00
|
|
|
static void
|
2006-06-06 18:50:21 +00:00
|
|
|
script_fu_install_menu (SFMenu *menu)
|
2004-11-17 15:24:07 +00:00
|
|
|
{
|
2022-06-19 16:03:06 -04:00
|
|
|
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
|
|
|
GimpProcedure *procedure = NULL;
|
2019-08-12 20:11:45 +02:00
|
|
|
|
|
|
|
procedure = gimp_plug_in_get_temp_procedure (plug_in,
|
|
|
|
menu->script->name);
|
|
|
|
|
2022-06-19 16:03:06 -04:00
|
|
|
if (procedure)
|
|
|
|
gimp_procedure_add_menu_path (procedure, menu->menu_path);
|
2004-11-17 15:24:07 +00:00
|
|
|
|
|
|
|
g_free (menu->menu_path);
|
2007-05-22 14:20:08 +00:00
|
|
|
g_slice_free (SFMenu, menu);
|
2004-11-17 15:24:07 +00:00
|
|
|
}
|
|
|
|
|
2003-09-04 23:12:32 +00:00
|
|
|
/*
|
2000-05-07 22:04:51 +00:00
|
|
|
* The following function is a GTraverseFunction.
|
|
|
|
*/
|
2001-01-21 20:06:26 +00:00
|
|
|
static gboolean
|
2006-06-06 18:50:21 +00:00
|
|
|
script_fu_remove_script (gpointer foo G_GNUC_UNUSED,
|
2006-06-16 09:55:13 +00:00
|
|
|
GList *scripts,
|
2019-08-12 20:11:45 +02:00
|
|
|
gpointer data)
|
2000-05-07 22:04:51 +00:00
|
|
|
{
|
2019-08-12 20:11:45 +02:00
|
|
|
GimpPlugIn *plug_in = data;
|
|
|
|
GList *list;
|
2004-11-18 01:57:13 +00:00
|
|
|
|
|
|
|
for (list = scripts; list; list = g_list_next (list))
|
2008-09-17 21:39:44 +00:00
|
|
|
{
|
|
|
|
SFScript *script = list->data;
|
|
|
|
|
2019-08-12 20:11:45 +02:00
|
|
|
script_fu_script_uninstall_proc (plug_in, script);
|
2008-09-17 21:39:44 +00:00
|
|
|
script_fu_script_free (script);
|
|
|
|
}
|
2004-11-18 01:57:13 +00:00
|
|
|
|
2004-11-20 14:55:51 +00:00
|
|
|
g_list_free (scripts);
|
2000-05-07 22:04:51 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
|
2000-05-07 22:04:51 +00:00
|
|
|
/* this is a GTraverseFunction */
|
2001-01-21 20:06:26 +00:00
|
|
|
static gboolean
|
2006-06-06 18:50:21 +00:00
|
|
|
script_fu_lookup_script (gpointer *foo G_GNUC_UNUSED,
|
2006-06-16 09:55:13 +00:00
|
|
|
GList *scripts,
|
|
|
|
gconstpointer *name)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2004-11-18 01:57:13 +00:00
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = scripts; list; list = g_list_next (list))
|
2003-09-04 23:12:32 +00:00
|
|
|
{
|
2004-11-18 01:57:13 +00:00
|
|
|
SFScript *script = list->data;
|
|
|
|
|
2006-06-16 10:19:24 +00:00
|
|
|
if (strcmp (script->name, *name) == 0)
|
2004-11-18 01:57:13 +00:00
|
|
|
{
|
|
|
|
/* store the script in the name pointer and stop the traversal */
|
|
|
|
*name = script;
|
|
|
|
return TRUE;
|
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2004-09-01 13:51:51 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2000-05-07 22:04:51 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2022-06-19 16:03:06 -04:00
|
|
|
SFScript *
|
2006-06-16 10:19:24 +00:00
|
|
|
script_fu_find_script (const gchar *name)
|
2000-05-07 22:04:51 +00:00
|
|
|
{
|
2006-06-16 10:19:24 +00:00
|
|
|
gconstpointer script = name;
|
2003-07-02 11:07:41 +00:00
|
|
|
|
2004-11-20 14:55:51 +00:00
|
|
|
g_tree_foreach (script_tree,
|
2003-09-04 23:12:32 +00:00
|
|
|
(GTraverseFunc) script_fu_lookup_script,
|
2001-11-29 15:54:39 +00:00
|
|
|
&script);
|
2001-01-21 20:06:26 +00:00
|
|
|
|
2006-06-16 10:19:24 +00:00
|
|
|
if (script == name)
|
2000-05-07 22:04:51 +00:00
|
|
|
return NULL;
|
2004-09-01 13:51:51 +00:00
|
|
|
|
|
|
|
return (SFScript *) script;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2008-09-19 15:42:02 +00:00
|
|
|
static gchar *
|
|
|
|
script_fu_menu_map (const gchar *menu_path)
|
2007-08-03 19:39:41 +00:00
|
|
|
{
|
|
|
|
/* for backward compatibility, we fiddle with some menu paths */
|
|
|
|
const struct
|
|
|
|
{
|
|
|
|
const gchar *old;
|
|
|
|
const gchar *new;
|
|
|
|
} mapping[] = {
|
2007-08-06 22:54:03 +00:00
|
|
|
{ "<Image>/Script-Fu/Alchemy", "<Image>/Filters/Artistic" },
|
|
|
|
{ "<Image>/Script-Fu/Alpha to Logo", "<Image>/Filters/Alpha to Logo" },
|
2023-03-28 23:43:11 +02:00
|
|
|
{ "<Image>/Script-Fu/Animators", "<Image>/Filters/Animation" },
|
2007-08-06 22:54:03 +00:00
|
|
|
{ "<Image>/Script-Fu/Decor", "<Image>/Filters/Decor" },
|
|
|
|
{ "<Image>/Script-Fu/Render", "<Image>/Filters/Render" },
|
|
|
|
{ "<Image>/Script-Fu/Selection", "<Image>/Select/Modify" },
|
2023-07-13 15:34:40 +02:00
|
|
|
{ "<Image>/Script-Fu/Shadow", "<Image>/Filters/Light and Shadow/[Shadow]" },
|
2007-08-06 22:54:03 +00:00
|
|
|
{ "<Image>/Script-Fu/Stencil Ops", "<Image>/Filters/Decor" }
|
2007-08-03 19:39:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (mapping); i++)
|
|
|
|
{
|
2008-09-19 15:42:02 +00:00
|
|
|
if (g_str_has_prefix (menu_path, mapping[i].old))
|
2007-08-03 19:39:41 +00:00
|
|
|
{
|
2008-09-19 15:42:02 +00:00
|
|
|
const gchar *suffix = menu_path + strlen (mapping[i].old);
|
2007-08-03 19:39:41 +00:00
|
|
|
|
2014-08-15 23:02:31 +02:00
|
|
|
if (*suffix != '/')
|
2007-08-03 19:39:41 +00:00
|
|
|
continue;
|
|
|
|
|
2008-09-19 15:42:02 +00:00
|
|
|
return g_strconcat (mapping[i].new, suffix, NULL);
|
2007-08-03 19:39:41 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-19 15:42:02 +00:00
|
|
|
|
|
|
|
return NULL;
|
2007-08-03 19:39:41 +00:00
|
|
|
}
|
|
|
|
|
2004-11-18 01:57:13 +00:00
|
|
|
static gint
|
|
|
|
script_fu_menu_compare (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
2004-11-19 22:13:58 +00:00
|
|
|
const SFMenu *menu_a = a;
|
|
|
|
const SFMenu *menu_b = b;
|
2004-11-22 21:01:28 +00:00
|
|
|
gint retval = 0;
|
2004-11-19 22:13:58 +00:00
|
|
|
|
|
|
|
if (menu_a->menu_path && menu_b->menu_path)
|
2004-11-22 21:01:28 +00:00
|
|
|
{
|
2013-04-02 15:15:22 -04:00
|
|
|
retval = g_utf8_collate (menu_a->menu_path,
|
|
|
|
menu_b->menu_path);
|
2004-11-22 21:01:28 +00:00
|
|
|
|
|
|
|
if (retval == 0 &&
|
2008-09-19 19:17:12 +00:00
|
|
|
menu_a->script->menu_label && menu_b->script->menu_label)
|
2006-05-16 12:05:30 +00:00
|
|
|
{
|
2013-04-02 15:15:22 -04:00
|
|
|
retval = g_utf8_collate (menu_a->script->menu_label,
|
|
|
|
menu_b->script->menu_label);
|
2006-05-16 12:05:30 +00:00
|
|
|
}
|
2004-11-22 21:01:28 +00:00
|
|
|
}
|
2004-11-19 22:13:58 +00:00
|
|
|
|
2004-11-22 21:01:28 +00:00
|
|
|
return retval;
|
2004-11-18 01:57:13 +00:00
|
|
|
}
|
2022-06-19 16:03:06 -04:00
|
|
|
|
|
|
|
/* Is name a defined symbol in the interpreter state?
|
|
|
|
* (Defined in any script already loaded.)
|
|
|
|
* Where "symbol" has the usual lisp meaning: a unique name associated with
|
|
|
|
* a variable or function.
|
|
|
|
*
|
|
|
|
* The most common use is
|
|
|
|
* test the name of a PDB proc, which in ScriptFu must match
|
|
|
|
* a defined function that is the inner run function.
|
|
|
|
* I.E. check for typos by author of script.
|
|
|
|
* Used during query, to preflight so that we don't install a PDB proc
|
|
|
|
* that won't run later (during the run phase)
|
|
|
|
* giving "undefined symbol" for extension-script-fu.
|
|
|
|
* Note that if instead we create a PDB proc having no defined run func,
|
|
|
|
* script-fu-interpreter would load and define a same-named scheme function
|
|
|
|
* that calls the PDB, and can enter an infinite loop.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
script_fu_is_defined (const gchar * name)
|
|
|
|
{
|
|
|
|
gchar *scheme_text;
|
|
|
|
GError *error = NULL;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
/* text to be interpreted is a call to an internal scheme function. */
|
|
|
|
scheme_text = g_strdup_printf (" (symbol? %s ) ", name);
|
|
|
|
|
|
|
|
/* Use script_fu_run_command, it correctly handles the string yielded.
|
|
|
|
* But we don't need the string yielded.
|
|
|
|
* If defined, string yielded is "#t", else is "Undefined symbol" or "#f"
|
|
|
|
*/
|
|
|
|
result = script_fu_run_command (scheme_text, &error);
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
g_debug ("script_fu_is_defined returns false");
|
|
|
|
/* error contains string yielded by interpretation. */
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2022-07-15 13:50:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* Side effects on script. */
|
|
|
|
static void
|
|
|
|
script_fu_try_map_menu (SFScript *script)
|
|
|
|
{
|
|
|
|
if (script->menu_label[0] == '<')
|
|
|
|
{
|
|
|
|
gchar *mapped = script_fu_menu_map (script->menu_label);
|
|
|
|
|
|
|
|
if (mapped)
|
|
|
|
{
|
|
|
|
g_free (script->menu_label);
|
|
|
|
script->menu_label = mapped;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append to ordered tree.
|
|
|
|
* Side effects on script_tree.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
script_fu_append_script_to_tree (SFScript *script)
|
|
|
|
{
|
|
|
|
GList *list = g_tree_lookup (script_tree, script->menu_label);
|
|
|
|
|
|
|
|
g_tree_insert (script_tree, (gpointer) script->menu_label,
|
|
|
|
g_list_append (list, script));
|
|
|
|
}
|