[rkward-cvs] rkward/rkward rkconsole.cpp,1.12,1.13 rkconsole.h,1.8,1.9
Thomas Friedrichsmeier
tfry at users.sourceforge.net
Sun Oct 16 16:02:02 UTC 2005
Update of /cvsroot/rkward/rkward/rkward
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25476/rkward
Modified Files:
rkconsole.cpp rkconsole.h
Log Message:
Allow empty lines when pasting to the console. Some code cleanups (mostly coding style)
Index: rkconsole.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rkconsole.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** rkconsole.cpp 29 Sep 2005 16:02:50 -0000 1.12
--- rkconsole.cpp 16 Oct 2005 16:01:59 -0000 1.13
***************
*** 44,58 ****
setFont (font);
! setCaption(i18n("R Console"));
! prefix = "> ";
command_incomplete = false;
clear();
!
! commandsList.append (new QString(""));
!
! commandsList.setAutoDelete( TRUE );
!
! connect (this, SIGNAL (userCommandFinished ()), this, SLOT (slotCommandFinished ()));
RKGlobals::rkApp()->m_manager->addPart (new RKConsolePart (this), false);
--- 44,57 ----
setFont (font);
! setCaption (i18n ("R Console"));
! nprefix = "> ";
! iprefix = "+ ";
! prefix = nprefix;
command_incomplete = false;
clear();
!
! commands_history.append (new QString (""));
! commands_history.setAutoDelete (true);
RKGlobals::rkApp()->m_manager->addPart (new RKConsolePart (this), false);
***************
*** 64,71 ****
}
!
!
! void RKConsole::keyPressEvent ( QKeyEvent * e )
! {
int para=0; int p=0;
getCursorPosition (¶, &p);
--- 63,67 ----
}
! void RKConsole::keyPressEvent (QKeyEvent *e) {
int para=0; int p=0;
getCursorPosition (¶, &p);
***************
*** 95,125 ****
return;
}
!
!
if (para<paragraphs () - 1 || pos <= prefix.length () - 1){
cursorAtTheEnd ();
}
! KTextEdit::keyPressEvent( e );
! }
!
!
! void RKConsole::newLine()
! {
! append (prefix);
! cursorAtTheEnd ();
}
! QString RKConsole::currentCommand()
! {
QString s = text (paragraphs () - 1).right(paragraphLength (paragraphs () - 1) - prefix.length () + 1);
s = s.stripWhiteSpace ();
! return(s);
}
!
! void RKConsole::setCurrentCommand(QString command)
! {
removeParagraph (paragraphs () - 1);
append (prefix + command);
--- 91,110 ----
return;
}
!
if (para<paragraphs () - 1 || pos <= prefix.length () - 1){
cursorAtTheEnd ();
}
! KTextEdit::keyPressEvent (e);
}
! QString RKConsole::currentCommand () {
QString s = text (paragraphs () - 1).right(paragraphLength (paragraphs () - 1) - prefix.length () + 1);
s = s.stripWhiteSpace ();
! return (s);
}
! void RKConsole::setCurrentCommand (QString command) {
removeParagraph (paragraphs () - 1);
append (prefix + command);
***************
*** 127,200 ****
}
!
! void RKConsole::cursorAtTheEnd()
! {
setCursorPosition (paragraphs () - 1, paragraphLength (paragraphs () - 1));
}
-
- void RKConsole::submitCommand()
- {
if (!currentCommand ().isEmpty ()) {
- // If we added an item to the list, we delete it here.
- if (!(commandsList.getLast () == commandsList.current ())){
- commandsList.last ();
- commandsList.remove ();
- }
- QString c = currentCommand ();
- commandsList.append (new QString (c.latin1 ()));
-
- if (command_incomplete) {
- c.prepend (incomplete_command + "\n");
- }
-
RKGlobals::rInterface ()->issueCommand (c, RCommand::User, QString::null, this);
} else {
! command_incomplete = false;
! newLine ();
}
}
!
!
! void RKConsole::commandsListUp()
! {
! if (commandsList.getFirst () == commandsList.current ()){
return;
}
// We add the current line to the list.
! if (commandsList.getLast () == commandsList.current ()) {
! commandsList.append (new QString(currentCommand ().latin1 ()));
}
! commandsList.prev ();
! QString newString = commandsList.current ()->utf8 ();
! setCurrentCommand (newString);
}
!
!
! void RKConsole::commandsListDown()
! {
! if (commandsList.getLast () == commandsList.current ()){
return;
}
! commandsList.next ();
! QString newString = commandsList.current ()->utf8 ();
setCurrentCommand (newString);
// If we are back at the begining of the list, we remove the item we've added.
! if (commandsList.getLast () == commandsList.current ()){
! commandsList.remove ();
}
}
!
! void RKConsole::cursorAtTheBeginning()
! {
setCursorPosition (paragraphs () - 1, prefix.length ());
}
-
void RKConsole::rCommandDone (RCommand *command) {
if (command->hasOutput ()) {
--- 112,169 ----
}
! void RKConsole::cursorAtTheEnd () {
setCursorPosition (paragraphs () - 1, paragraphLength (paragraphs () - 1));
}
+ void RKConsole::submitCommand () {
+ // If we added an item to the list, we delete it here.
+ if (!(commands_history.getLast () == commands_history.current ())){
+ commands_history.removeLast ();
+ }
+ QString c = currentCommand ();
+ commands_history.append (new QString (c.latin1 ()));
+
+ if (command_incomplete) {
+ c.prepend (incomplete_command + "\n");
+ }
if (!currentCommand ().isEmpty ()) {
RKGlobals::rInterface ()->issueCommand (c, RCommand::User, QString::null, this);
} else {
! tryNextInBatch ();
}
}
! void RKConsole::commandsListUp () {
! if (commands_history.getFirst () == commands_history.current ()) { // already at topmost item
return;
}
// We add the current line to the list.
! if (commands_history.getLast () == commands_history.current ()) {
! commands_history.append (new QString (currentCommand ().latin1 ()));
}
! commands_history.prev ();
! QString new_string = commands_history.current ()->utf8 ();
! setCurrentCommand (new_string);
}
! void RKConsole::commandsListDown () {
! if (commands_history.getLast () == commands_history.current ()) { // already at bottommost item
return;
}
! commands_history.next ();
! QString newString = commands_history.current ()->utf8 ();
setCurrentCommand (newString);
// If we are back at the begining of the list, we remove the item we've added.
! if (commands_history.getLast () == commands_history.current ()){
! commands_history.remove ();
}
}
! void RKConsole::cursorAtTheBeginning () {
setCursorPosition (paragraphs () - 1, prefix.length ());
}
void RKConsole::rCommandDone (RCommand *command) {
if (command->hasOutput ()) {
***************
*** 208,267 ****
if (command->errorIncomplete ()) {
! prefix = "+ ";
command_incomplete = true;
incomplete_command = command->command ();
} else {
! prefix = "> ";
command_incomplete = false;
incomplete_command = QString::null;
}
! newLine ();
! emit(userCommandFinished());
}
!
!
! void RKConsole::submitBatch(QString batch)
! {
// splitting batch, not allowing empty entries.
// TODO: hack something so we can have empty entries.
! commandsBatch = QStringList::split("\n", batch, false);
! setCurrentCommand(currentCommand() + commandsBatch.first());
! if (commandsBatch.count()!=0){
! submitCommand();
! }
! commandsBatch.erase(commandsBatch.begin());
}
! void RKConsole::slotCommandFinished()
! {
! if (!commandsBatch.empty()) {
// If we were not finished executing a batch of commands, we execute the next one.
! setCurrentCommand(currentCommand() + commandsBatch.first());
! commandsBatch.erase(commandsBatch.begin());
! if (commandsBatch.count()>=1){
! submitCommand();
}
! // We would put this here if we would want the last line to be executed
//TODO: deal with this kind of situation better.
! //commandsBatch.erase(commandsBatch.begin());
}
-
}
!
! void RKConsole::paste()
! {
! QClipboard *cb = QApplication::clipboard();
! submitBatch (cb->text());
}
! void RKConsole::clear()
! {
! KTextEdit::clear();
! newLine();
!
}
--- 177,224 ----
if (command->errorIncomplete ()) {
! prefix = iprefix;
command_incomplete = true;
incomplete_command = command->command ();
} else {
! prefix = nprefix;
command_incomplete = false;
incomplete_command = QString::null;
}
! tryNextInBatch ();
}
! void RKConsole::submitBatch (QString batch) {
// splitting batch, not allowing empty entries.
// TODO: hack something so we can have empty entries.
! commands_batch = QStringList::split ("\n", batch, true);
! tryNextInBatch ();
}
+ void RKConsole::tryNextInBatch () {
+ append (prefix);
+ cursorAtTheEnd ();
! if (!commands_batch.isEmpty()) {
// If we were not finished executing a batch of commands, we execute the next one.
! setCurrentCommand (currentCommand () + commands_batch.first ());
! commands_batch.pop_front ();
! if (!commands_batch.isEmpty ()){
! submitCommand ();
}
! // We would put this here if we would want the last line to be executed. We generally don't want this, as there is an empty last item, if there is a newline at the end.
//TODO: deal with this kind of situation better.
! //commands_batch.erase(commands_batch.begin());
}
}
! void RKConsole::paste () {
! QClipboard *cb = QApplication::clipboard ();
! submitBatch (cb->text ());
}
! void RKConsole::clear () {
! KTextEdit::clear ();
! tryNextInBatch ();
}
Index: rkconsole.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rkconsole.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** rkconsole.h 17 Sep 2005 19:23:52 -0000 1.8
--- rkconsole.h 16 Oct 2005 16:01:59 -0000 1.9
***************
*** 47,78 ****
~RKConsole();
- /** Sets the current command
- \param command the new command */
- void setCurrentCommand (QString command);
/** Submits a batch of commands, line by line.
\param batch a QString containing the batch of commands to be executed */
void submitBatch(QString batch);
-
- signals:
- void userCommandRunning (RCommand *command);
- /** Emited when the command has been executed */
- void userCommandFinished ();
protected:
void keyPressEvent ( QKeyEvent * e );
void rCommandDone (RCommand *command);
private:
- /** This string stores the prefix printed at the beginning of each line. */
- QString prefix;
QString incomplete_command;
bool command_incomplete;
/** A list to store previous commands */
! QPtrList<QString> commandsList;
/** A list to store a commands batch that will be executed one line at a time */
! QStringList commandsBatch;
/** Sets the cursor position to the end of the last line. */
void cursorAtTheEnd();
- /** Add a new line, with the prefix. */
- void newLine();
/** Returns the command currently being edited (not executed yet) */
QString currentCommand();
--- 47,66 ----
~RKConsole();
/** Submits a batch of commands, line by line.
\param batch a QString containing the batch of commands to be executed */
void submitBatch(QString batch);
protected:
void keyPressEvent ( QKeyEvent * e );
void rCommandDone (RCommand *command);
private:
QString incomplete_command;
bool command_incomplete;
/** A list to store previous commands */
! QPtrList<QString> commands_history;
/** A list to store a commands batch that will be executed one line at a time */
! QStringList commands_batch;
/** Sets the cursor position to the end of the last line. */
void cursorAtTheEnd();
/** Returns the command currently being edited (not executed yet) */
QString currentCommand();
***************
*** 85,96 ****
/** Sets the cursor position to the beginning of the last line. */
void cursorAtTheBeginning();
! /** We overload the paste function, in order to intercept paste commands and get them executed thru submitBatch.
@sa submitBatch */
void paste();
! /** We overload the clear function.*/
void clear();
! private slots:
! /** Called when a command has been executed. */
! void slotCommandFinished();
};
--- 73,92 ----
/** Sets the cursor position to the beginning of the last line. */
void cursorAtTheBeginning();
! /** We overload the paste function, in order to intercept paste commands and get them executed through submitBatch.
@sa submitBatch */
void paste();
! /** We overload the clear function, to add a prompt at the top. */
void clear();
! /** Sets the current command. This is used from commandsListUp (), and commandsListDown ();
! \param command the new command */
! void setCurrentCommand (QString command);
! /** 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. */
! void tryNextInBatch ();
! private:
! QString prefix;
! /** This string stores the regular prefix printed at the beginning of each line. */
! const char *nprefix;
! /** This string stores the continuation prefix. */
! const char *iprefix;
};
More information about the rkward-tracker
mailing list