[rkward-cvs] SF.net SVN: rkward: [890] trunk/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Thu Oct 19 22:59:32 UTC 2006
Revision: 890
http://svn.sourceforge.net/rkward/?rev=890&view=rev
Author: tfry
Date: 2006-10-19 15:59:24 -0700 (Thu, 19 Oct 2006)
Log Message:
-----------
code completion for the command editor
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/rkconsole.cpp
trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
trunk/rkward/rkward/windows/rkcommandeditorwindow.h
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2006-10-19 21:46:29 UTC (rev 889)
+++ trunk/rkward/ChangeLog 2006-10-19 22:59:24 UTC (rev 890)
@@ -1,3 +1,4 @@
+- as you type completion of R symbol names in the script editor
- function argument hinting in the console
- tab completion of R symbol names in the console
- added R function rk.edit (x) to open object x for editing in rkward
Modified: trunk/rkward/rkward/rkconsole.cpp
===================================================================
--- trunk/rkward/rkward/rkconsole.cpp 2006-10-19 21:46:29 UTC (rev 889)
+++ trunk/rkward/rkward/rkconsole.cpp 2006-10-19 22:59:24 UTC (rev 890)
@@ -354,15 +354,14 @@
RObject::RObjectMap map;
RObject::RObjectMap::const_iterator it;
RObjectList::getObjectList ()->findObjectsMatching (current_symbol, &map);
- QValueList<KTextEditor::CompletionEntry> list;
int count = map.count ();
if (count == 1) {
- int current_line = doc->numLines () - 1;
+ int current_line_num = 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 ());
+ doc->removeText (current_line_num, offset + word_start, current_line_num, offset + word_end);
+ doc->insertText (current_line_num, offset + word_start, it.key ());
} else if (count == 0) {
KApplication::kApplication ()->beep ();
} else if (tab_key_pressed_before) {
Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp 2006-10-19 21:46:29 UTC (rev 889)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp 2006-10-19 22:59:24 UTC (rev 890)
@@ -2,7 +2,7 @@
rkcommandeditorwindow - description
-------------------
begin : Mon Aug 30 2004
- copyright : (C) 2004 by Thomas Friedrichsmeier
+ copyright : (C) 2004, 2006 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -34,6 +34,7 @@
#include <qapplication.h>
#include <qtabwidget.h>
#include <qfile.h>
+#include <qtimer.h>
#include <klocale.h>
#include <kmenubar.h>
@@ -46,7 +47,7 @@
#include <kiconloader.h>
#include "../misc/rkcommonfunctions.h"
-#include "../core/robject.h"
+#include "../core/robjectlist.h"
#include "../rkglobals.h"
#include "../rkward.h"
#include "../khelpdlg.h"
@@ -81,6 +82,11 @@
connect (m_doc, SIGNAL (fileNameChanged ()), this, SLOT (updateCaption ()));
connect (m_doc, SIGNAL (modifiedChanged ()), this, SLOT (updateCaption ())); // of course most of the time this causes a redundant call to updateCaption. Not if a modification is undone, however.
+ connect (m_doc, SIGNAL (textChanged ()), this, SLOT (tryCompletionProxy ()));
+ connect (m_view, SIGNAL (filterInsertString (KTextEditor::CompletionEntry *, QString *)), this, SLOT (fixCompletion (KTextEditor::CompletionEntry *, QString *)));
+ completion_timer = new QTimer (this);
+ connect (completion_timer, SIGNAL (timeout ()), this, SLOT (tryCompletion()));
+
if (use_r_highlighting) setRHighlighting ();
updateCaption (); // initialize
@@ -164,7 +170,7 @@
bool RKCommandEditorWindow::isModified() {
RK_TRACE (COMMANDEDITOR);
- return m_doc->isModified();
+ return m_doc->isModified();
}
void RKCommandEditorWindow::insertText (const QString &text) {
@@ -198,4 +204,51 @@
RKGlobals::helpDialog ()->getContextHelp (line, p);
}
+void RKCommandEditorWindow::tryCompletionProxy () {
+ completion_timer->start (100, true);
+}
+
+void RKCommandEditorWindow::tryCompletion () {
+ // TODO: merge this with RKConsole::doTabCompletion () somehow
+ RK_TRACE (COMMANDEDITOR);
+
+ uint para=0; uint cursor_pos=0;
+ m_view->cursorPosition (¶, &cursor_pos);
+ QString current_line = getLine ();
+
+ QString current_symbol = RKCommonFunctions::getCurrentSymbol (current_line, cursor_pos, false);
+ if (current_symbol.length () >= 2) {
+ RObject::RObjectMap map;
+ RObject::RObjectMap::const_iterator it;
+ RObjectList::getObjectList ()->findObjectsMatching (current_symbol, &map);
+
+ if (!map.isEmpty ()) {
+ QValueList<KTextEditor::CompletionEntry> list;
+
+ for (it = map.constBegin (); it != map.constEnd (); ++it) {
+ KTextEditor::CompletionEntry entry;
+ entry.text = it.key ();
+ list.append (entry);
+ }
+
+ m_view->showCompletionBox (list);
+ }
+ }
+}
+
+void RKCommandEditorWindow::fixCompletion (KTextEditor::CompletionEntry *, QString *) {
+ RK_TRACE (COMMANDEDITOR);
+
+ uint current_line_num=0; uint cursor_pos=0;
+ m_view->cursorPosition (¤t_line_num, &cursor_pos);
+ QString current_line = getLine ();
+
+ int word_start;
+ int word_end;
+ RKCommonFunctions::getCurrentSymbolOffset (current_line, cursor_pos, false, &word_start, &word_end);
+
+ // remove the start of the word, as the whole string will be inserted by katepart
+ m_doc->removeText (current_line_num, word_start, current_line_num, word_end);
+}
+
#include "rkcommandeditorwindow.moc"
Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.h 2006-10-19 21:46:29 UTC (rev 889)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.h 2006-10-19 22:59:24 UTC (rev 890)
@@ -2,7 +2,7 @@
rkcommandeditorwindow - description
-------------------
begin : Mon Aug 30 2004
- copyright : (C) 2004 by Thomas Friedrichsmeier
+ copyright : (C) 2004, 2006 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -26,6 +26,8 @@
#include "../windows/rkmdiwindow.h"
+class QTimer;
+
/**
\brief Provides an editor window for R-commands, as well as a text-editor window in general.
@@ -68,6 +70,9 @@
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 approriate */
void updateCaption ();
+ void tryCompletionProxy ();
+ void tryCompletion ();
+ void fixCompletion (KTextEditor::CompletionEntry *, QString *);
protected:
/** reimplemented from KMdiChildView: give the editor window a chance to object to being closed (if unsaved) */
void closeEvent (QCloseEvent *e);
@@ -75,6 +80,7 @@
Kate::Document *m_doc;
Kate::View *m_view;
+ QTimer *completion_timer;
/** set syntax highlighting-mode to R syntax */
void setRHighlighting ();
};
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