static void script_fu_output_to_console (TsOutputType type, const gchar *text, gint len, gpointer user_data) { ConsoleInterface *console = user_data; if (console && console->text_view) { GtkTextBuffer *buffer; GtkTextIter cursor; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (console->text_view)); gtk_text_buffer_get_end_iter (buffer, &cursor); if (type == TS_OUTPUT_NORMAL) { gtk_text_buffer_insert (buffer, &cursor, text, len); } else { gtk_text_buffer_insert_with_tags_by_name (console->console, &cursor, text, len, "emphasis", NULL); } script_fu_console_scroll_end (console->text_view); } }
static gboolean script_fu_siod_read (GIOChannel *channel, GIOCondition cond, gpointer data) { int count; static int hack = 0; GIOError error; count = 0; error = g_io_channel_read (channel, read_buffer, BUFSIZE - 1, &count); if (error == G_IO_ERROR_NONE) { #ifndef G_OS_WIN32 /* Is this needed any longer on Unix? */ if (!hack) /* this is a stupid hack, but as of 10/27/98 * the script-fu-console will hang on my system without it. * the real cause of this needs to be tracked down. * posibly a problem with the text widget, or the * signal handlers not getting fully initialized or... * no reports of hangs on other platforms, could just be a * problem with my system. */ { hack = 1; return TRUE; } #endif read_buffer[count] = '\0'; gtk_text_freeze (GTK_TEXT (cint.console)); gtk_text_insert (GTK_TEXT (cint.console), cint.font_weak, NULL, NULL, read_buffer, -1); gtk_text_thaw (GTK_TEXT (cint.console)); script_fu_console_scroll_end (NULL); } return TRUE; }
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; }