[rkward-cvs] SF.net SVN: rkward: [2164] branches/KDE4_port

tfry at users.sourceforge.net tfry at users.sourceforge.net
Fri Nov 2 12:50:19 UTC 2007


Revision: 2164
          http://rkward.svn.sourceforge.net/rkward/?rev=2164&view=rev
Author:   tfry
Date:     2007-11-02 05:50:18 -0700 (Fri, 02 Nov 2007)

Log Message:
-----------
Some fixes (some hopefully temporary) to code completion

Modified Paths:
--------------
    branches/KDE4_port/ChangeLog
    branches/KDE4_port/rkward/windows/rkcommandeditorwindow.cpp
    branches/KDE4_port/rkward/windows/rkcommandeditorwindow.h

Modified: branches/KDE4_port/ChangeLog
===================================================================
--- branches/KDE4_port/ChangeLog	2007-11-02 12:14:59 UTC (rev 2163)
+++ branches/KDE4_port/ChangeLog	2007-11-02 12:50:18 UTC (rev 2164)
@@ -5,6 +5,7 @@
 ---- KDE 3 versions
 
 
+- More reliable C stack limit detection on some systems
 - Fixed: Console accepted pasted input while a command is running
 - Fixed: Analysis->Moments->Moment plugin did not use the order-parameter
 - Fixed: Crash on simple assignments in globalenv() with R < 2.4.0

Modified: branches/KDE4_port/rkward/windows/rkcommandeditorwindow.cpp
===================================================================
--- branches/KDE4_port/rkward/windows/rkcommandeditorwindow.cpp	2007-11-02 12:14:59 UTC (rev 2163)
+++ branches/KDE4_port/rkward/windows/rkcommandeditorwindow.cpp	2007-11-02 12:50:18 UTC (rev 2164)
@@ -20,7 +20,6 @@
 
 #include <ktexteditor/configinterface.h>
 #include <ktexteditor/sessionconfiginterface.h>
-#include <ktexteditor/codecompletioninterface.h>
 #include <ktexteditor/editorchooser.h>
 
 #include <qlayout.h>
@@ -94,17 +93,22 @@
 	connect (m_doc, SIGNAL (textChanged (KTextEditor::Document*)), this, SLOT (tryCompletionProxy (KTextEditor::Document*)));
 	// somehow the katepart loses the context menu each time it loses focus
 	connect (m_view, SIGNAL (focusIn(KTextEditor::View*)), this, SLOT (focusIn(KTextEditor::View*)));
-	connect (m_view, SIGNAL (focusOut(KTextEditor::View*)), this, SLOT (focusOut(KTextEditor::View*)));
 	completion_timer = new QTimer (this);
 	connect (completion_timer, SIGNAL (timeout ()), this, SLOT (tryCompletion()));
 
+	completion_model = 0;
+	cc_iface = 0;
+	hinter = 0;
 	if (use_r_highlighting) {
 		setRHighlighting ();
-		completion_model = new RKCodeCompletionModel (m_view);
+		cc_iface = qobject_cast<KTextEditor::CodeCompletionInterface*> (m_view);
+		if (cc_iface) {
+			cc_iface->setAutomaticInvocationEnabled (true);
+			completion_model = new RKCodeCompletionModel (this);
+		} else {
+			RK_ASSERT (false);
+		}
 		hinter = new RKFunctionArgHinter (this, m_view);
-	} else {
-		hinter = 0;
-		completion_model = 0;
 	}
 
 	updateCaption ();	// initialize
@@ -239,17 +243,31 @@
 
 void RKCommandEditorWindow::tryCompletionProxy (KTextEditor::Document*) {
 	if (RKSettingsModuleCommandEditor::completionEnabled ()) {
-		completion_timer->start (RKSettingsModuleCommandEditor::completionTimeout (), true);
+		if (cc_iface && cc_iface->isCompletionActive ()) {
+			tryCompletion ();
+		} else {
+			completion_timer->start (RKSettingsModuleCommandEditor::completionTimeout (), true);
+		}
 	}
 }
 
