plug-ins/script-fu/script-fu-scripts.c changed to actually return a

2008-08-21  Sven Neumann  <sven@gimp.org>

	* plug-ins/script-fu/script-fu-scripts.c
	* plug-ins/script-fu/script-fu-interface.[ch]: changed to 
actually
	return a meaningful return status when a script-fu procedure is 
run.


svn path=/trunk/; revision=26702
This commit is contained in:
Sven Neumann
2008-08-21 17:35:52 +00:00
committed by Sven Neumann
parent 84c0b27708
commit c908bfc3fc
3 changed files with 59 additions and 38 deletions

View File

@ -108,8 +108,11 @@ static void script_fu_brush_callback (gpointer data,
* Local variables * Local variables
*/ */
static SFInterface *sf_interface = NULL; /* there can only be at most one static SFInterface *sf_interface = NULL; /* there can only be at most
interactive interface */ * oneinteractive interface
*/
static GimpPDBStatusType sf_status = GIMP_PDB_SUCCESS;
/* /*
@ -165,9 +168,9 @@ script_fu_interface_report_cc (const gchar *command)
gtk_main_iteration (); gtk_main_iteration ();
} }
void GimpPDBStatusType
script_fu_interface (SFScript *script, script_fu_interface (SFScript *script,
gint start_arg) gint start_arg)
{ {
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *menu; GtkWidget *menu;
@ -195,10 +198,10 @@ script_fu_interface (SFScript *script,
g_message (message, sf_interface->title); g_message (message, sf_interface->title);
g_free (message); g_free (message);
return; return GIMP_PDB_CANCEL;
} }
g_return_if_fail (script != NULL); g_return_val_if_fail (script != NULL, FALSE);
if (!gtk_initted) if (!gtk_initted)
{ {
@ -209,12 +212,14 @@ script_fu_interface (SFScript *script,
gtk_initted = TRUE; gtk_initted = TRUE;
} }
sf_status = GIMP_PDB_SUCCESS;
sf_interface = g_slice_new0 (SFInterface); sf_interface = g_slice_new0 (SFInterface);
sf_interface->widgets = g_new0 (GtkWidget *, script->num_args); sf_interface->widgets = g_new0 (GtkWidget *, script->num_args);
/* strip mnemonics from the menupath */ /* strip mnemonics from the menupath */
sf_interface->title = gimp_strip_uline (gettext (script->menu_path)); sf_interface->title = gimp_strip_uline (gettext (script->menu_path));
/* if this looks like a full menu path, use only the last part */ /* if this looks like a full menu path, use only the last part */
if (sf_interface->title[0] == '<' && if (sf_interface->title[0] == '<' &&
@ -601,6 +606,8 @@ script_fu_interface (SFScript *script,
gtk_widget_show (dialog); gtk_widget_show (dialog);
gtk_main (); gtk_main ();
return sf_status;
} }
static void static void
@ -750,9 +757,11 @@ script_fu_response (GtkWidget *widget,
FALSE); FALSE);
script_fu_ok (script); script_fu_ok (script);
/* fallthru */ gtk_widget_destroy (sf_interface->dialog);
break;
default: default:
sf_status = GIMP_PDB_CANCEL;
gtk_widget_destroy (sf_interface->dialog); gtk_widget_destroy (sf_interface->dialog);
break; break;
} }
@ -898,10 +907,12 @@ script_fu_ok (SFScript *script)
command = g_string_free (s, FALSE); command = g_string_free (s, FALSE);
/* run the command through the interpreter */ /* run the command through the interpreter */
output = g_string_new (""); output = g_string_new (NULL);
ts_register_output_func (ts_gstring_output_func, output); ts_register_output_func (ts_gstring_output_func, output);
if (ts_interpret_string (command)) if (ts_interpret_string (command))
script_fu_error_msg (command, output->str); script_fu_error_msg (command, output->str);
g_string_free (output, TRUE); g_string_free (output, TRUE);
g_free (command); g_free (command);

View File

@ -20,10 +20,10 @@
#define __SCRIPT_FU_INTERFACE_H__ #define __SCRIPT_FU_INTERFACE_H__
void script_fu_interface (SFScript *script, GimpPDBStatusType script_fu_interface (SFScript *script,
gint start_arg); gint start_arg);
void script_fu_interface_report_cc (const gchar *command); void script_fu_interface_report_cc (const gchar *command);
gboolean script_fu_interface_is_active (void); gboolean script_fu_interface_is_active (void);
#endif /* __SCRIPT_FU_INTERFACE_H__ */ #endif /* __SCRIPT_FU_INTERFACE_H__ */

