28
28
#include "rbackend/rcommandreceiver.h"
29
29
#include "windows/rkcommandeditorwindow.h"
30
#include "windows/rkmdiwindow.h"
35
class KActionCollection;
36
** \brief Provides an R-like console.
38
** This class provides a console, which is very similar to the classic R console. It is mainly used by RKwatch to allow
39
** the user to enter commands manualy. It is basically just a modified KTextEdit.
41
Do not construct directly. Construct an RKConsolePart instead.
43
** \sa RKwatch, KTextEdit
45
** @author Pierre Ecochard
39
\brief Provides an R-like console.
41
This class provides a console, which is very similar to the classic R console. It is based on a heavily modified KatePart.
43
Do not construct directly. Construct an RKConsolePart instead.
47
@author Pierre Ecochard
48
class RKConsole : public QWidget, public RCommandReceiver, public RKScriptContextProvider {
50
class RKConsole : public RKMDIWindow, public RCommandReceiver, public RKScriptContextProvider {
54
RKConsole (QWidget *parent, bool tool_window, const char *name=0);
51
58
/** Submits a batch of commands, line by line.
52
59
\param batch a QString containing the batch of commands to be executed */
53
void submitBatch (QString batch);
60
void submitBatch (const QString &batch);
54
61
/** Returns the command currently being edited (not executed yet) */
55
62
QString currentCommand ();
56
63
/** Returns the current cursor position. Returns the column on which is the cursor. */
63
70
void resetIncompleteCommand ();
64
71
void doTabCompletion ();
65
72
bool provideContext (unsigned int line_rev, QString *context, int *cursor_position);
74
static RKConsole *mainConsole () { return main_console; };
75
static void setMainConsole (RKConsole *console) { main_console = console; };
77
bool isBusy () { return (current_command || command_incomplete); };
78
/** Run a user command (through console, if applicable */
79
static void pipeUserCommand (RCommand *command);
80
/** Overload for the above function: Use this, if you just need to run a string with no specials */
81
static void pipeUserCommand (const QString &command);
67
/** Constructor. Protected. Construct an RKConsolePart instead */
72
83
/** Handle keystrokes before they reach the kate-part. Return TRUE if we want the kate-part to ignore it
73
84
\param e the QKeyEvent */
74
85
bool handleKeyPress (QKeyEvent * e);
75
86
void rCommandDone (RCommand *command);
76
/** provides our own context menu */
77
void createPopupMenu (const QPoint &pos);
78
87
/** reimplemented from RCommandReceiver::newOutput () to handle output of console commands */
79
88
void newOutput (RCommand *command, ROutput *output);
81
void doingCommand (bool busy);
82
void fetchPopupMenu (QPopupMenu **menu);
84
90
friend class RKConsolePart;
85
91
bool eventFilter (QObject *o, QEvent *e);
86
92
/** set syntax-highlighting for R */
87
93
void setRHighlighting ();
94
bool doTabCompletionHelper (int line_num, const QString &line, int word_start, int word_end, const QStringList &entries);
95
/** a helper function to doTabCompletionHelper */
96
void insertCompletion (int line_num, int word_start, int word_end, const QString &completion);
88
97
QString incomplete_command;
89
98
bool command_incomplete;
90
99
/** A list to store previous commands */
91
100
QStringList commands_history;
92
101
/** current position in the commands history */
93
102
QStringList::const_iterator commands_history_position;
103
/** A flag to indicate wheter the command was edited while scrolling in the history */
94
105
/** The last line in the history is special, in that it is stored before it is submitted, but not permanently so */
95
106
QString history_editing_line;
107
/** The context to look out for, if doing a context search in the command history */
108
QString command_history_context;
96
109
/** A list to store a commands batch that will be executed one line at a time */
97
110
QStringList commands_batch;
98
111
/** Sets the cursor position to the end of the last line. */
100
112
void cursorAtTheEnd ();
101
113
/** Submits the current command */
102
114
void submitCommand ();
103
/** Set the current command to the previous command in the command list */
104
void commandsListUp ();
105
/** Set the current command to the next command in the command list */
106
void commandsListDown ();
115
/** Set the current command to the previous command in the command list
116
@param context_sensitive if set to true, history lines that do not start with command_history_context are ignored (leading to context sensitive navigation of the command history) */
117
void commandsListUp (bool context_sensitive=false);
118
/** Set the current command to the next command in the command list
119
@param context_sensitive if set to true, history lines that do not start with command_history_context are ignored (leading to context sensitive navigation of the command history) */
120
void commandsListDown (bool context_sensitive=false);
107
121
/** Sets the cursor position to the beginning of the last line. */
108
122
void cursorAtTheBeginning ();
109
/** Clear the view, and add a prompt at the top. */
111
123
/** Sets the current command. This is used from commandsListUp (), and commandsListDown ();
112
124
\param command the new command */
113
void setCurrentCommand (QString command);
125
void setCurrentCommand (const QString &command);
114
126
/** Add a new line, and try to submit the next item in a batch of (pasted) commands. If there is no batch, only add the new line. */
115
127
void tryNextInBatch (bool add_new_line = true);
116
128
/** Add given command to command history. Also checks, wether the history is longer than max length, and chops it if so. */
133
147
Kate::View *view;
134
148
RKFunctionArgHinter *hinter;
150
static RKConsole *main_console;
136
152
bool tab_key_pressed_before;
154
KAction* context_help_action;
155
KAction* run_selection_action;
156
KAction* interrupt_command_action;
157
KAction* copy_action;
158
KAction* copy_literal_action;
159
KAction* paste_action;
161
void initializeActions (KActionCollection *ac);
162
void pipeCommandThroughConsoleLocal (RCommand *command);
163
bool command_was_piped;
165
RKConsolePart *console_part;
167
void doPopupMenu (const QPoint &pos);
138
169
/** We intercept paste commands and get them executed through submitBatch.
139
170
@sa submitBatch */
174
/** Clear the view, and add a prompt at the top. */
177
/** show context help on the current word */
178
void showContextHelp ();
179
/** interrupt current command. */
180
void slotInterruptCommand ();
181
void runSelection ();
144
184
/** A part interface to RKConsole. Provides the context-help functionality
146
186
@author Thomas Friedrichsmeier */
148
188
class RKConsolePart : public KParts::Part {
189
friend class RKConsole;
191
/** constructor. Protected. Meant to the created by the RKConsole itself
152
192
@param console The console for this part */
193
RKConsolePart (RKConsole *console);
154
194
/** destructor */
155
195
~RKConsolePart ();
157
/** show context help on the current word */
158
void showContextHelp ();
159
void setDoingCommand (bool busy);
160
/** interrupt current command. */
161
void slotInterruptCommand ();
162
void makePopupMenu (QPopupMenu **menu);
164
KAction* context_help;
165
KAction* interrupt_command;
197
void showPopupMenu (const QPoint &pos);