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 gint script_fu_cc_key_function (GtkWidget *widget, GdkEventKey *event, gpointer data) { GList *list; int direction = 0; switch (event->keyval) { case GDK_Return: gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event"); if (script_fu_cc_is_empty ()) return TRUE; list = g_list_nth (history, (g_list_length (history) - 1)); if (list->data) g_free (list->data); list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (cint.cc))); gtk_text_freeze (GTK_TEXT (cint.console)); gtk_text_insert (GTK_TEXT (cint.console), cint.font_strong, NULL, NULL, "=> ", -1); gtk_text_insert (GTK_TEXT (cint.console), cint.font, NULL, NULL, gtk_entry_get_text (GTK_ENTRY (cint.cc)), -1); gtk_text_insert (GTK_TEXT (cint.console), cint.font, NULL, NULL, "\n\n", -1); gtk_text_thaw (GTK_TEXT (cint.console)); cint.vadj->value = cint.vadj->upper - cint.vadj->page_size; gtk_signal_emit_by_name (GTK_OBJECT (cint.vadj), "changed"); gtk_entry_set_text (GTK_ENTRY (cint.cc), ""); gdk_flush (); repl_c_string ((char *) list->data, 0, 0, 1); gimp_displays_flush (); history = g_list_append (history, NULL); if (history_len == history_max) { history = g_list_remove (history, history->data); if (history->data) g_free (history->data); } else history_len++; history_cur = g_list_length (history) - 1; return TRUE; break; case GDK_KP_Up: case GDK_Up: gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event"); direction = -1; break; case GDK_KP_Down: case GDK_Down: gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event"); direction = 1; break; case GDK_P: case GDK_p: if (event->state & GDK_CONTROL_MASK) { gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event"); direction = -1; } break; case GDK_N: case GDK_n: if (event->state & GDK_CONTROL_MASK) { gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event"); direction = 1; } break; default: break; } if (direction) { /* Make sure we keep track of the current one */ if (history_cur == g_list_length (history) - 1) { list = g_list_nth (history, history_cur); if (list->data) g_free (list->data); list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (cint.cc))); } history_cur += direction; if (history_cur < 0) history_cur = 0; if (history_cur >= history_len) history_cur = history_len - 1; gtk_entry_set_text (GTK_ENTRY (cint.cc), (char *) (g_list_nth (history, history_cur))->data); return TRUE; } return FALSE; }