[rkward-cvs] rkward/rkward rkconsole.cpp, 1.27, 1.28 rkconsole.h, 1.18, 1.19

Thomas Friedrichsmeier tfry at users.sourceforge.net
Mon Sep 11 00:48:57 UTC 2006


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

Modified Files:
	rkconsole.cpp rkconsole.h 
Log Message:
Simplify RKConsole command history logic

Index: rkconsole.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rkconsole.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** rkconsole.cpp	11 Sep 2006 00:26:41 -0000	1.27
--- rkconsole.cpp	11 Sep 2006 00:48:55 -0000	1.28
***************
*** 132,141 ****
  	clear ();
  
! 	commands_history.setAutoDelete (true);
! 	commands_history.append (new QString (""));
! 	QStringList history = RKSettingsModuleConsole::loadCommandHistory ();
! 	for (QStringList::const_iterator it = history.begin (); it != history.end (); ++it) {
! 		commands_history.append (new QString (*it));
! 	}
  
  	current_command = 0;
--- 132,137 ----
  	clear ();
  
! 	commands_history = RKSettingsModuleConsole::loadCommandHistory ();
! 	commands_history_position = commands_history.constBegin ();
  
  	current_command = 0;
***************
*** 146,156 ****
  	RK_TRACE (APP);
  
! 	QStringList savelist;
! 	QString *str;
! 	for (str = commands_history.first (); str; str = commands_history.next ()) {
! 		savelist.append (*str);
! 	}
! 
! 	RKSettingsModuleConsole::saveCommandHistory (savelist);
  }
  
--- 142,146 ----
  	RK_TRACE (APP);
  
! 	RKSettingsModuleConsole::saveCommandHistory (commands_history);
  }
  
***************
*** 313,320 ****
  void RKConsole::submitCommand () {
  	RK_TRACE (APP);
! 	// 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 ();
  	addCommandToHistory (c);
--- 303,307 ----
  void RKConsole::submitCommand () {
  	RK_TRACE (APP);
! 
  	QString c = currentCommand ();
  	addCommandToHistory (c);
***************
*** 335,364 ****
  void RKConsole::commandsListUp () {
  	RK_TRACE (APP);
! 	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 ()) {
! 		addCommandToHistory (currentCommand ());
! 	}
! 	commands_history.prev ();
! 	QString new_string = commands_history.current ()->utf8 ();
! 	setCurrentCommand (new_string);
  }
  
  void RKConsole::commandsListDown () {
  	RK_TRACE (APP);
! 	if (commands_history.getLast () == commands_history.current ()) {		// already at bottommost item
  		setCurrentCommand (QString::null);
  		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 ();
! 	}
  }
  
--- 322,342 ----
  void RKConsole::commandsListUp () {
  	RK_TRACE (APP);
! 	if (commands_history.constBegin () == commands_history_position) {		// already at topmost item
  		return;
  	}
! 	--commands_history_position;
! 
! 	setCurrentCommand (*commands_history_position);
  }
  
  void RKConsole::commandsListDown () {
  	RK_TRACE (APP);
! 	if (commands_history.constEnd () == commands_history_position) {		// already at bottommost item
  		setCurrentCommand (QString::null);
  		return;
  	}
! 	++commands_history_position;
! 
! 	setCurrentCommand (*commands_history_position);
  }
  
***************
*** 468,479 ****
  //	if (command.isEmpty ()) return;	// don't add empty lines		// WHOA! does not work that way!
  
! 	commands_history.append (new QString (command.latin1 ()));
  
  	if (RKSettingsModuleConsole::maxHistoryLength ()) {
  		uint c = commands_history.count ();
  		for (uint ui = c; ui > RKSettingsModuleConsole::maxHistoryLength (); --ui) {
! 			commands_history.removeFirst ();
  		}
- 		commands_history.last ();
  	}
  }
--- 446,456 ----
  //	if (command.isEmpty ()) return;	// don't add empty lines		// WHOA! does not work that way!
  
! 	commands_history_position = commands_history.append (command);
  
  	if (RKSettingsModuleConsole::maxHistoryLength ()) {
  		uint c = commands_history.count ();
  		for (uint ui = c; ui > RKSettingsModuleConsole::maxHistoryLength (); --ui) {
! 			commands_history.pop_front ();
  		}
  	}
  }

Index: rkconsole.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rkconsole.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** rkconsole.h	10 Sep 2006 23:45:40 -0000	1.18
--- rkconsole.h	11 Sep 2006 00:48:55 -0000	1.19
***************
*** 53,63 ****
  	void submitBatch (QString batch);
  /** Returns the command currently being edited (not executed yet) */
! 	QString currentCommand();
  /** Returns the current cursor position. Returns the column on which is the cursor.  */
! 	int currentCursorPosition();
  /** Returns the current cursor position, within the current command (without taking into account the prefix).*/
! 	int currentCursorPositionInCommand();
  /** Returns TRUE if some text is selected; otherwise returns FALSE.  */
! 	bool hasSelectedText();
  /** interrupt the current incomplete command (if any) */
  	void resetIncompleteCommand ();
--- 53,63 ----
  	void submitBatch (QString batch);
  /** Returns the command currently being edited (not executed yet) */
! 	QString currentCommand ();
  /** Returns the current cursor position. Returns the column on which is the cursor.  */
! 	int currentCursorPosition ();
  /** Returns the current cursor position, within the current command (without taking into account the prefix).*/
! 	int currentCursorPositionInCommand ();
  /** Returns TRUE if some text is selected; otherwise returns FALSE.  */
! 	bool hasSelectedText ();
  /** interrupt the current incomplete command (if any) */
  	void resetIncompleteCommand ();
***************
*** 87,104 ****
  	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();
  /** 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();
  /** Clear the view, and add a prompt at the top. */
  	void clear();
--- 87,105 ----
  	bool command_incomplete;
  /** A list to store previous commands */
! 	QStringList commands_history;
! 	QStringList::const_iterator commands_history_position;
  /** 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 ();
  /** 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 ();
  /** Clear the view, and add a prompt at the top. */
  	void clear();
***************
*** 119,123 ****
  \param action the KAction to be unplugged
  \param ac the action collection from which to retrieve the KAction*/
! 	void unplugAction(QString action, KActionCollection* ac);
  
  	bool output_continuation;
--- 120,124 ----
  \param action the KAction to be unplugged
  \param ac the action collection from which to retrieve the KAction*/
! 	void unplugAction (QString action, KActionCollection* ac);
  
  	bool output_continuation;
***************
*** 130,135 ****
  /** We intercept paste commands and get them executed through submitBatch.
  @sa submitBatch */
! 	void paste();
! 	void copy();
  };
  
--- 131,136 ----
  /** We intercept paste commands and get them executed through submitBatch.
  @sa submitBatch */
! 	void paste ();
! 	void copy ();
  };
  
***************
*** 162,168 ****
  };
  
- 
- 
- 
- 
  #endif
--- 163,165 ----





More information about the rkward-tracker mailing list