~l3on/ubuntu/precise/rkward/rebuild1

« back to all changes in this revision

Viewing changes to rkward/rkconsole.h

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Friedrichsmeier
  • Date: 2008-04-20 21:30:00 UTC
  • mfrom: (1.2.2 upstream) (3.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080420213000-fs4i8efmfc793bnn
new upstream release
closes: #475175
closes: #463348
closes: #475982

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
                          robjectbrowser  -  description
3
3
                             -------------------
4
4
    begin                : Thu Aug 19 2004
5
 
    copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
 
5
    copyright            : (C) 2004, 2006, 2007 by Thomas Friedrichsmeier
6
6
    email                : tfry@users.sourceforge.net
7
7
 ***************************************************************************/
8
8
 
27
27
 
28
28
#include "rbackend/rcommandreceiver.h"
29
29
#include "windows/rkcommandeditorwindow.h"
 
30
#include "windows/rkmdiwindow.h"
30
31
 
31
32
class QStringList;
32
33
class KAction;
33
34
class RCommand;
 
35
class KActionCollection;
 
36
class RKConsolePart;
34
37
 
35
38
/**
36
 
**      \brief Provides an R-like console.
37
 
**
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.
40
 
** 
41
 
        Do not construct directly. Construct an RKConsolePart instead.
42
 
        
43
 
** \sa RKwatch, KTextEdit
44
 
** 
45
 
** @author Pierre Ecochard
 
39
\brief Provides an R-like console.
 
40
 
 
41
This class provides a console, which is very similar to the classic R console. It is based on a heavily modified KatePart.
 
42
 
 
43
Do not construct directly. Construct an RKConsolePart instead.
 
44
 
 
45
\sa RKCommandLog
 
46
 
 
47
@author Pierre Ecochard
46
48
**/
47
49
 
48
 
class RKConsole : public QWidget, public RCommandReceiver, public RKScriptContextProvider {
 
50
class RKConsole : public RKMDIWindow, public RCommandReceiver, public RKScriptContextProvider {
49
51
Q_OBJECT
50
52
public:
 
53
/** Constructor. */
 
54
        RKConsole (QWidget *parent, bool tool_window, const char *name=0);
 
55
/** Destructor */
 
56
        ~RKConsole ();
 
57
 
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);
 
73
 
 
74
        static RKConsole *mainConsole () { return main_console; };
 
75
        static void setMainConsole (RKConsole *console) { main_console = console; };
 
76
 
 
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);
66
82
protected:
67
 
/** Constructor. Protected. Construct an RKConsolePart instead */
68
 
        RKConsole ();
69
 
/** Destructor */
70
 
        ~RKConsole ();
71
 
 
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);
80
 
signals:
81
 
        void doingCommand (bool busy);
82
 
        void fetchPopupMenu (QPopupMenu **menu);
83
89
private:
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 */ 
 
104
        bool command_edited;
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. */
99
 
 
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. */
110
 
        void clear();
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. */
124
136
/** This function unplugs a KAction
125
137
\param action the KAction to be unplugged
126
138
\param ac the action collection from which to retrieve the KAction*/
127
 
        void unplugAction (QString action, KActionCollection* ac);
 
139
        void unplugAction (const QString &action, KActionCollection* ac);
 
140
 
 
141
        QString cleanedSelection ();
128
142
 
129
143
        bool output_continuation;
130
144
 
133
147
        Kate::View *view;
134
148
        RKFunctionArgHinter *hinter;
135
149
 
 
150
        static RKConsole *main_console;
 
151
 
136
152
        bool tab_key_pressed_before;
 
153
 
 
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;
 
160
 
 
161
        void initializeActions (KActionCollection *ac);
 
162
        void pipeCommandThroughConsoleLocal (RCommand *command);
 
163
        bool command_was_piped;
 
164
 
 
165
        RKConsolePart *console_part;
 
166
 
 
167
        void doPopupMenu (const QPoint &pos);
137
168
public slots:
138
169
/** We intercept paste commands and get them executed through submitBatch.
139
170
@sa submitBatch */
140
171
        void paste ();
141
172
        void copy ();
 
173
        void literalCopy ();
 
174
/** Clear the view, and add a prompt at the top. */
 
175
        void clear ();
 
176
        void configure ();
 
177
/** show context help on the current word */
 
178
        void showContextHelp ();
 
179
/** interrupt current command. */
 
180
        void slotInterruptCommand ();
 
181
        void runSelection ();
142
182
};
143
183
 
144
184
/** A part interface to RKConsole. Provides the context-help functionality
146
186
@author Thomas Friedrichsmeier */
147
187
 
148
188
class RKConsolePart : public KParts::Part {
149
 
        Q_OBJECT
150
 
public:
151
 
/** constructor.
 
189
friend class RKConsole;
 
190
protected:
 
191
/** constructor. Protected. Meant to the created by the RKConsole itself
152
192
@param console The console for this part */
153
 
        RKConsolePart ();
 
193
        RKConsolePart (RKConsole *console);
154
194
/** destructor */
155
195
        ~RKConsolePart ();
156
 
public slots:
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);
163
 
private:
164
 
        KAction* context_help;
165
 
        KAction* interrupt_command;
166
 
        KAction* copy;
167
 
        KAction* paste;
168
196
 
169
 
        RKConsole *console;
 
197
        void showPopupMenu (const QPoint &pos);
170
198
};
171
199
 
172
200
#endif