[rkward-cvs] rkward/rkward rkconsole.cpp,1.6,1.7 rkconsole.h,1.3,1.4

Pierre ecoch at users.sourceforge.net
Sun Apr 17 17:42:27 UTC 2005


Update of /cvsroot/rkward/rkward/rkward
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24408/rkward

Modified Files:
	rkconsole.cpp rkconsole.h 
Log Message:
Console now handle paste correctly.

Index: rkconsole.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rkconsole.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** rkconsole.cpp	15 Apr 2005 21:38:08 -0000	1.6
--- rkconsole.cpp	17 Apr 2005 17:42:25 -0000	1.7
***************
*** 22,25 ****
--- 22,28 ----
   
  #include <qfont.h>
+ #include <qstringlist.h>
+ #include <qclipboard.h>
+ #include <qapplication.h>
   
  #include <klocale.h>
***************
*** 47,50 ****
--- 50,54 ----
  	commandsList.setAutoDelete( TRUE );
  	
+ 	connect (this, SIGNAL (userCommandFinished ()), this, SLOT (slotCommandFinished ()));
  }
  
***************
*** 55,58 ****
--- 59,63 ----
  
  
+ 
  void RKConsole::keyPressEvent ( QKeyEvent * e )
  {
***************
*** 81,90 ****
  	}
  	else if (e->key () == Qt::Key_Home){
! 		cursorAtTheBegining ();
  		return;
  	}
  	
  	
- 	
  	if (para<paragraphs () - 1 || pos <= prefix.length () - 1){
  		cursorAtTheEnd ();
--- 86,94 ----
  	}
  	else if (e->key () == Qt::Key_Home){
! 		cursorAtTheBeginning ();
  		return;
  	}
  	
  	
  	if (para<paragraphs () - 1 || pos <= prefix.length () - 1){
  		cursorAtTheEnd ();
***************
*** 189,197 ****
  
  
! /*!
!     \fn RKConsole::cursorAtTheBegining()
!     Puts the cursor at the begining of the last line.
!  */
! void RKConsole::cursorAtTheBegining()
  {
  	setCursorPosition (paragraphs () - 1, prefix.length ());
--- 193,197 ----
  
  
! void RKConsole::cursorAtTheBeginning()
  {
  	setCursorPosition (paragraphs () - 1, prefix.length ());
***************
*** 218,222 ****
--- 218,264 ----
  
  	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());
  }
  
  #include "rkconsole.moc"
+ 
+ 
+ 
+ 
+ 
+ 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());
+ }

Index: rkconsole.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rkconsole.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** rkconsole.h	15 Apr 2005 14:15:29 -0000	1.3
--- rkconsole.h	17 Apr 2005 17:42:25 -0000	1.4
***************
*** 32,55 ****
  @author Pierre Ecochard
  */
  class RKConsole : public QTextEdit, public RCommandReceiver {
  Q_OBJECT
  public:
! /** Constructor */
!     RKConsole(QWidget *parent = 0, const char *name = 0);
! /** Destructor */
!     ~RKConsole();
!     
! /** Empties the console */
!     void flush ();
! /** Sets the current command
! \param command the new command */
!     void setCurrentCommand (QString command);
  
  signals:
  	void userCommandRunning (RCommand *command);
  protected:
  	void keyPressEvent ( QKeyEvent * e );
  	void rCommandDone (RCommand *command);
  private:
  	QString prefix;
  	QString incomplete_command;
--- 32,65 ----
  @author Pierre Ecochard
  */
+ 
+ class QStringList;
+ 
  class RKConsole : public QTextEdit, public RCommandReceiver {
  Q_OBJECT
  public:
! 	/** Constructor */
! 	RKConsole(QWidget *parent = 0, const char *name = 0);
! 	/** Destructor */
! 	~RKConsole();
! 	
! 	/** Empties the console */
! 	void flush ();
! 	/** 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;
***************
*** 57,71 ****
  /** A list to store previous commands */
  	QPtrList<QString> commandsList;
  /** Sets the cursor position to the end of the last line. */
!     void cursorAtTheEnd();
!     void newLine();
!     QString currentCommand();
! /**
! Submits the current command
! */
!     void submitCommand();
!     void commandsListUp();
!     void commandsListDown();
!     void cursorAtTheBegining();
  };
  
--- 67,93 ----
  /** 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();
! /** Submits the current command */
! 	void submitCommand();
! /** Set the current command to the previous command in the command list */
! 	void commandsListUp();
! /** Set the current command to the next command in the command list */
! 	void commandsListDown();
! /** 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();
!     
! private slots:
! /** Called when a command has been executed. */
! 	void slotCommandFinished();
  };
  





More information about the rkward-tracker mailing list