[rkward-cvs] SF.net SVN: rkward: [1142] trunk/rkward/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Sun Jan 14 17:16:53 UTC 2007
Revision: 1142
http://svn.sourceforge.net/rkward/?rev=1142&view=rev
Author: tfry
Date: 2007-01-14 09:16:53 -0800 (Sun, 14 Jan 2007)
Log Message:
-----------
SHIFT + KEY_U/DOWN searches command history context sensitive (adopted from patch by Roland Vollgraf).
Beep when at end (top / bottom) of command history
Modified Paths:
--------------
trunk/rkward/rkward/rkconsole.cpp
trunk/rkward/rkward/rkconsole.h
Modified: trunk/rkward/rkward/rkconsole.cpp
===================================================================
--- trunk/rkward/rkward/rkconsole.cpp 2007-01-14 15:27:26 UTC (rev 1141)
+++ trunk/rkward/rkward/rkconsole.cpp 2007-01-14 17:16:53 UTC (rev 1142)
@@ -2,7 +2,7 @@
robjectbrowser - description
-------------------
begin : Thu Aug 19 2004
- copyright : (C) 2004, 2006 by Thomas Friedrichsmeier
+ copyright : (C) 2004, 2006, 2007 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -202,6 +202,16 @@
return true;
}
+ if (e->key () == Qt::Key_Up) {
+ commandsListUp (e->state() & Qt::ShiftButton);
+ return true;
+ }
+ else if (e->key () == Qt::Key_Down) {
+ commandsListDown (e->state() & Qt::ShiftButton);
+ return true;
+ }
+ command_edited = true; // all other keys are considered as "editing" the current comand
+
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
hinter->hideArgHint ();
submitCommand ();
@@ -222,14 +232,6 @@
return false;
}
}
- else if (e->key () == Qt::Key_Up) {
- commandsListUp ();
- return true;
- }
- else if (e->key () == Qt::Key_Down) {
- commandsListDown ();
- return true;
- }
else if (e->key () == Qt::Key_Left){
if(pos<=prefix.length ()){
return true;
@@ -402,21 +404,68 @@
}
}
-void RKConsole::commandsListUp () {
+void RKConsole::commandsListUp (bool context_sensitive) {
RK_TRACE (APP);
- if (commands_history.constBegin () == commands_history_position) return; // already at topmost item
+
+ // if we are at the last line, i.e. not yet navigating the command history, store the current command
if (commands_history.constEnd () == commands_history_position) history_editing_line = currentCommand ();
- --commands_history_position;
- setCurrentCommand (*commands_history_position);
+ if (context_sensitive) {
+ if (command_edited) {
+ command_history_context = currentCommand ();
+ commands_history_position = commands_history.constEnd ();
+ command_edited = false;
+ }
+ } else {
+ command_edited = true;
+ }
+
+ bool found = false;
+ QStringList::const_iterator it = commands_history_position;
+ while (it != commands_history.constBegin ()) {
+ --it;
+ if ((!context_sensitive) || (*it).startsWith (command_history_context)) { // we found a match or previous line
+ found = true;
+ break;
+ }
+ }
+
+ if (found) { // if we did not find a previous matching line, do not touch the commands_history_position
+ commands_history_position = it;
+ setCurrentCommand (*commands_history_position);
+ } else {
+ KApplication::kApplication ()->beep ();
+ }
}
-void RKConsole::commandsListDown () {
+void RKConsole::commandsListDown (bool context_sensitive) {
RK_TRACE (APP);
- if (commands_history.constEnd () == commands_history_position) return; // already at bottommost item
- ++commands_history_position;
+
+ if (context_sensitive) {
+ if (command_edited) {
+ command_history_context = currentCommand ();
+ commands_history_position = commands_history.constEnd ();
+ command_edited = false;
+ return; // back at bottommost item
+ }
+ } else {
+ command_edited = true;
+ }
+
+ if (commands_history.constEnd () == commands_history_position) { // already at bottommost item
+ KApplication::kApplication ()->beep ();
+ return;
+ }
+
+ while (commands_history_position != commands_history.constEnd ()) {
+ ++commands_history_position;
+ if ((!context_sensitive) || (*commands_history_position).startsWith (command_history_context)) { // we found a match or next line
+ break;
+ }
+ }
+
if (commands_history.constEnd () == commands_history_position) setCurrentCommand (history_editing_line);
- else setCurrentCommand (*commands_history_position);
+ else setCurrentCommand (*commands_history_position);
}
void RKConsole::rCommandDone (RCommand *command) {
@@ -525,7 +574,7 @@
void RKConsole::addCommandToHistory (const QString &command) {
RK_TRACE (APP);
- if (command.isEmpty ()) return; // don't add empty lines
+ if (command.isEmpty () || commands_history.last() == command) return; // don't add empty or duplicate lines
commands_history.append (command);
history_editing_line = QString::null;
Modified: trunk/rkward/rkward/rkconsole.h
===================================================================
--- trunk/rkward/rkward/rkconsole.h 2007-01-14 15:27:26 UTC (rev 1141)
+++ trunk/rkward/rkward/rkconsole.h 2007-01-14 17:16:53 UTC (rev 1142)
@@ -2,7 +2,7 @@
robjectbrowser - description
-------------------
begin : Thu Aug 19 2004
- copyright : (C) 2004, 2006 by Thomas Friedrichsmeier
+ copyright : (C) 2004, 2006, 2007 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -98,18 +98,24 @@
QStringList commands_history;
/** current position in the commands history */
QStringList::const_iterator commands_history_position;
+/** A flag to indicate wheter the command was edited while scrolling in the history */
+ bool command_edited;
/** The last line in the history is special, in that it is stored before it is submitted, but not permanently so */
QString history_editing_line;
+/** The context to look out for, if doing a context search in the command history */
+ QString command_history_context;
/** 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 ();
+/** Set the current command to the previous command in the command list
+ at 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) */
+ void commandsListUp (bool context_sensitive=false);
+/** Set the current command to the next command in the command list
+ at 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) */
+ void commandsListDown (bool context_sensitive=false);
/** Sets the cursor position to the beginning of the last line. */
void cursorAtTheBeginning ();
/** Sets the current command. This is used from commandsListUp (), and commandsListDown ();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list