+QString RKCommandEditorWindow::currentCompletionWord () const {
+	RK_TRACE (COMMANDEDITOR);
+// KDE4 TODO: This may no longer be needed, if the katepart gets fixed not to abort completions when the range
+// contains dots or other special characters
+	KTextEditor::Cursor c = m_view->cursorPosition();
+	uint para=c.line(); uint cursor_pos=c.column();
+
+	QString current_line = m_doc->line (para);
+	if (current_line.findRev ("#", cursor_pos) >= 0) return QString ();	// do not hint while in comments
+
+	return RKCommonFunctions::getCurrentSymbol (current_line, cursor_pos, false);
+}
+
 void RKCommandEditorWindow::tryCompletion () {
 	// TODO: merge this with RKConsole::doTabCompletion () somehow
 	RK_TRACE (COMMANDEDITOR);
-	if (!completion_model) return;
-
-	KTextEditor::CodeCompletionInterface *iface = qobject_cast<KTextEditor::CodeCompletionInterface*> (m_view);
-	if (!iface) {
+	if ((!cc_iface) || (!completion_model)) {
 		RK_ASSERT (false);
 		return;
 	}
@@ -258,24 +276,24 @@
 	uint para=c.line(); uint cursor_pos=c.column();
 
 	QString current_line = m_doc->line (para);
-	if (current_line.findRev ("#", cursor_pos) >= 0) return;	// do not hint while in comments
-
 	int start;
 	int end;
 	RKCommonFunctions::getCurrentSymbolOffset (current_line, cursor_pos, false, &start, &end);
-	if ((end - start) >= RKSettingsModuleCommandEditor::completionMinChars ()) {
-		KTextEditor::Range range (para, start, para, end);
 
-		completion_model->updateCompletionList (m_doc->text (range));
+	KTextEditor::Range range = KTextEditor::Range (para, start, para, end);
+	QString word = m_doc->text (range);
+	if (current_line.findRev ("#", cursor_pos) >= 0) word.clear ();	// do not hint while in comments
+	if (word.length () >= RKSettingsModuleCommandEditor::completionMinChars ()) {
+		completion_model->updateCompletionList (word);
 		if (completion_model->isEmpty ()) {
-			iface->abortCompletion ();
+			cc_iface->abortCompletion ();
 		} else {
-			if (!iface->isCompletionActive ()) {
-				iface->startCompletion (range, completion_model);
+			if (!cc_iface->isCompletionActive ()) {
+				cc_iface->startCompletion (range, completion_model);
 			}
 		}
 	} else {
-		iface->abortCompletion ();
+		cc_iface->abortCompletion ();
 	}
 }
 
@@ -484,17 +502,11 @@
 
 //////////////////////// RKCodeCompletionModel ////////////////////
 
-RKCodeCompletionModel::RKCodeCompletionModel (KTextEditor::View *parent) : KTextEditor::CodeCompletionModel (parent) {
+RKCodeCompletionModel::RKCodeCompletionModel (RKCommandEditorWindow *parent) : KTextEditor::CodeCompletionModel (parent) {
 	RK_TRACE (COMMANDEDITOR);
 
 	setRowCount (0);
-
-	KTextEditor::CodeCompletionInterface *iface = qobject_cast<KTextEditor::CodeCompletionInterface*> (parent);
-	if (!iface) {
-		RK_ASSERT (false);
-		return;
-	}
-	iface->setAutomaticInvocationEnabled (false);
+	command_editor = parent;
 }
 
 RKCodeCompletionModel::~RKCodeCompletionModel () {
@@ -509,33 +521,42 @@
 	RObject::RObjectSearchMap map;
 	RObjectList::getObjectList ()->findObjectsMatching (symbol, &map);
 
-//KDE4 TODO: clean up once the format of findObjectsMatching is solid
+	int count = map.size ();
 	list.clear ();
+	list_names.clear ();
+	list.reserve (count);
+	list_names.reserve (count);
 	// this is silly, but we need an int indexable storage, so we copy the map to a list
 	for (RObject::RObjectSearchMap::const_iterator it = map.constBegin (); it != map.constEnd (); ++it) {
 		list.append (it.data ());
+		// the second list is used to store the name that should be used for completion.
+		// This may be object->getBaseName() or object->getFullName () depending on whether the object is
+		// masked or not.
+		list_names.append (it.key ());
 	}
 
-	setRowCount (list.count ());
+	setRowCount (count);
 	current_symbol = symbol;
 
 	reset ();
 }
 
-void RKCodeCompletionModel::completionInvoked (KTextEditor::View *view, const KTextEditor::Range &range, InvocationType) {
+void RKCodeCompletionModel::completionInvoked (KTextEditor::View*, const KTextEditor::Range&, InvocationType) {
 	RK_TRACE (COMMANDEDITOR);
 
-	updateCompletionList (view->document ()->text (range));
+	// we totally ignore whichever range the katepart thinks we should offer a completion on.
+	// it is often wrong, esp, when there are dots in the symbol
+// KDE4 TODO: This may no longer be needed, if the katepart gets fixed not to abort completions when the range
+// contains dots or other special characters
+	updateCompletionList (command_editor->currentCompletionWord ());
 }
 
 void RKCodeCompletionModel::executeCompletionItem (KTextEditor::Document *document, const KTextEditor::Range &word, int row) const {
 	RK_TRACE (COMMANDEDITOR);
 
-	RK_ASSERT (list.size () > row);
-	RObject *object = list[row];
-	RK_ASSERT (object);
+	RK_ASSERT (list_names.size () > row);
 
-	document->replaceText (word, object->getFullName ());
+	document->replaceText (word, list_names[row]);
 }
 
 QVariant RKCodeCompletionModel::data (const QModelIndex& index, int role) const {

Modified: branches/KDE4_port/rkward/windows/rkcommandeditorwindow.h
===================================================================
--- branches/KDE4_port/rkward/windows/rkcommandeditorwindow.h	2007-11-02 12:14:59 UTC (rev 2163)
+++ branches/KDE4_port/rkward/windows/rkcommandeditorwindow.h	2007-11-02 12:50:18 UTC (rev 2164)
@@ -18,11 +18,13 @@
 #define RKCOMMANDEDITORWINDOW_H
 
 #include <QWidget>
+#include <QVector>
 #include <qstring.h>
 
 #include <ktexteditor/view.h>
 #include <ktexteditor/document.h>
 #include <ktexteditor/codecompletionmodel.h>
+#include <ktexteditor/codecompletioninterface.h>
 #include <kurl.h>
 
 #include "../windows/rkmdiwindow.h"
@@ -31,6 +33,7 @@
 class QCloseEvent;
 class QFrame;
 class QLabel;
+class RKCommandEditorWindow;
 
 /** classes wishing to use RKFunctionArgHinter should derive from this, and implement provideContext () */
 class RKScriptContextProvider {
@@ -74,18 +77,20 @@
 /** code completion model for RKCommandEditorWindow */
 class RKCodeCompletionModel : public KTextEditor::CodeCompletionModel {
 public:
-	RKCodeCompletionModel (KTextEditor::View* parent);
+	RKCodeCompletionModel (RKCommandEditorWindow* parent);
 	~RKCodeCompletionModel ();
 
 	void updateCompletionList (const QString& symbol);
-	void completionInvoked (KTextEditor::View *view, const KTextEditor::Range &range, InvocationType);
+	void completionInvoked (KTextEditor::View *, const KTextEditor::Range &, InvocationType);
 	void executeCompletionItem (KTextEditor::Document *document, const KTextEditor::Range &word, int row) const;
 	QVariant data (const QModelIndex& index, int role=Qt::DisplayRole) const;
 
-	bool isEmpty () { return list.isEmpty (); };
+	bool isEmpty () const { return list.isEmpty (); };
 private:
-	QList<RObject*> list;
+	QVector<RObject*> list;
+	QVector<QString> list_names;
 	QString current_symbol;
+	RKCommandEditorWindow *command_editor;
 };
 
 class QTimer;
@@ -130,6 +135,7 @@
 	KUrl url ();
 
 	bool provideContext (unsigned int line_rev, QString *context, int *cursor_position);
+	QString currentCompletionWord () const;
 public slots:
 /** update Tab caption according to the current url. Display the filename-component of the URL, or - if not available - a more elaborate description of the url. Also appends a "[modified]" if appropriate */
 	void updateCaption (KTextEditor::Document* = 0);
@@ -155,6 +161,7 @@
 private:
 	KTextEditor::Document *m_doc;
 	KTextEditor::View *m_view;
+	KTextEditor::CodeCompletionInterface *cc_iface;
 	RKFunctionArgHinter *hinter;
 	RKCodeCompletionModel *completion_model;
 


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