[rkward-cvs] SF.net SVN: rkward: [888] trunk/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Thu Oct 19 19:51:24 UTC 2006
Revision: 888
http://svn.sourceforge.net/rkward/?rev=888&view=rev
Author: tfry
Date: 2006-10-19 12:51:18 -0700 (Thu, 19 Oct 2006)
Log Message:
-----------
Function argument hinting in the console. Not pretty, but working
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/rkconsole.cpp
trunk/rkward/rkward/rkconsole.h
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2006-10-19 18:37:53 UTC (rev 887)
+++ trunk/rkward/ChangeLog 2006-10-19 19:51:18 UTC (rev 888)
@@ -1,3 +1,5 @@
+- 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
- fixed: an empty table created before the object list was updated (esp. at startup) would be thought to have been removed in the workspace
- object data changed in the console (or by other means) is updated to the editor automatically, if the object is opened for editing
Modified: trunk/rkward/rkward/rkconsole.cpp
===================================================================
--- trunk/rkward/rkward/rkconsole.cpp 2006-10-19 18:37:53 UTC (rev 887)
+++ trunk/rkward/rkward/rkconsole.cpp 2006-10-19 19:51:18 UTC (rev 888)
@@ -22,6 +22,10 @@
#include <qapplication.h>
#include <qobjectlist.h>
#include <qevent.h>
+#include <qregexp.h>
+#include <qvbox.h>
+#include <qlabel.h>
+#include <qtimer.h>
#include <klocale.h>
#include <kaction.h>
@@ -38,6 +42,7 @@
#include "settings/rksettingsmoduleconsole.h"
#include "misc/rkcommonfunctions.h"
#include "core/robjectlist.h"
+#include "core/rfunctionobject.h"
RKConsole::RKConsole () : QWidget (0) {
RK_TRACE (APP);
@@ -132,12 +137,19 @@
current_command = 0;
tab_key_pressed_before = false;
+
+ arghints_popup = new QVBox (0, 0, WType_Popup);
+ arghints_popup->setFrameStyle (QFrame::Box | QFrame::Plain);
+ arghints_popup->setLineWidth (1);
+ arghints_popup_text = new QLabel (arghints_popup);
+ arghints_popup->hide ();
+ arghints_popup->setFocusProxy (this);
}
-
RKConsole::~RKConsole () {
RK_TRACE (APP);
+ delete arghints_popup;
RKSettingsModuleConsole::saveCommandHistory (commands_history);
}
@@ -191,10 +203,12 @@
}
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
+ arghints_popup->hide ();
submitCommand ();
return true;
}
else if (e->state () == Qt::ShiftButton && e->key () == Qt::Key_Home){
+ arghints_popup->hide ();
if(hasSelectedText())
pos=selectionInterfaceExt(doc)->selEndCol (); //There is already a selection, we take it into account.
selectionInterface(doc)->setSelection(doc->numLines()-1,prefix.length (),doc->numLines()-1, pos);
@@ -202,6 +216,7 @@
return TRUE;
}
else if (e->state () == Qt::ShiftButton && e->key () == Qt::Key_Left){
+ arghints_popup->hide ();
if(pos<=prefix.length ()){
return TRUE;
} else {
@@ -210,14 +225,17 @@
}
}
else if (e->key () == Qt::Key_Up) {
+ arghints_popup->hide ();
commandsListUp ();
return true;
}
else if (e->key () == Qt::Key_Down) {
+ arghints_popup->hide ();
commandsListDown ();
return true;
}
else if (e->key () == Qt::Key_Left){
+ arghints_popup->hide ();
if(pos<=prefix.length ()){
return TRUE;
} else {
@@ -226,6 +244,7 @@
}
}
else if (e->key () == Qt::Key_Backspace){
+ tryShowFunctionArgHints ();
if(pos<=prefix.length ()){
return TRUE;
} else {
@@ -238,17 +257,86 @@
return TRUE;
}
else if (e->key () == Qt::Key_Home){
+ arghints_popup->hide ();
cursorAtTheBeginning ();
return TRUE;
}
else if (e->key() == Qt::Key_Delete) {
+ tryShowFunctionArgHints ();
view->keyDelete();
return TRUE;
+ } else {
+ QString text = e->text ();
+ if (text == "(") {
+ tryShowFunctionArgHints ();
+ } else if (text == ",") {
+ tryShowFunctionArgHints ();
+ } else if (text == ")") {
+ tryShowFunctionArgHints ();
+ }
}
return FALSE;
}
+void RKConsole::tryShowFunctionArgHints () {
+ // wait for the keypress to become effective first
+ QTimer::singleShot (0, this, SLOT (realTryShowFunctionArgHints ()));
+}
+
+void RKConsole::realTryShowFunctionArgHints () {
+ RK_TRACE (APP);
+
+ QString current_line = currentCommand ();
+ int cursor_pos = currentCursorPositionInCommand ();
+ int matching_left_brace_pos;
+
+ // find the corrresponding opening brace
+ int brace_level = 1;
+ int i;
+ for (i = cursor_pos; i >= 0; --i) {
+ if (current_line.at (i) == QChar (')')) {
+ brace_level++;
+ } else if (current_line.at (i) == QChar ('(')) {
+ brace_level--;
+ if (!brace_level) break;
+ }
+ }
+ if (!brace_level) matching_left_brace_pos = i;
+ else {
+ arghints_popup->hide ();
+ return;
+ }
+
+ // now find where the symbol to the left ends
+ int potential_symbol_end = matching_left_brace_pos - 1;
+ while ((potential_symbol_end >= 0) && current_line.at (potential_symbol_end).isSpace ()) {
+ --potential_symbol_end;
+ }
+ if (current_line.at (potential_symbol_end).isSpace ()) {
+ arghints_popup->hide ();
+ return;
+ }
+
+ // now identify the symbol (if any)
+ QString effective_symbol = RKCommonFunctions::getCurrentSymbol (current_line, potential_symbol_end);
+ if (effective_symbol.isEmpty ()) {
+ arghints_popup->hide ();
+ return;
+ }
+
+ RObject *object = RObjectList::getObjectList ()->findObject (effective_symbol);
+ if ((!object) || (!object->isType (RObject::Function))) {
+ arghints_popup->hide ();
+ return;
+ }
+
+ arghints_popup_text->setText (effective_symbol + " (" + static_cast<RFunctionObject*> (object)->printArgs () + ")");
+ arghints_popup->resize (arghints_popup_text->sizeHint () + QSize (2, 2));
+ arghints_popup->move (mapToGlobal (view->cursorCoordinates () + QPoint (0, arghints_popup->height ())));
+ arghints_popup->show ();
+}
+
void RKConsole::doTabCompletion () {
RK_TRACE (APP);
Modified: trunk/rkward/rkward/rkconsole.h
===================================================================
--- trunk/rkward/rkward/rkconsole.h 2006-10-19 18:37:53 UTC (rev 887)
+++ trunk/rkward/rkward/rkconsole.h 2006-10-19 19:51:18 UTC (rev 888)
@@ -28,6 +28,8 @@
#include "rbackend/rcommandreceiver.h"
class QStringList;
+class QVBox;
+class QLabel;
class KAction;
class RCommand;
class KateCodeCompletion;
@@ -125,6 +127,8 @@
\param ac the action collection from which to retrieve the KAction*/
void unplugAction (QString action, KActionCollection* ac);
+ void tryShowFunctionArgHints ();
+
bool output_continuation;
RCommand *current_command;
@@ -132,11 +136,14 @@
Kate::View *view;
bool tab_key_pressed_before;
+ QVBox *arghints_popup;
+ QLabel *arghints_popup_text;
public slots:
/** We intercept paste commands and get them executed through submitBatch.
@sa submitBatch */
void paste ();
void copy ();
+ void realTryShowFunctionArgHints ();
};
/** A part interface to RKConsole. Provides the context-help functionality
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