mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-04 09:53:25 +00:00
Refactor ScriptFu Console
Rename fields of ConsoleInterface more desciptive Add c,h files for object editor and history Extract object ConsoleEditor Extract object ConsoleHistory Extract TotalHistory methods
This commit is contained in:
parent
d7287e0f3b
commit
5eac31f07f
11 changed files with 643 additions and 188 deletions
39
plug-ins/script-fu/console/meson.build
Normal file
39
plug-ins/script-fu/console/meson.build
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
# library for script-fu-console
|
||||||
|
#
|
||||||
|
# Contains just the run_func for ScriptFu console plugin.
|
||||||
|
# The plugin is a PDB procedure of type temporary.
|
||||||
|
# The PDB procedure is registered by script-fu plugin,
|
||||||
|
# which passes the run_func as a closure at registration time.
|
||||||
|
#
|
||||||
|
# Static library: just an archive of object files.
|
||||||
|
# The library is not installed,
|
||||||
|
# only linked with the script-fu plugin which references it.
|
||||||
|
|
||||||
|
# uses libscriptfu
|
||||||
|
|
||||||
|
libscriptfuconsoleInclude = include_directories('.')
|
||||||
|
|
||||||
|
libscriptfuconsole_sources = [
|
||||||
|
'script-fu-console.c',
|
||||||
|
'script-fu-console-editor.c',
|
||||||
|
'script-fu-console-history.c',
|
||||||
|
'script-fu-console-total.c',
|
||||||
|
]
|
||||||
|
|
||||||
|
libscriptfuconsole = static_library('scriptfu-console',
|
||||||
|
libscriptfuconsole_sources,
|
||||||
|
include_directories: [
|
||||||
|
libscriptfuInclude,
|
||||||
|
rootInclude,
|
||||||
|
appInclude,
|
||||||
|
],
|
||||||
|
c_args: [
|
||||||
|
'-DG_LOG_DOMAIN="scriptfu-console"',
|
||||||
|
],
|
||||||
|
dependencies: [
|
||||||
|
libgimpui_dep,
|
||||||
|
math,
|
||||||
|
],
|
||||||
|
link_with: libscriptfu,
|
||||||
|
install: false,
|
||||||
|
)
|
89
plug-ins/script-fu/console/script-fu-console-editor.c
Normal file
89
plug-ins/script-fu/console/script-fu-console-editor.c
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
/* GIMP - The GNU Image Manipulation Program
|
||||||
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (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
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* ConsoleEditor
|
||||||
|
|
||||||
|
* An API that abstracts these GtkWidgets for editing text:
|
||||||
|
* - GtkTextEntry is single line,
|
||||||
|
* - GtkTextView is multiline.
|
||||||
|
*
|
||||||
|
* So that we can swap out or enhance widget without affecting main logic.
|
||||||
|
*
|
||||||
|
* Not a defined class but methods conform to naming and calling conventions.
|
||||||
|
*
|
||||||
|
* Is-a GtkWidget.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* FUTURE
|
||||||
|
* GtkTextEntry => GtkTextView (multiline)
|
||||||
|
*
|
||||||
|
* Possibly: an editor that understands syntax and highlighting.
|
||||||
|
*/
|
||||||
|
|
||||||
|
GtkWidget *
|
||||||
|
console_editor_new ()
|
||||||
|
{
|
||||||
|
return gtk_entry_new ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set editor's text and position the cursor.
|
||||||
|
* @position conforms to GtkEditable interface.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
console_editor_set_text_and_position (GtkWidget *self,
|
||||||
|
const gchar *text,
|
||||||
|
gint position)
|
||||||
|
{
|
||||||
|
gtk_entry_set_text (GTK_ENTRY (self), text);
|
||||||
|
gtk_editable_set_position (GTK_EDITABLE (self), position);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
console_editor_clear (GtkWidget *self)
|
||||||
|
{
|
||||||
|
console_editor_set_text_and_position (self, "", -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const gchar *
|
||||||
|
console_editor_get_text (GtkWidget *self)
|
||||||
|
{
|
||||||
|
return gtk_entry_get_text (GTK_ENTRY (self));
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
console_editor_is_empty (GtkWidget *self)
|
||||||
|
{
|
||||||
|
const gchar *str;
|
||||||
|
|
||||||
|
if ((str = console_editor_get_text (self)) == NULL)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
while (*str)
|
||||||
|
{
|
||||||
|
if (*str != ' ' && *str != '\t' && *str != '\n')
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
str ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
32
plug-ins/script-fu/console/script-fu-console-editor.h
Normal file
32
plug-ins/script-fu/console/script-fu-console-editor.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/* GIMP - The GNU Image Manipulation Program
|
||||||
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (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
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SCRIPT_FU_CONSOLE_EDITOR_H__
|
||||||
|
#define __SCRIPT_FU_CONSOLE_EDITOR_H__
|
||||||
|
|
||||||
|
|
||||||
|
GtkWidget *console_editor_new (void);
|
||||||
|
void console_editor_set_text_and_position (GtkWidget *self,
|
||||||
|
const gchar *text,
|
||||||
|
gint position);
|
||||||
|
|
||||||
|
const gchar *console_editor_get_text (GtkWidget *self);
|
||||||
|
gboolean console_editor_is_empty (GtkWidget *self);
|
||||||
|
void console_editor_clear (GtkWidget *self);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __SCRIPT_FU_CONSOLE_EDITOR_H__ */
|
157
plug-ins/script-fu/console/script-fu-console-history.c
Normal file
157
plug-ins/script-fu/console/script-fu-console-history.c
Normal file
|
@ -0,0 +1,157 @@
|
||||||
|
/* GIMP - The GNU Image Manipulation Program
|
||||||
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (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
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
#include "script-fu-console-history.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* CommandHistory
|
||||||
|
*
|
||||||
|
* Not a true class, just a struct with methods.
|
||||||
|
* Does not inherit GObject.
|
||||||
|
*
|
||||||
|
* Is a model that affects a view of the "console history."
|
||||||
|
* The model is a sequence of ExecutedCommands.
|
||||||
|
* The sequence is a time-ordered queue.
|
||||||
|
* You can only append to the end, called the tail.
|
||||||
|
* An ExecutedCommand does not contain the result of interpretation,
|
||||||
|
* only the string that was interpreted.
|
||||||
|
*
|
||||||
|
* The sequence is finite.
|
||||||
|
* When you append to the tail,
|
||||||
|
* commands might be discarded from the head.
|
||||||
|
*
|
||||||
|
* Has a cursor.
|
||||||
|
* You can only get the command at the cursor.
|
||||||
|
* The user scrolling through the history moves the cursor.
|
||||||
|
* This scrolling is arrow keys in the editor pane,
|
||||||
|
* (not scroll bars in the history view pane.)
|
||||||
|
* See the main console logic:
|
||||||
|
* when user hits arrow keys in the editor,
|
||||||
|
* move cursor in the history, get the command at the cursor,
|
||||||
|
* and display it in the editor, ready to execute.
|
||||||
|
*
|
||||||
|
* A CommandHistory is a model,
|
||||||
|
* but there is also a distinct TotalHistory model for a scrolling view of the history
|
||||||
|
* (e.g. a GtkTextBuffer model for a GtkTextView.)
|
||||||
|
*
|
||||||
|
* CommandHistory <-supersets- TotalHistory <-views- ConsoleView
|
||||||
|
*
|
||||||
|
* TotalHistory contains more than the commands in CommandHistory.
|
||||||
|
* TotalHistory contains e.g. splash, prompts, and interpretation results.
|
||||||
|
*
|
||||||
|
* !!! Self does not currently write TotalHistory;
|
||||||
|
* The main console logic writes TotalHistory,
|
||||||
|
*
|
||||||
|
* FUTURE:
|
||||||
|
* CommandHistory is persistent across sessions of the ScriptFu Console,
|
||||||
|
* and across sessions of Gimp.
|
||||||
|
* When the SFConsole starts, the TotalHistory,
|
||||||
|
* is just the CommandHistory, without results.
|
||||||
|
* Old results are not meaningful since the environment changed.
|
||||||
|
* Specifically, a new session of SFConsole has a new initialized interpreter.
|
||||||
|
* Similarly, when the user quits the console,
|
||||||
|
* only the CommandHistory is saved as settings.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
console_history_init (CommandHistory *self,
|
||||||
|
GtkTextBuffer *model_of_view)
|
||||||
|
{
|
||||||
|
self->model = g_list_append (self->model, NULL);
|
||||||
|
self->model_len = 1;
|
||||||
|
self->model_max = 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Store the command in tail of CommandHistory.
|
||||||
|
* The tail is the most recent added element, which was created prior by new_tail.
|
||||||
|
*
|
||||||
|
* @commmand transfer full
|
||||||
|
*
|
||||||
|
* !!! The caller is executing the command.
|
||||||
|
* The caller updates TotalHistory, with a prompt string and the command string.
|
||||||
|
* Self does not update TotalHistory, the model of the view.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
console_history_set_tail (CommandHistory *self,
|
||||||
|
const gchar *command)
|
||||||
|
{
|
||||||
|
GList *list;
|
||||||
|
|
||||||
|
list = g_list_nth (self->model,
|
||||||
|
(g_list_length (self->model) - 1));
|
||||||
|
|
||||||
|
if (list->data)
|
||||||
|
g_free (list->data);
|
||||||
|
|
||||||
|
/* Discarding const. */
|
||||||
|
list->data = (gpointer) command;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allocate an empty element at tail of CommandHistory.
|
||||||
|
* Prune head when max exceeded.
|
||||||
|
* Position the cursor at last element.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
console_history_new_tail (CommandHistory *self)
|
||||||
|
{
|
||||||
|
self->model = g_list_append (self->model, NULL);
|
||||||
|
|
||||||
|
if (self->model_len == self->model_max)
|
||||||
|
{
|
||||||
|
/* FIXME: is this correct, seems to be double freeing the head. */
|
||||||
|
self->model = g_list_remove (self->model, self->model->data);
|
||||||
|
if (self->model->data)
|
||||||
|
g_free (self->model->data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self->model_len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->model_cursor = g_list_length (self->model) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
console_history_is_cursor_at_tail (CommandHistory *self)
|
||||||
|
{
|
||||||
|
return self->model_cursor == g_list_length (self->model) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
console_history_move_cursor (CommandHistory *self,
|
||||||
|
gint direction)
|
||||||
|
{
|
||||||
|
self->model_cursor += direction;
|
||||||
|
|
||||||
|
if (self->model_cursor < 0)
|
||||||
|
self->model_cursor = 0;
|
||||||
|
|
||||||
|
if (self->model_cursor >= self->model_len)
|
||||||
|
self->model_cursor = self->model_len - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gchar *
|
||||||
|
console_history_get_at_cursor (CommandHistory *self)
|
||||||
|
{
|
||||||
|
return g_list_nth (self->model, self->model_cursor)->data;
|
||||||
|
}
|
44
plug-ins/script-fu/console/script-fu-console-history.h
Normal file
44
plug-ins/script-fu/console/script-fu-console-history.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/* GIMP - The GNU Image Manipulation Program
|
||||||
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (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
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SCRIPT_FU_CONSOLE_HISTORY_H__
|
||||||
|
#define __SCRIPT_FU_CONSOLE_HISTORY_H__
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GList *model;
|
||||||
|
gint model_len;
|
||||||
|
gint model_cursor;
|
||||||
|
gint model_max;
|
||||||
|
} CommandHistory;
|
||||||
|
|
||||||
|
|
||||||
|
void console_history_init (CommandHistory *self,
|
||||||
|
GtkTextBuffer *total_history);
|
||||||
|
|
||||||
|
void console_history_new_tail (CommandHistory *self);
|
||||||
|
void console_history_set_tail (CommandHistory *self,
|
||||||
|
const gchar *command);
|
||||||
|
|
||||||
|
void console_history_move_cursor (CommandHistory *self,
|
||||||
|
gint direction);
|
||||||
|
gboolean console_history_is_cursor_at_tail (CommandHistory *self);
|
||||||
|
const gchar *console_history_get_at_cursor (CommandHistory *self);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __SCRIPT_FU_CONSOLE_HISTORY_H__ */
|
164
plug-ins/script-fu/console/script-fu-console-total.c
Normal file
164
plug-ins/script-fu/console/script-fu-console-total.c
Normal file
|
@ -0,0 +1,164 @@
|
||||||
|
/* GIMP - The GNU Image Manipulation Program
|
||||||
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (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
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
#include "script-fu-console-total.h"
|
||||||
|
|
||||||
|
#include "script-fu-intl.h"
|
||||||
|
|
||||||
|
/* TotalHistory
|
||||||
|
* Model for the history pane of SFConsole.
|
||||||
|
*
|
||||||
|
* Shows welcome, prompts repr, commands executed, and results of evaluation.
|
||||||
|
*
|
||||||
|
* A thin wrapper around GtkTextBuffer
|
||||||
|
*
|
||||||
|
* All changes to the model update the view via signals of the underlying Gtk classes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
GtkTextBuffer *
|
||||||
|
console_total_history_new ()
|
||||||
|
{
|
||||||
|
return gtk_text_buffer_new (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clear TotalHistory.
|
||||||
|
*
|
||||||
|
* !!! Not clear CommandHistory, only TotalHistory.
|
||||||
|
* So TotalHistory is not always a superset of CommandHistory.
|
||||||
|
* FUTURE: also clear CommandHistory??
|
||||||
|
*
|
||||||
|
* !!! Not affect cursor of CommandHistory
|
||||||
|
* FUTURE: reset cursor to bottom?
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
console_total_history_clear (GtkTextBuffer *self)
|
||||||
|
{
|
||||||
|
GtkTextIter start, end;
|
||||||
|
|
||||||
|
gtk_text_buffer_get_start_iter (self, &start);
|
||||||
|
gtk_text_buffer_get_end_iter (self, &end);
|
||||||
|
gtk_text_buffer_delete (self, &start, &end);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get all the text in self, including text
|
||||||
|
* that is not in CommandHistory, i.e. splash, prompts, and results.
|
||||||
|
*/
|
||||||
|
gchar *
|
||||||
|
console_total_history_get_text (GtkTextBuffer *self)
|
||||||
|
{
|
||||||
|
GtkTextIter start, end;
|
||||||
|
|
||||||
|
gtk_text_buffer_get_start_iter (self, &start);
|
||||||
|
gtk_text_buffer_get_end_iter (self, &end);
|
||||||
|
return gtk_text_buffer_get_text (self, &start, &end, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
console_total_append_welcome (GtkTextBuffer *self)
|
||||||
|
{
|
||||||
|
gtk_text_buffer_create_tag (self, "strong",
|
||||||
|
"weight", PANGO_WEIGHT_BOLD,
|
||||||
|
"scale", PANGO_SCALE_LARGE,
|
||||||
|
NULL);
|
||||||
|
gtk_text_buffer_create_tag (self, "emphasis",
|
||||||
|
"style", PANGO_STYLE_OBLIQUE,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
{
|
||||||
|
const gchar * const greetings[] =
|
||||||
|
{
|
||||||
|
"strong", N_("Welcome to TinyScheme"),
|
||||||
|
NULL, "\n",
|
||||||
|
NULL, "Copyright (c) Dimitrios Souflis",
|
||||||
|
NULL, "\n",
|
||||||
|
"strong", N_("Script-Fu Console"),
|
||||||
|
NULL, " - ",
|
||||||
|
"emphasis", N_("Interactive Scheme Development"),
|
||||||
|
NULL, "\n"
|
||||||
|
};
|
||||||
|
|
||||||
|
GtkTextIter cursor;
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
gtk_text_buffer_get_end_iter (self, &cursor);
|
||||||
|
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (greetings); i += 2)
|
||||||
|
{
|
||||||
|
if (greetings[i])
|
||||||
|
gtk_text_buffer_insert_with_tags_by_name (self, &cursor,
|
||||||
|
gettext (greetings[i + 1]),
|
||||||
|
-1, greetings[i],
|
||||||
|
NULL);
|
||||||
|
else
|
||||||
|
gtk_text_buffer_insert (self, &cursor,
|
||||||
|
gettext (greetings[i + 1]), -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
console_total_append_text_normal (GtkTextBuffer *self,
|
||||||
|
const gchar *text,
|
||||||
|
gint len)
|
||||||
|
{
|
||||||
|
GtkTextIter cursor;
|
||||||
|
|
||||||
|
gtk_text_buffer_get_end_iter (self, &cursor);
|
||||||
|
gtk_text_buffer_insert (self, &cursor, text, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
console_total_append_text_emphasize (GtkTextBuffer *self,
|
||||||
|
const gchar *text,
|
||||||
|
gint len)
|
||||||
|
{
|
||||||
|
GtkTextIter cursor;
|
||||||
|
|
||||||
|
gtk_text_buffer_get_end_iter (self, &cursor);
|
||||||
|
gtk_text_buffer_insert_with_tags_by_name (self,
|
||||||
|
&cursor,
|
||||||
|
text, len, "emphasis",
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write newlines, prompt, and command. */
|
||||||
|
void
|
||||||
|
console_total_append_command (GtkTextBuffer *self,
|
||||||
|
const gchar *command)
|
||||||
|
{
|
||||||
|
GtkTextIter cursor;
|
||||||
|
|
||||||
|
gtk_text_buffer_get_end_iter (self, &cursor);
|
||||||
|
|
||||||
|
gtk_text_buffer_insert (self, &cursor, "\n", 1);
|
||||||
|
/* Write repr of a prompt.
|
||||||
|
* SFConsole doesn't have a prompt in it's command line,
|
||||||
|
* But we show one in the history view to distinguish commands.
|
||||||
|
*/
|
||||||
|
gtk_text_buffer_insert_with_tags_by_name (self, &cursor,
|
||||||
|
"> ", 2,
|
||||||
|
"strong",
|
||||||
|
NULL);
|
||||||
|
gtk_text_buffer_insert (self, &cursor, command, -1);
|
||||||
|
gtk_text_buffer_insert (self, &cursor, "\n", 1);
|
||||||
|
}
|
37
plug-ins/script-fu/console/script-fu-console-total.h
Normal file
37
plug-ins/script-fu/console/script-fu-console-total.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/* GIMP - The GNU Image Manipulation Program
|
||||||
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (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
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SCRIPT_FU_CONSOLE_TOTAL_H__
|
||||||
|
#define __SCRIPT_FU_CONSOLE_TOTAL_H__
|
||||||
|
|
||||||
|
|
||||||
|
GtkTextBuffer *console_total_history_new (void);
|
||||||
|
void console_total_history_clear (GtkTextBuffer *self);
|
||||||
|
gchar *console_total_history_get_text (GtkTextBuffer *self);
|
||||||
|
|
||||||
|
void console_total_append_welcome (GtkTextBuffer *self);
|
||||||
|
void console_total_append_text_normal (GtkTextBuffer *self,
|
||||||
|
const gchar *text,
|
||||||
|
gint len);
|
||||||
|
void console_total_append_text_emphasize (GtkTextBuffer *self,
|
||||||
|
const gchar *text,
|
||||||
|
gint len);
|
||||||
|
void console_total_append_command (GtkTextBuffer *self,
|
||||||
|
const gchar *command);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __SCRIPT_FU_CONSOLE_TOTAL_H__ */
|
|
@ -28,6 +28,9 @@
|
||||||
#include <gdk/gdkkeysyms.h>
|
#include <gdk/gdkkeysyms.h>
|
||||||
|
|
||||||
#include "script-fu-console.h"
|
#include "script-fu-console.h"
|
||||||
|
#include "script-fu-console-editor.h"
|
||||||
|
#include "script-fu-console-history.h"
|
||||||
|
#include "script-fu-console-total.h"
|
||||||
|
|
||||||
#include "script-fu-lib.h"
|
#include "script-fu-lib.h"
|
||||||
#include "script-fu-intl.h"
|
#include "script-fu-intl.h"
|
||||||
|
@ -41,16 +44,13 @@
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkTextBuffer *console;
|
GtkTextBuffer *total_history;
|
||||||
GtkWidget *cc;
|
GtkWidget *editor;
|
||||||
GtkWidget *text_view;
|
GtkWidget *history_view;
|
||||||
GtkWidget *proc_browser;
|
GtkWidget *proc_browser;
|
||||||
GtkWidget *save_dialog;
|
GtkWidget *save_dialog;
|
||||||
|
|
||||||
GList *history;
|
CommandHistory history;
|
||||||
gint history_len;
|
|
||||||
gint history_cur;
|
|
||||||
gint history_max;
|
|
||||||
} ConsoleInterface;
|
} ConsoleInterface;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -77,8 +77,7 @@ static void script_fu_browse_response (GtkWidget *widget,
|
||||||
ConsoleInterface *console);
|
ConsoleInterface *console);
|
||||||
static void script_fu_browse_row_activated (GtkDialog *dialog);
|
static void script_fu_browse_row_activated (GtkDialog *dialog);
|
||||||
|
|
||||||
static gboolean script_fu_cc_is_empty (ConsoleInterface *console);
|
static gboolean script_fu_editor_key_function (GtkWidget *widget,
|
||||||
static gboolean script_fu_cc_key_function (GtkWidget *widget,
|
|
||||||
GdkEventKey *event,
|
GdkEventKey *event,
|
||||||
ConsoleInterface *console);
|
ConsoleInterface *console);
|
||||||
|
|
||||||
|
@ -105,8 +104,6 @@ script_fu_console_run (GimpProcedure *procedure,
|
||||||
|
|
||||||
gimp_ui_init ("script-fu");
|
gimp_ui_init ("script-fu");
|
||||||
|
|
||||||
console.history_max = 50;
|
|
||||||
|
|
||||||
console.dialog = gimp_dialog_new (_("Script-Fu Console"),
|
console.dialog = gimp_dialog_new (_("Script-Fu Console"),
|
||||||
"gimp-script-fu-console",
|
"gimp-script-fu-console",
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
|
@ -140,7 +137,7 @@ script_fu_console_run (GimpProcedure *procedure,
|
||||||
vbox, TRUE, TRUE, 0);
|
vbox, TRUE, TRUE, 0);
|
||||||
gtk_widget_show (vbox);
|
gtk_widget_show (vbox);
|
||||||
|
|
||||||
/* The output text widget */
|
/* A view of the total history. */
|
||||||
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
||||||
GTK_POLICY_AUTOMATIC,
|
GTK_POLICY_AUTOMATIC,
|
||||||
|
@ -148,70 +145,35 @@ script_fu_console_run (GimpProcedure *procedure,
|
||||||
gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
|
||||||
gtk_widget_show (scrolled_window);
|
gtk_widget_show (scrolled_window);
|
||||||
|
|
||||||
console.console = gtk_text_buffer_new (NULL);
|
console.total_history = console_total_history_new ();
|
||||||
console.text_view = gtk_text_view_new_with_buffer (console.console);
|
|
||||||
g_object_unref (console.console);
|
|
||||||
|
|
||||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (console.text_view), FALSE);
|
console.history_view = gtk_text_view_new_with_buffer (console.total_history);
|
||||||
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (console.text_view),
|
/* View keeps reference. Unref our ref so buffer is destroyed with view. */
|
||||||
|
g_object_unref (console.total_history);
|
||||||
|
|
||||||
|
gtk_text_view_set_editable (GTK_TEXT_VIEW (console.history_view), FALSE);
|
||||||
|
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (console.history_view),
|
||||||
GTK_WRAP_WORD);
|
GTK_WRAP_WORD);
|
||||||
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (console.text_view), 6);
|
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (console.history_view), 6);
|
||||||
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (console.text_view), 6);
|
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (console.history_view), 6);
|
||||||
gtk_widget_set_size_request (console.text_view, TEXT_WIDTH, TEXT_HEIGHT);
|
gtk_widget_set_size_request (console.history_view, TEXT_WIDTH, TEXT_HEIGHT);
|
||||||
gtk_container_add (GTK_CONTAINER (scrolled_window), console.text_view);
|
gtk_container_add (GTK_CONTAINER (scrolled_window), console.history_view);
|
||||||
gtk_widget_show (console.text_view);
|
gtk_widget_show (console.history_view);
|
||||||
|
|
||||||
gtk_text_buffer_create_tag (console.console, "strong",
|
console_total_append_welcome (console.total_history);
|
||||||
"weight", PANGO_WEIGHT_BOLD,
|
|
||||||
"scale", PANGO_SCALE_LARGE,
|
|
||||||
NULL);
|
|
||||||
gtk_text_buffer_create_tag (console.console, "emphasis",
|
|
||||||
"style", PANGO_STYLE_OBLIQUE,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
{
|
/* An editor of a command to be executed. */
|
||||||
const gchar * const greetings[] =
|
|
||||||
{
|
|
||||||
"strong", N_("Welcome to TinyScheme"),
|
|
||||||
NULL, "\n",
|
|
||||||
NULL, "Copyright (c) Dimitrios Souflis",
|
|
||||||
NULL, "\n",
|
|
||||||
"strong", N_("Script-Fu Console"),
|
|
||||||
NULL, " - ",
|
|
||||||
"emphasis", N_("Interactive Scheme Development"),
|
|
||||||
NULL, "\n"
|
|
||||||
};
|
|
||||||
|
|
||||||
GtkTextIter cursor;
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
gtk_text_buffer_get_end_iter (console.console, &cursor);
|
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (greetings); i += 2)
|
|
||||||
{
|
|
||||||
if (greetings[i])
|
|
||||||
gtk_text_buffer_insert_with_tags_by_name (console.console, &cursor,
|
|
||||||
gettext (greetings[i + 1]),
|
|
||||||
-1, greetings[i],
|
|
||||||
NULL);
|
|
||||||
else
|
|
||||||
gtk_text_buffer_insert (console.console, &cursor,
|
|
||||||
gettext (greetings[i + 1]), -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The current command */
|
|
||||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
||||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
||||||
gtk_widget_show (hbox);
|
gtk_widget_show (hbox);
|
||||||
|
|
||||||
console.cc = gtk_entry_new ();
|
console.editor = console_editor_new ();
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), console.cc, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox), console.editor, TRUE, TRUE, 0);
|
||||||
gtk_widget_grab_focus (console.cc);
|
gtk_widget_grab_focus (console.editor);
|
||||||
gtk_widget_show (console.cc);
|
gtk_widget_show (console.editor);
|
||||||
|
|
||||||
g_signal_connect (console.cc, "key-press-event",
|
g_signal_connect (console.editor, "key-press-event",
|
||||||
G_CALLBACK (script_fu_cc_key_function),
|
G_CALLBACK (script_fu_editor_key_function),
|
||||||
&console);
|
&console);
|
||||||
|
|
||||||
button = gtk_button_new_with_mnemonic (_("_Browse..."));
|
button = gtk_button_new_with_mnemonic (_("_Browse..."));
|
||||||
|
@ -226,9 +188,7 @@ script_fu_console_run (GimpProcedure *procedure,
|
||||||
G_CALLBACK (script_fu_browse_callback),
|
G_CALLBACK (script_fu_browse_callback),
|
||||||
&console);
|
&console);
|
||||||
|
|
||||||
/* Initialize the history */
|
console_history_init (&console.history, console.total_history);
|
||||||
console.history = g_list_append (console.history, NULL);
|
|
||||||
console.history_len = 1;
|
|
||||||
|
|
||||||
gtk_widget_show (console.dialog);
|
gtk_widget_show (console.dialog);
|
||||||
|
|
||||||
|
@ -248,14 +208,10 @@ script_fu_console_response (GtkWidget *widget,
|
||||||
gint response_id,
|
gint response_id,
|
||||||
ConsoleInterface *console)
|
ConsoleInterface *console)
|
||||||
{
|
{
|
||||||
GtkTextIter start, end;
|
|
||||||
|
|
||||||
switch (response_id)
|
switch (response_id)
|
||||||
{
|
{
|
||||||
case RESPONSE_CLEAR:
|
case RESPONSE_CLEAR:
|
||||||
gtk_text_buffer_get_start_iter (console->console, &start);
|
console_total_history_clear (console->total_history);
|
||||||
gtk_text_buffer_get_end_iter (console->console, &end);
|
|
||||||
gtk_text_buffer_delete (console->console, &start, &end);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RESPONSE_SAVE:
|
case RESPONSE_SAVE:
|
||||||
|
@ -310,8 +266,6 @@ script_fu_console_save_response (GtkWidget *dialog,
|
||||||
gint response_id,
|
gint response_id,
|
||||||
ConsoleInterface *console)
|
ConsoleInterface *console)
|
||||||
{
|
{
|
||||||
GtkTextIter start, end;
|
|
||||||
|
|
||||||
if (response_id == GTK_RESPONSE_OK)
|
if (response_id == GTK_RESPONSE_OK)
|
||||||
{
|
{
|
||||||
gchar *filename;
|
gchar *filename;
|
||||||
|
@ -332,10 +286,7 @@ script_fu_console_save_response (GtkWidget *dialog,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_text_buffer_get_start_iter (console->console, &start);
|
str = console_total_history_get_text (console->total_history);
|
||||||
gtk_text_buffer_get_end_iter (console->console, &end);
|
|
||||||
|
|
||||||
str = gtk_text_buffer_get_text (console->console, &start, &end, FALSE);
|
|
||||||
|
|
||||||
fputs (str, fh);
|
fputs (str, fh);
|
||||||
fclose (fh);
|
fclose (fh);
|
||||||
|
@ -422,13 +373,13 @@ script_fu_browse_response (GtkWidget *widget,
|
||||||
|
|
||||||
text = g_string_append_c (text, ')');
|
text = g_string_append_c (text, ')');
|
||||||
|
|
||||||
gtk_window_set_focus (GTK_WINDOW (console->dialog), console->cc);
|
gtk_window_set_focus (GTK_WINDOW (console->dialog), console->editor);
|
||||||
|
|
||||||
gtk_entry_set_text (GTK_ENTRY (console->cc), text->str);
|
console_editor_set_text_and_position (console->editor,
|
||||||
gtk_editable_set_position (GTK_EDITABLE (console->cc),
|
text->str,
|
||||||
g_utf8_pointer_to_offset (text->str,
|
g_utf8_pointer_to_offset (
|
||||||
text->str +
|
text->str,
|
||||||
strlen (proc_name) + 2));
|
text->str + strlen (proc_name) + 2));
|
||||||
|
|
||||||
g_string_free (text, TRUE);
|
g_string_free (text, TRUE);
|
||||||
|
|
||||||
|
@ -474,6 +425,9 @@ script_fu_console_scroll_end (GtkWidget *view)
|
||||||
g_idle_add ((GSourceFunc) script_fu_console_idle_scroll_end, view);
|
g_idle_add ((GSourceFunc) script_fu_console_idle_scroll_end, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Write results of execution to the console view.
|
||||||
|
* But not put results in the history model.
|
||||||
|
*/
|
||||||
static void
|
static void
|
||||||
script_fu_output_to_console (gboolean is_error_msg,
|
script_fu_output_to_console (gboolean is_error_msg,
|
||||||
const gchar *text,
|
const gchar *text,
|
||||||
|
@ -482,91 +436,52 @@ script_fu_output_to_console (gboolean is_error_msg,
|
||||||
{
|
{
|
||||||
ConsoleInterface *console = user_data;
|
ConsoleInterface *console = user_data;
|
||||||
|
|
||||||
if (console && console->text_view)
|
if (console && console->history_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 (! is_error_msg)
|
if (! is_error_msg)
|
||||||
{
|
console_total_append_text_normal (console->total_history, text, len);
|
||||||
gtk_text_buffer_insert (buffer, &cursor, text, len);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
console_total_append_text_emphasize (console->total_history, text, len);
|
||||||
gtk_text_buffer_insert_with_tags_by_name (console->console, &cursor,
|
|
||||||
text, len, "emphasis",
|
script_fu_console_scroll_end (console->history_view);
|
||||||
NULL);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
script_fu_console_scroll_end (console->text_view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
script_fu_cc_is_empty (ConsoleInterface *console)
|
script_fu_editor_key_function (GtkWidget *widget,
|
||||||
{
|
|
||||||
const gchar *str;
|
|
||||||
|
|
||||||
if ((str = gtk_entry_get_text (GTK_ENTRY (console->cc))) == NULL)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
while (*str)
|
|
||||||
{
|
|
||||||
if (*str != ' ' && *str != '\t' && *str != '\n')
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
str ++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
script_fu_cc_key_function (GtkWidget *widget,
|
|
||||||
GdkEventKey *event,
|
GdkEventKey *event,
|
||||||
ConsoleInterface *console)
|
ConsoleInterface *console)
|
||||||
{
|
{
|
||||||
GList *list;
|
|
||||||
gint direction = 0;
|
gint direction = 0;
|
||||||
GtkTextIter cursor;
|
|
||||||
GString *output;
|
GString *output;
|
||||||
gboolean is_error;
|
gboolean is_error;
|
||||||
|
const gchar *command;
|
||||||
|
|
||||||
switch (event->keyval)
|
switch (event->keyval)
|
||||||
{
|
{
|
||||||
case GDK_KEY_Return:
|
case GDK_KEY_Return:
|
||||||
case GDK_KEY_KP_Enter:
|
case GDK_KEY_KP_Enter:
|
||||||
case GDK_KEY_ISO_Enter:
|
case GDK_KEY_ISO_Enter:
|
||||||
if (script_fu_cc_is_empty (console))
|
if (console_editor_is_empty (console->editor))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
list = g_list_nth (console->history,
|
command = g_strdup (console_editor_get_text (console->editor));
|
||||||
(g_list_length (console->history) - 1));
|
/* Put to history model.
|
||||||
|
*
|
||||||
|
* We own the command.
|
||||||
|
* This transfers ownership to history model.
|
||||||
|
* We retain a reference, used below, but soon out of scope.
|
||||||
|
*/
|
||||||
|
console_history_set_tail (&console->history, command);
|
||||||
|
|
||||||
if (list->data)
|
/* Put decorated command to total_history, distinct from history model. */
|
||||||
g_free (list->data);
|
console_total_append_command (console->total_history, command);
|
||||||
|
|
||||||
list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (console->cc)));
|
script_fu_console_scroll_end (console->history_view);
|
||||||
|
|
||||||
gtk_text_buffer_get_end_iter (console->console, &cursor);
|
console_editor_clear (console->editor);
|
||||||
|
|
||||||
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);
|
output = g_string_new (NULL);
|
||||||
script_fu_redirect_output_to_gstr (output);
|
script_fu_redirect_output_to_gstr (output);
|
||||||
|
@ -574,7 +489,7 @@ script_fu_cc_key_function (GtkWidget *widget,
|
||||||
gimp_plug_in_set_pdb_error_handler (gimp_get_plug_in (),
|
gimp_plug_in_set_pdb_error_handler (gimp_get_plug_in (),
|
||||||
GIMP_PDB_ERROR_HANDLER_PLUGIN);
|
GIMP_PDB_ERROR_HANDLER_PLUGIN);
|
||||||
|
|
||||||
is_error = script_fu_interpret_string (list->data);
|
is_error = script_fu_interpret_string (command);
|
||||||
|
|
||||||
script_fu_output_to_console (is_error,
|
script_fu_output_to_console (is_error,
|
||||||
output->str,
|
output->str,
|
||||||
|
@ -588,21 +503,7 @@ script_fu_cc_key_function (GtkWidget *widget,
|
||||||
|
|
||||||
gimp_displays_flush ();
|
gimp_displays_flush ();
|
||||||
|
|
||||||
console->history = g_list_append (console->history, NULL);
|
console_history_new_tail (&console->history);
|
||||||
|
|
||||||
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;
|
return TRUE;
|
||||||
break;
|
break;
|
||||||
|
@ -635,28 +536,20 @@ script_fu_cc_key_function (GtkWidget *widget,
|
||||||
|
|
||||||
if (direction)
|
if (direction)
|
||||||
{
|
{
|
||||||
/* Make sure we keep track of the current one */
|
/* Tail was preallocated and usually empty.
|
||||||
if (console->history_cur == g_list_length (console->history) - 1)
|
* Keep the editor contents in the tail as cursor is moved away from tail.
|
||||||
{
|
* So any edited text is not lost if user moves cursor back to tail.
|
||||||
list = g_list_nth (console->history, console->history_cur);
|
*/
|
||||||
|
command = console_editor_get_text (console->editor);
|
||||||
|
if (console_history_is_cursor_at_tail (&console->history))
|
||||||
|
console_history_set_tail (&console->history, g_strdup (command));
|
||||||
|
|
||||||
g_free (list->data);
|
/* Now move cursor and replace editor contents. */
|
||||||
list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (console->cc)));
|
console_history_move_cursor (&console->history, direction);
|
||||||
}
|
command = console_history_get_at_cursor (&console->history);
|
||||||
|
console_editor_set_text_and_position (console->editor,
|
||||||
console->history_cur += direction;
|
command,
|
||||||
|
-1);
|
||||||
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 TRUE;
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ subdir('libscriptfu')
|
||||||
subdir('scripts')
|
subdir('scripts')
|
||||||
subdir('server')
|
subdir('server')
|
||||||
subdir('interpreter')
|
subdir('interpreter')
|
||||||
|
subdir('console')
|
||||||
|
|
||||||
|
|
||||||
executable_name = 'script-fu'
|
executable_name = 'script-fu'
|
||||||
|
@ -20,7 +21,6 @@ executable_name = 'script-fu'
|
||||||
# script-fu.c also implements PDB procedure of type EXTENSION "extension-script-fu"
|
# script-fu.c also implements PDB procedure of type EXTENSION "extension-script-fu"
|
||||||
|
|
||||||
plugin_sources = [
|
plugin_sources = [
|
||||||
'script-fu-console.c',
|
|
||||||
'script-fu-eval.c',
|
'script-fu-eval.c',
|
||||||
'script-fu-text-console.c',
|
'script-fu-text-console.c',
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ executable(executable_name,
|
||||||
include_directories: [
|
include_directories: [
|
||||||
libscriptfuInclude,
|
libscriptfuInclude,
|
||||||
],
|
],
|
||||||
link_with : libscriptfu,
|
link_with : [libscriptfuconsole, libscriptfu ],
|
||||||
install: true,
|
install: true,
|
||||||
install_dir: gimpplugindir / 'plug-ins' / executable_name,
|
install_dir: gimpplugindir / 'plug-ins' / executable_name,
|
||||||
)
|
)
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include <libgimp/gimp.h>
|
#include <libgimp/gimp.h>
|
||||||
|
|
||||||
#include "script-fu-console.h"
|
#include "console/script-fu-console.h"
|
||||||
#include "script-fu-eval.h"
|
#include "script-fu-eval.h"
|
||||||
#include "script-fu-text-console.h"
|
#include "script-fu-text-console.h"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue