void script_fu_text_console_run (const gchar *name, gint nparams, const GimpParam *params, gint *nreturn_vals, GimpParam **return_vals) { 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); /* Run the interface */ ts_interpret_stdin (); gimp_plugin_set_pdb_error_handler (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; }
static gboolean script_fu_cc_key_function (GtkWidget *widget, GdkEventKey *event, ConsoleInterface *console) { GList *list; gint direction = 0; GtkTextIter cursor; GString *output; switch (event->keyval) { case GDK_KEY_Return: case GDK_KEY_KP_Enter: case GDK_KEY_ISO_Enter: if (script_fu_cc_is_empty (console)) return TRUE; list = g_list_nth (console->history, (g_list_length (console->history) - 1)); if (list->data) g_free (list->data); list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (console->cc))); gtk_text_buffer_get_end_iter (console->console, &cursor); gtk_text_buffer_insert (console->console, &cursor, "\n", 1); gtk_text_buffer_insert_with_tags_by_name (console->console, &cursor, "> ", 2, "strong", NULL); gtk_text_buffer_insert (console->console, &cursor, gtk_entry_get_text (GTK_ENTRY (console->cc)), -1); gtk_text_buffer_insert (console->console, &cursor, "\n", 1); script_fu_console_scroll_end (console->text_view); gtk_entry_set_text (GTK_ENTRY (console->cc), ""); 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); if (ts_interpret_string (list->data) != 0) { script_fu_output_to_console (TS_OUTPUT_ERROR, output->str, output->len, console); } else { script_fu_output_to_console (TS_OUTPUT_NORMAL, output->str, output->len, console); } gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_INTERNAL); g_string_free (output, TRUE); gimp_displays_flush (); console->history = g_list_append (console->history, NULL); if (console->history_len == console->history_max) { console->history = g_list_remove (console->history, console->history->data); if (console->history->data) g_free (console->history->data); } else { console->history_len++; } console->history_cur = g_list_length (console->history) - 1; return TRUE; break; case GDK_KEY_KP_Up: case GDK_KEY_Up: direction = -1; break; case GDK_KEY_KP_Down: case GDK_KEY_Down: direction = 1; break; case GDK_KEY_P: case GDK_KEY_p: if (event->state & GDK_CONTROL_MASK) direction = -1; break; case GDK_KEY_N: case GDK_KEY_n: if (event->state & GDK_CONTROL_MASK) direction = 1; break; default: break; } if (direction) { /* Make sure we keep track of the current one */ if (console->history_cur == g_list_length (console->history) - 1) { list = g_list_nth (console->history, console->history_cur); g_free (list->data); list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (console->cc))); } console->history_cur += direction; if (console->history_cur < 0) console->history_cur = 0; if (console->history_cur >= console->history_len) console->history_cur = console->history_len - 1; gtk_entry_set_text (GTK_ENTRY (console->cc), (gchar *) (g_list_nth (console->history, console->history_cur))->data); gtk_editable_set_position (GTK_EDITABLE (console->cc), -1); return TRUE; } return FALSE; }
static void script_fu_ok (SFScript *script) { GString *output; gchar *command; gint i; for (i = 0; i < script->n_args; i++) { SFArgValue *arg_value = &script->args[i].value; GtkWidget *widget = sf_interface->widgets[i]; switch (script->args[i].type) { case SF_IMAGE: case SF_DRAWABLE: case SF_LAYER: case SF_CHANNEL: case SF_VECTORS: case SF_DISPLAY: case SF_COLOR: case SF_TOGGLE: break; case SF_VALUE: case SF_STRING: g_free (arg_value->sfa_value); arg_value->sfa_value = g_strdup (gtk_entry_get_text (GTK_ENTRY (widget))); break; case SF_TEXT: { GtkWidget *view; GtkTextBuffer *buffer; GtkTextIter start, end; view = gtk_bin_get_child (GTK_BIN (widget)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); gtk_text_buffer_get_start_iter (buffer, &start); gtk_text_buffer_get_end_iter (buffer, &end); g_free (arg_value->sfa_value); arg_value->sfa_value = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); } break; case SF_ADJUSTMENT: case SF_FILENAME: case SF_DIRNAME: case SF_FONT: case SF_PALETTE: case SF_PATTERN: case SF_GRADIENT: case SF_BRUSH: case SF_OPTION: case SF_ENUM: break; } } command = script_fu_script_get_command (script); /* run the command through the interpreter */ 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); if (ts_interpret_string (command)) { gchar *message = g_strdup_printf (_("Error while executing %s:"), script->name); g_message ("%s\n\n%s", message, output->str); g_free (message); } gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_INTERNAL); g_string_free (output, TRUE); g_free (command); }