[rkward-cvs] SF.net SVN: rkward: [1823] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Apr 18 14:22:31 UTC 2007


Revision: 1823
          http://svn.sourceforge.net/rkward/?rev=1823&view=rev
Author:   tfry
Date:     2007-04-18 07:22:31 -0700 (Wed, 18 Apr 2007)

Log Message:
-----------
improvements to tab completion

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/rkconsole.cpp
    trunk/rkward/rkward/rkconsole.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2007-04-17 16:46:01 UTC (rev 1822)
+++ trunk/rkward/ChangeLog	2007-04-18 14:22:31 UTC (rev 1823)
@@ -1,3 +1,5 @@
+- tab-completion in the console will do partial completion, if all potential completion have a common start
+- fixed: file-name completion would always assume the home directory as the current directory
 - compilation fix for FreeBSD (thanks to Thierry Thomas)
 - fixed: when executing commands line by line from the script editor, line breaks would be omitted
 - Messages, warnings, and errors for plugin commands are shown in the output, instead of in a dialog

Modified: trunk/rkward/rkward/rkconsole.cpp
===================================================================
--- trunk/rkward/rkward/rkconsole.cpp	2007-04-17 16:46:01 UTC (rev 1822)
+++ trunk/rkward/rkward/rkconsole.cpp	2007-04-18 14:22:31 UTC (rev 1823)
@@ -17,6 +17,7 @@
 #include "rkconsole.h"
 
 #include <qfont.h>
+#include <qdir.h>
 #include <qstringlist.h>
 #include <qclipboard.h>
 #include <qapplication.h>
@@ -282,6 +283,14 @@
 	return true;
 }
 
+void RKConsole::insertCompletion (int line_num, int word_start, int word_end, const QString &completion) {
+	RK_TRACE (APP);
+
+	int offset = prefix.length ();
+	doc->removeText (line_num, offset + word_start, line_num, offset + word_end);
+	doc->insertText (line_num, offset + word_start, completion);
+}
+
 bool RKConsole::doTabCompletionHelper (int line_num, const QString &line, int word_start, int word_end, const QStringList &entries) {
 	RK_TRACE (APP);
 
@@ -290,10 +299,8 @@
 	if (!count) return false;
 
 	if (count == 1) {
-		int offset = prefix.length ();
 		it = entries.constBegin ();
-		doc->removeText (line_num, offset + word_start, line_num, offset + word_end);
-		doc->insertText (line_num, offset + word_start, *it);
+		insertCompletion (line_num, word_start, word_end, *it);
 	} else if (tab_key_pressed_before) {
 		int i=0;
 		for (it = entries.constBegin (); it != entries.constEnd (); ++it) {
@@ -308,6 +315,38 @@
 		cursorAtTheEnd ();
 	} else {
 		tab_key_pressed_before = true;
+
+		// do all entries have a common start?
+		QString common;
+		bool done = false;
+		unsigned int i = 0;
+		while (!done) {
+			bool ok = true;
+			QChar current;
+			for (it = entries.constBegin (); it != entries.constEnd (); ++it) {
+				if (it == entries.constBegin ()) {
+					current = (*it).at(i);
+				}
+				QChar dummy = (*it).at(i);
+				if (dummy.isNull ()) {
+					ok = false;
+					break;
+				} else if (dummy != current) {
+					ok = false;
+					break;
+				}
+			}
+			if (ok) common.append (current);
+			else break;
+			++i;
+		}
+		if (i > 0) {
+			if (common.length() > (word_end - word_start)) {		// more than there already is
+				insertCompletion (line_num, word_start, word_end, common);
+				return false;	// will beep to signal completion is not complete
+			}
+		}
+
 		return true;
 	}
 	tab_key_pressed_before = false;
@@ -350,6 +389,7 @@
 	
 			QString current_name = current_line.mid (quote_start + 1, quote_end - quote_start - 1);
 			KURLCompletion comp (KURLCompletion::FileCompletion);
+			comp.setDir (QDir::currentDirPath ());
 			QString test = comp.makeCompletion (current_name);
 	
 			if (doTabCompletionHelper (current_line_num, current_line, quote_start+1, quote_end, comp.allMatches ())) return;

Modified: trunk/rkward/rkward/rkconsole.h
===================================================================
--- trunk/rkward/rkward/rkconsole.h	2007-04-17 16:46:01 UTC (rev 1822)
+++ trunk/rkward/rkward/rkconsole.h	2007-04-18 14:22:31 UTC (rev 1823)
@@ -92,6 +92,8 @@
 /** set syntax-highlighting for R */
 	void setRHighlighting ();
 	bool doTabCompletionHelper (int line_num, const QString &line, int word_start, int word_end, const QStringList &entries);
+/** a helper function to doTabCompletionHelper */
+	void insertCompletion (int line_num, int word_start, int word_end, const QString &completion);
 	QString incomplete_command;
 	bool command_incomplete;
 /** A list to store previous commands */


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