[rkward-cvs] SF.net SVN: rkward: [810] trunk/rkward/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Thu Oct 5 12:48:54 UTC 2006
Revision: 810
http://svn.sourceforge.net/rkward/?rev=810&view=rev
Author: tfry
Date: 2006-10-05 05:48:45 -0700 (Thu, 05 Oct 2006)
Log Message:
-----------
Automatic object list update part 1: After a user command, check search path, and list of toplevel symbols in globalent. Update if needed
Modified Paths:
--------------
trunk/rkward/rkward/rbackend/rinterface.cpp
trunk/rkward/rkward/rbackend/rthread.cpp
trunk/rkward/rkward/rbackend/rthread.h
trunk/rkward/rkward/rkward.cpp
Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp 2006-10-05 12:10:27 UTC (rev 809)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp 2006-10-05 12:48:45 UTC (rev 810)
@@ -24,6 +24,7 @@
#include "../settings/rksettingsmoduler.h"
#include "../settings/rksettingsmodulegeneral.h"
#include "../core/robjectlist.h"
+#include "../core/renvironmentobject.h"
#include "../core/rkmodificationtracker.h"
#include "../dialogs/rkloadlibsdialog.h"
#include "../dialogs/rkreadlinedialog.h"
@@ -161,6 +162,13 @@
RKwardApp::getApp ()->setRStatus (false);
} else if ((e->type () == RBUSY_EVENT)) {
RKwardApp::getApp ()->setRStatus (true);
+ } else if ((e->type () == RSEARCHLIST_CHANGED_EVENT)) {
+ RK_DO (qDebug ("triggering update of object list"), RBACKEND, DL_DEBUG);
+ RObjectList::getObjectList ()->updateFromR ();
+ } else if ((e->type () == RGLOBALENV_SYMBOLS_CHANGED_EVENT)) {
+ RK_DO (qDebug ("triggering update of globalenv"), RBACKEND, DL_DEBUG);
+ // TODO: maybe this should be put inside a chain
+ RObjectList::getGlobalEnv ()->updateFromR ();
} else if ((e->type () == R_EVAL_REQUEST_EVENT)) {
r_thread->pauseOutput (false); // we may be recursing downwards into event loops here. Hence we need to make sure, we don't create a deadlock
processREvalRequest (static_cast<REvalRequest *> (e->data ()));
Modified: trunk/rkward/rkward/rbackend/rthread.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rthread.cpp 2006-10-05 12:10:27 UTC (rev 809)
+++ trunk/rkward/rkward/rbackend/rthread.cpp 2006-10-05 12:48:45 UTC (rev 810)
@@ -45,6 +45,11 @@
current_output = 0;
out_buf_len = 0;
output_paused = false;
+
+ toplevel_env_names = 0;
+ toplevel_env_count = 0;
+ global_env_toplevel_names = 0;
+ global_env_toplevel_count = 0;
}
RThread::~RThread() {
@@ -208,6 +213,10 @@
}
// step 3: cleanup
+ if (command->type () & RCommand::User) {
+ checkObjectUpdatesNeeded ();
+ }
+
// notify GUI-thread that command was finished
event = new QCustomEvent (RCOMMAND_OUT_EVENT);
event->setData (command);
@@ -428,6 +437,8 @@
if (error) status |= OtherFail;
// TODO: error-handling?
+ checkObjectUpdatesNeeded ();
+
MUTEX_LOCK;
flushOutput ();
MUTEX_UNLOCK;
@@ -438,6 +449,64 @@
return status;
}
+void RThread::checkObjectUpdatesNeeded () {
+ RK_TRACE (RBACKEND);
+
+ RKWardRError error;
+ unsigned int count;
+ QString *strings;
+
+ bool search_update_needed = false;
+ bool globalenv_update_needed = false;
+
+// TODO: avoid parsing this over and over again
+ strings = getCommandAsStringVector ("search ()\n", &count, &error);
+ if (count != toplevel_env_count) {
+ search_update_needed = true;
+ } else {
+ for (unsigned int i = 0; i < toplevel_env_count; ++i) {
+ if (toplevel_env_names[i] != strings[i]) {
+ search_update_needed = true;
+ break;
+ }
+ }
+ }
+ delete [] toplevel_env_names;
+ toplevel_env_names = strings;
+ toplevel_env_count = count;
+
+// TODO: avoid parsing this over and over again
+ strings = getCommandAsStringVector ("ls (globalenv (), all.names=TRUE)\n", &count, &error);
+ if (count != global_env_toplevel_count) {
+ globalenv_update_needed = true;
+ } else {
+ for (unsigned int i = 0; i < global_env_toplevel_count; ++i) {
+ bool found = false;
+ for (unsigned int j = 0; j < global_env_toplevel_count; ++j) {
+ if (global_env_toplevel_names[j] == strings[i]) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ globalenv_update_needed = true;
+ break;
+ }
+ }
+ }
+ delete [] global_env_toplevel_names;
+ global_env_toplevel_names = strings;
+ global_env_toplevel_count = count;
+
+ if (search_update_needed) { // this includes an update of the globalenv, even if not needed
+ QCustomEvent *event = new QCustomEvent (RSEARCHLIST_CHANGED_EVENT);
+ qApp->postEvent (RKGlobals::rInterface (), event);
+ } else if (globalenv_update_needed) {
+ QCustomEvent *event = new QCustomEvent (RGLOBALENV_SYMBOLS_CHANGED_EVENT);
+ qApp->postEvent (RKGlobals::rInterface (), event);
+ }
+}
+
QString *stringsToStringList (char **strings, int count) {
QString *list = new QString[count];
for (int i=0; i < count; ++i) {
Modified: trunk/rkward/rkward/rbackend/rthread.h
===================================================================
--- trunk/rkward/rkward/rbackend/rthread.h 2006-10-05 12:10:27 UTC (rev 809)
+++ trunk/rkward/rkward/rbackend/rthread.h 2006-10-05 12:48:45 UTC (rev 810)
@@ -37,6 +37,8 @@
#define R_CALLBACK_REQUEST_EVENT 12002
// don't use the numbers following RSTARTUP_ERROR_EVENT, because an error code will be added!
#define RSTARTUP_ERROR_EVENT 13000
+#define RSEARCHLIST_CHANGED_EVENT 14000
+#define RGLOBALENV_SYMBOLS_CHANGED_EVENT 14001
/** This class represents the thread the R backend is running in. So to speak, this is where the "eventloop" of R is running. The main thing happening
in this class, is that an infinite loop is running. Whenever there are commands to be executed, those get evaluated. Also, at regular intervals,
@@ -169,6 +171,12 @@
/** thread is killed. Should exit as soon as possible. @see kill */
bool killed;
bool output_paused;
+
+ QString *toplevel_env_names;
+ unsigned int toplevel_env_count;
+ QString *global_env_toplevel_names;
+ unsigned int global_env_toplevel_count;
+ void checkObjectUpdatesNeeded ();
};
#endif
Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp 2006-10-05 12:10:27 UTC (rev 809)
+++ trunk/rkward/rkward/rkward.cpp 2006-10-05 12:48:45 UTC (rev 810)
@@ -264,7 +264,6 @@
RKGlobals::rInterface ()->startThread ();
object_browser->initialize ();
- RObjectList::getObjectList ()->updateFromR ();
}
void RKwardApp::slotConfigure () {
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