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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Oct 19 18:38:00 UTC 2006


Revision: 887
          http://svn.sourceforge.net/rkward/?rev=887&view=rev
Author:   tfry
Date:     2006-10-19 11:37:53 -0700 (Thu, 19 Oct 2006)

Log Message:
-----------
Tab completion in console is working half decently

Modified Paths:
--------------
    trunk/rkward/rkward/core/rcontainerobject.cpp
    trunk/rkward/rkward/misc/rkcommonfunctions.cpp
    trunk/rkward/rkward/rkconsole.cpp
    trunk/rkward/rkward/rkconsole.h

Modified: trunk/rkward/rkward/core/rcontainerobject.cpp
===================================================================
--- trunk/rkward/rkward/core/rcontainerobject.cpp	2006-10-19 17:13:20 UTC (rev 886)
+++ trunk/rkward/rkward/core/rcontainerobject.cpp	2006-10-19 18:37:53 UTC (rev 887)
@@ -237,6 +237,17 @@
 	QString current_level = canonified.section (QChar ('$'), 0, 0);
 	QString remainder = canonified.section (QChar ('$'), 1);
 
+	if (canonified.endsWith (QChar ('$'))) {
+		RObjectMap::iterator it = childmap.find (current_level);
+		
+		if (it == childmap.end ()) return;
+		
+		RObject *found = it.data ();
+		found->findObjectsMatching (QString (), current_list, true);
+
+		return;
+	}
+
 	if (remainder.isEmpty ()) {
 		for (RObjectMap::const_iterator it = childmap.constBegin (); it != childmap.constEnd (); ++it) {
 			if (it.key ().startsWith (current_level)) {

Modified: trunk/rkward/rkward/misc/rkcommonfunctions.cpp
===================================================================
--- trunk/rkward/rkward/misc/rkcommonfunctions.cpp	2006-10-19 17:13:20 UTC (rev 886)
+++ trunk/rkward/rkward/misc/rkcommonfunctions.cpp	2006-10-19 18:37:53 UTC (rev 887)
@@ -129,6 +129,7 @@
 		// find out the next non-word stuff left and right of the current cursor position
 		*start = context_line.findRev (rx_no_word, cursor_pos-1) + 1;
 		*end = context_line.find (rx_no_word, cursor_pos);
+		if (*end < 0) *end = context_line.length ();
 	}
 
 }	// namespace

Modified: trunk/rkward/rkward/rkconsole.cpp
===================================================================
--- trunk/rkward/rkward/rkconsole.cpp	2006-10-19 17:13:20 UTC (rev 886)
+++ trunk/rkward/rkward/rkconsole.cpp	2006-10-19 18:37:53 UTC (rev 887)
@@ -27,6 +27,7 @@
 #include <kaction.h>
 #include <kactioncollection.h>
 #include <kconfig.h>
+#include <kapplication.h>
 
 #include "rkglobals.h"
 #include "rkward.h"
@@ -130,6 +131,7 @@
 	commands_history_position = commands_history.constEnd ();
 
 	current_command = 0;
+	tab_key_pressed_before = false;
 }
 
 
@@ -190,7 +192,7 @@
 
 	if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
 		submitCommand ();
-		return TRUE;
+		return true;
 	}
 	else if (e->state () == Qt::ShiftButton && e->key () == Qt::Key_Home){
 		if(hasSelectedText())
@@ -207,13 +209,13 @@
 			return FALSE;
 		}
 	}
-	else if (e->key () == Qt::Key_Up){
+	else if (e->key () == Qt::Key_Up) {
 		commandsListUp ();
-		return TRUE;
+		return true;
 	}
-	else if (e->key () == Qt::Key_Down){
+	else if (e->key () == Qt::Key_Down) {
 		commandsListDown ();
-		return TRUE;
+		return true;
 	}
 	else if (e->key () == Qt::Key_Left){
 		if(pos<=prefix.length ()){
@@ -250,18 +252,46 @@
 void RKConsole::doTabCompletion () {
 	RK_TRACE (APP);
 
-	QString current_symbol = RKCommonFunctions::getCurrentSymbol (currentCommand (), currentCursorPositionInCommand (), false);
+	QString current_line = currentCommand ();
+	int word_start;
+	int word_end;
+	int cursor_pos = currentCursorPositionInCommand ();
+	RKCommonFunctions::getCurrentSymbolOffset (current_line, cursor_pos, false, &word_start, &word_end);
+
+	QString current_symbol = current_line.mid (word_start, word_end - word_start);
 	if (!current_symbol.isEmpty ()) {
 		RObject::RObjectMap map;
+		RObject::RObjectMap::const_iterator it;
 		RObjectList::getObjectList ()->findObjectsMatching (current_symbol, &map);
 		QValueList<KTextEditor::CompletionEntry> list;
-		for (RObject::RObjectMap::const_iterator it = map.constBegin (); it != map.constEnd (); ++it) {
-			KTextEditor::CompletionEntry entry;
-			entry.text = it.key ();
-			list.append (entry);
+		int count = map.count ();
+
+		if (count == 1) {
+			int current_line = doc->numLines () - 1;
+			int offset = prefix.length ();
+			it = map.constBegin ();
+			doc->removeText (current_line, offset + word_start, current_line, offset + word_end);
+			doc->insertText (current_line, offset + word_start, it.key ());
+		} else if (count == 0) {
+			KApplication::kApplication ()->beep ();
+		} else if (tab_key_pressed_before) {
+			int i=0;
+			for (it = map.constBegin (); it != map.constEnd (); ++it) {
+				if (i % 3) {
+					doc->insertText (doc->numLines () - 1, 0, it.key ().leftJustify (35));
+				} else {
+					doc->insertText (doc->numLines (), 0, it.key ());
+				}
+				++i;
+			}
+			doc->insertText (doc->numLines (),  0, prefix + current_line);
+			cursorAtTheEnd ();
+		} else {
+			tab_key_pressed_before = true;
+			return;
 		}
-		view->showCompletionBox (list);
 	}
+	tab_key_pressed_before = false;
 }
 
 bool RKConsole::eventFilter (QObject *, QEvent *e) {

Modified: trunk/rkward/rkward/rkconsole.h
===================================================================
--- trunk/rkward/rkward/rkconsole.h	2006-10-19 17:13:20 UTC (rev 886)
+++ trunk/rkward/rkward/rkconsole.h	2006-10-19 18:37:53 UTC (rev 887)
@@ -30,8 +30,8 @@
 class QStringList;
 class KAction;
 class RCommand;
+class KateCodeCompletion;
 
-
 /**
 ** 	\brief Provides an R-like console.
 **
@@ -131,6 +131,7 @@
 	Kate::Document *doc;
 	Kate::View *view;
 
+	bool tab_key_pressed_before;
 public slots:
 /** We intercept paste commands and get them executed through submitBatch.
 @sa submitBatch */


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