View File

@ -53,6 +53,7 @@ typedef struct
* Local Functions * Local Functions
*/ */
static gboolean script_fu_run_command (const gchar *command);
static void script_fu_load_script (const GimpDatafileData *file_data, static void script_fu_load_script (const GimpDatafileData *file_data,
gpointer user_data); gpointer user_data);
static gboolean script_fu_install_script (gpointer foo, static gboolean script_fu_install_script (gpointer foo,
@ -670,24 +671,42 @@ script_fu_error_msg (const gchar *command,
/* private functions */ /* private functions */
static gboolean
script_fu_run_command (const gchar *command)
{
GString *output = g_string_new ("");
gboolean success = FALSE;
output = g_string_new ("");
ts_register_output_func (ts_gstring_output_func, output);
if (ts_interpret_string (command))
{
script_fu_error_msg (command, output->str);
}
else
{
success = TRUE;
}
g_string_free (output, TRUE);
return success;
}
static void static void
script_fu_load_script (const GimpDatafileData *file_data, script_fu_load_script (const GimpDatafileData *file_data,
gpointer user_data) gpointer user_data)
{ {
if (gimp_datafiles_check_extension (file_data->filename, ".scm")) if (gimp_datafiles_check_extension (file_data->filename, ".scm"))
{ {
gchar *command;
gchar *escaped = script_fu_strescape (file_data->filename); gchar *escaped = script_fu_strescape (file_data->filename);
GString *output; gchar *command;
command = g_strdup_printf ("(load \"%s\")", escaped); command = g_strdup_printf ("(load \"%s\")", escaped);
g_free (escaped); g_free (escaped);
output = g_string_new (""); script_fu_run_command (command);
ts_register_output_func (ts_gstring_output_func, output);
if (ts_interpret_string (command))
script_fu_error_msg (command, output->str);
g_string_free (output, TRUE);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
/* No, I don't know why, but this is /* No, I don't know why, but this is
@ -888,6 +907,11 @@ script_fu_script_proc (const gchar *name,
GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpPDBStatusType status = GIMP_PDB_SUCCESS;
SFScript *script; SFScript *script;
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
script = script_fu_find_script (name); script = script_fu_find_script (name);
if (! script) if (! script)
@ -912,7 +936,7 @@ script_fu_script_proc (const gchar *name,
/* ...then acquire the rest of arguments (if any) with a dialog */ /* ...then acquire the rest of arguments (if any) with a dialog */
if (script->num_args > min_args) if (script->num_args > min_args)
{ {
script_fu_interface (script, min_args); status = script_fu_interface (script, min_args);
break; break;
} }
/* otherwise (if the script takes no more arguments), skip /* otherwise (if the script takes no more arguments), skip
@ -928,7 +952,6 @@ script_fu_script_proc (const gchar *name,
if (status == GIMP_PDB_SUCCESS) if (status == GIMP_PDB_SUCCESS)
{ {
GString *s; GString *s;
GString *output;
gchar *command; gchar *command;
gint i; gint i;
@ -1015,11 +1038,7 @@ script_fu_script_proc (const gchar *name,
command = g_string_free (s, FALSE); command = g_string_free (s, FALSE);
/* run the command through the interpreter */ /* run the command through the interpreter */
output = g_string_new (""); script_fu_run_command (command);
ts_register_output_func (ts_gstring_output_func, output);
if (ts_interpret_string (command))
script_fu_error_msg (command, output->str);
g_string_free (output, TRUE);
g_free (command); g_free (command);
} }
@ -1028,7 +1047,6 @@ script_fu_script_proc (const gchar *name,
case GIMP_RUN_WITH_LAST_VALS: case GIMP_RUN_WITH_LAST_VALS:
{ {
GString *s; GString *s;
GString *output;
gchar *command; gchar *command;
gint i; gint i;
@ -1150,11 +1168,7 @@ script_fu_script_proc (const gchar *name,
command = g_string_free (s, FALSE); command = g_string_free (s, FALSE);
/* run the command through the interpreter */ /* run the command through the interpreter */
output = g_string_new (""); script_fu_run_command (command);
ts_register_output_func (ts_gstring_output_func, output);
if (ts_interpret_string (command))
script_fu_error_msg (command, output->str);
g_string_free (output, TRUE);
g_free (command); g_free (command);
} }
@ -1165,10 +1179,6 @@ script_fu_script_proc (const gchar *name,
} }
} }
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status; values[0].data.d_status = status;
} }