[rkward-cvs] SF.net SVN: rkward:[3537] trunk/rkward/rkward/rbackend
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Sat May 7 12:01:40 UTC 2011
Revision: 3537
http://rkward.svn.sourceforge.net/rkward/?rev=3537&view=rev
Author: tfry
Date: 2011-05-07 12:01:39 +0000 (Sat, 07 May 2011)
Log Message:
-----------
Convert the remaining applicable substack requests to generic requests.
Modified Paths:
--------------
trunk/rkward/rkward/rbackend/rinterface.cpp
trunk/rkward/rkward/rbackend/rkrbackend.cpp
trunk/rkward/rkward/rbackend/rkrbackend.h
trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp 2011-05-07 10:35:43 UTC (rev 3536)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp 2011-05-07 12:01:39 UTC (rev 3537)
@@ -460,6 +460,82 @@
RKWardMainWindow::getMain ()->updateCWD ();
} else if (call == "highlightRCode") {
return (QStringList (RKCommandHighlighter::commandToHTML (calllist.value (1))));
+ } else if (call == "quit") {
+ RKWardMainWindow::getMain ()->close ();
+ // if we're still alive, quitting was cancelled
+ return (QStringList ("FALSE"));
+ } else if (call == "preLocaleChange") {
+ int res = KMessageBox::warningContinueCancel (0, i18n ("A command in the R backend is trying to change the character encoding. While RKWard offers support for this, and will try to adjust to the new locale, this operation may cause subtle bugs, if data windows are currently open. Also the feature is not well tested, yet, and it may be advisable to save your workspace before proceeding.\nIf you have any data editor opened, or in any doubt, it is recommended to close those first (this will probably be auto-detected in later versions of RKWard). In this case, please chose 'Cancel' now, then close the data windows, save, and retry."), i18n ("Locale change"));
+ if (res != KMessageBox::Continue) return (QStringList ("FALSE"));
+ } else if (call == "listPlugins") {
+ RK_ASSERT (calllist.count () == 1);
+ return RKComponentMap::getMap ()->allComponentIds ();
+ } else if (call == "showHTML") {
+ RK_ASSERT (calllist.count () == 2);
+ RKWorkplace::mainWorkplace ()->openHelpWindow (calllist.value (1));
+ } else if (call == "select.list") {
+ QString title = calllist.value (1);
+ bool multiple = (calllist.value (2) == "multi");
+ int num_preselects = calllist.value (3).toInt ();
+ QStringList preselects = calllist.mid (4, num_preselects);
+ QStringList choices = calllist.mid (4 + num_preselects);
+
+ QStringList results = RKSelectListDialog::doSelect (0, title, choices, preselects, multiple);
+ if (results.isEmpty ()) results.append (""); // R wants to have it that way
+ return (results);
+ } else if (call == "commandHistory") {
+ if (calllist.value (1) == "get") {
+ return (RKConsole::mainConsole ()->commandHistory ());
+ } else {
+ RKConsole::mainConsole ()->setCommandHistory (calllist.mid (2), calllist.value (1) == "append");
+ }
+ } else if (call == "getWorkspaceUrl") {
+ KUrl url = RObjectList::getObjectList ()->getWorkspaceURL ();
+ if (!url.isEmpty ()) return (QStringList (url.url ()));
+ } else if (call == "workplace.layout") {
+ if (calllist.value (1) == "set") {
+ if (calllist.value (2) == "close") RKWorkplace::mainWorkplace ()->closeAll ();
+ QStringList list = calllist.mid (3);
+ RKWorkplace::mainWorkplace ()->restoreWorkplace (list);
+ } else {
+ RK_ASSERT (calllist.value (1) == "get");
+ return (RKWorkplace::mainWorkplace ()->makeWorkplaceDescription ());
+ }
+ } else if (call == "getSessionInfo") {
+ // Non-translatable on purpose. This is meant for posting to the bug tracker, mostly.
+ QStringList lines;
+ lines.append ("RKWard version: " RKWARD_VERSION);
+ lines.append ("KDE version (runtime): " + QString (KDE::versionString ()));
+ lines.append ("KDE version (compile time): " KDE_VERSION_STRING);
+ lines.append (QString());
+ lines.append ("Debug message file(s) in use (these may contain relevant diagnostic output in case of trouble):");
+ lines.append (RKSettingsModuleDebug::debug_file->fileName ());
+ lines.append (calllist.value (1));
+ lines.append (QString ());
+ lines.append ("R version (compile time): " + calllist.value (2));
+ return (lines);
+ } else if (call == "recordCommands") {
+ RK_ASSERT (calllist.count () == 3);
+ QString filename = calllist.value (1);
+ bool with_sync = (calllist.value (2) == "include.sync");
+
+ if (filename.isEmpty ()) {
+ command_logfile_mode = NotRecordingCommands;
+ command_logfile.close ();
+ } else {
+ if (command_logfile_mode != NotRecordingCommands) {
+ return (QStringList ("Attempt to start recording, while already recording commands. Ignoring.)"));
+ } else {
+ command_logfile.setFileName (filename);
+ bool ok = command_logfile.open (QIODevice::WriteOnly | QIODevice::Truncate);
+ if (ok) {
+ command_logfile_mode = RecordingCommands;
+ if (with_sync) command_logfile_mode = RecordingCommandsWithSync;
+ } else {
+ return (QStringList ("Could not open file for writing. Not recording commands"));
+ }
+ }
+ }
} else {
return (QStringList ("Error: unrecognized request '" + call + "'."));
}
@@ -529,15 +605,6 @@
} else {
issueCommand (".rk.set.reply (\"Too few arguments in call to require.\")", RCommand::App | RCommand::Sync, QString::null, 0, 0, in_chain);
}
- } else if (call == "quit") {
- RKWardMainWindow::getMain ()->close ();
- // if we're still alive, quitting was cancelled
- issueCommand (".rk.set.reply (\"Quitting was cancelled\")", RCommand::App | RCommand::Sync, QString::null, 0, 0, in_chain);
- } else if (call == "preLocaleChange") {
- int res = KMessageBox::warningContinueCancel (0, i18n ("A command in the R backend is trying to change the character encoding. While RKWard offers support for this, and will try to adjust to the new locale, this operation may cause subtle bugs, if data windows are currently open. Also the feature is not well tested, yet, and it may be advisable to save your workspace before proceeding.\nIf you have any data editor opened, or in any doubt, it is recommended to close those first (this will probably be auto-detected in later versions of RKWard). In this case, please chose 'Cancel' now, then close the data windows, save, and retry."), i18n ("Locale change"));
- if (res != KMessageBox::Continue) {
- issueCommand (".rk.set.reply (FALSE)", RCommand::App | RCommand::Sync, QString::null, 0, 0, in_chain);
- }
} else if (call == "doPlugin") {
if (calllist.count () >= 3) {
QString message;
@@ -555,103 +622,6 @@
} else {
RK_ASSERT (false);
}
- } else if (call == "listPlugins") {
- if (calllist.count () == 1) {
- QStringList list = RKComponentMap::getMap ()->allComponentIds ();
- issueCommand (".rk.set.reply (c (\"" + list.join ("\", \"") + "\"))\n", RCommand::App | RCommand::Sync, QString::null, 0, 0, in_chain);
- } else {
- RK_ASSERT (false);
- }
- } else if (call == "showHTML") {
- if (calllist.count () == 2) {
- RKWorkplace::mainWorkplace ()->openHelpWindow (calllist[1]);
- } else {
- RK_ASSERT (false);
- }
- } else if (call == "select.list") {
- QString title = calllist[1];
- bool multiple = (calllist[2] == "multi");
- int num_preselects = calllist[3].toInt ();
- QStringList preselects = calllist.mid (4, num_preselects);
- QStringList choices = calllist.mid (4 + num_preselects);
-
- QStringList results = RKSelectListDialog::doSelect (0, title, choices, preselects, multiple);
- if (results.isEmpty ()) results.append (""); // R wants to have it that way
-
- QString command = ".rk.set.reply (c (";
- for (int i = 0; i < results.count (); ++i) {
- if (i > 0) command.append (", ");
- command.append (RObject::rQuote (results[i]));
- }
- command.append ("))");
-
- issueCommand (command, RCommand::App | RCommand::Sync, QString::null, 0, 0, in_chain);
- } else if (call == "commandHistory") {
- if (calllist[1] == "get") {
- QStringList hist = RKConsole::mainConsole ()->commandHistory ();
- QString command = (".rk.set.reply (c (");
- for (int i = 0; i < hist.size (); ++i) {
- command.append (RObject::rQuote (hist[i]));
- if (i < (hist.size () - 1)) command.append (",\n");
- }
- command.append ("))\n");
- issueCommand (command, RCommand::App | RCommand::Sync, QString::null, 0, 0, in_chain);
- } else {
- RKConsole::mainConsole ()->setCommandHistory (calllist.mid (2), calllist[1] == "append");
- }
- } else if (call == "recordCommands") {
- if (calllist.count () == 3) {
- QString filename = calllist[1];
- bool with_sync = (calllist[2] == "include.sync");
-
- if (filename.isEmpty ()) {
- command_logfile_mode = NotRecordingCommands;
- command_logfile.close ();
- } else {
- if (command_logfile_mode != NotRecordingCommands) {
- issueCommand (".rk.set.reply (\"Attempt to start recording, while already recording commands. Ignoring.\")", RCommand::App | RCommand::Sync, QString::null, 0, 0, in_chain);
- } else {
- command_logfile.setFileName (filename);
- bool ok = command_logfile.open (QIODevice::WriteOnly | QIODevice::Truncate);
- if (ok) {
- command_logfile_mode = RecordingCommands;
- if (with_sync) command_logfile_mode = RecordingCommandsWithSync;
- } else {
- issueCommand (".rk.set.reply (\"Could not open file for writing. Not recording commands.\")", RCommand::App | RCommand::Sync, QString::null, 0, 0, in_chain);
- }
- }
- }
- } else {
- RK_ASSERT (false);
- }
- } else if (call == "getWorkspaceUrl") {
- KUrl url = RObjectList::getObjectList ()->getWorkspaceURL ();
- if (!url.isEmpty ()) issueCommand (".rk.set.reply (" + RObject::rQuote (url.url ()) + ")", RCommand::App | RCommand::Sync, QString::null, 0, 0, in_chain);
- } else if (call == "workplace.layout") {
- if (calllist.value (1) == "set") {
- if (calllist.value (2) == "close") RKWorkplace::mainWorkplace ()->closeAll ();
- QStringList list = calllist.mid (3);
- RKWorkplace::mainWorkplace ()->restoreWorkplace (list);
- } else {
- RK_ASSERT (calllist.value (1) == "get");
- QStringList list = RKWorkplace::mainWorkplace ()->makeWorkplaceDescription ();
- for (int i = 0; i < list.size (); ++i) list[i] = RObject::rQuote (list[i]);
- issueCommand (".rk.set.reply (c (" + list.join (", ") + "))", RCommand::App | RCommand::Sync, QString::null, 0, 0, in_chain);
- }
- } else if (call == "getSessionInfo") {
- // Non-translatable on purpose. This is meant for posting to the bug tracker, mostly.
- QStringList lines;
- lines.append ("RKWard version: " RKWARD_VERSION);
- lines.append ("KDE version (runtime): " + QString (KDE::versionString ()));
- lines.append ("KDE version (compile time): " KDE_VERSION_STRING);
- lines.append (QString());
- lines.append ("Debug message file(s) in use (these may contain relevant diagnostic output in case of trouble):");
- lines.append (RKSettingsModuleDebug::debug_file->fileName ());
- lines.append (calllist.value (1));
- lines.append (QString ());
- lines.append ("R version (compile time): " + calllist.value (2));
- for (int i = 0; i < lines.size (); ++i) lines[i] = RObject::rQuote (lines[i]);
- issueCommand (".rk.set.reply (c (" + lines.join (",\n") + "))", RCommand::App | RCommand::Sync, QString::null, 0, 0, in_chain);
} else {
issueCommand ("stop (\"Unrecognized call '" + call + "'. Ignoring\")", RCommand::App | RCommand::Sync, QString::null, 0, 0, in_chain);
}
Modified: trunk/rkward/rkward/rbackend/rkrbackend.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkrbackend.cpp 2011-05-07 10:35:43 UTC (rev 3536)
+++ trunk/rkward/rkward/rbackend/rkrbackend.cpp 2011-05-07 12:01:39 UTC (rev 3537)
@@ -1298,14 +1298,7 @@
RK_TRACE (RBACKEND);
RBackendRequest request (true, RBackendRequest::HistoricalSubstackRequest);
- if (list.value (0) == "getSessionInfo") {
- QStringList dummy = list;
- dummy.append (RKRBackendProtocolBackend::backendDebugFile ());
- dummy.append (R_MAJOR "." R_MINOR " " R_STATUS " (" R_YEAR "-" R_MONTH "-" R_DAY " r" R_SVN_REVISION ")");
- request.params["call"] = dummy;
- } else {
- request.params["call"] = list;
- }
+ request.params["call"] = list;
handleRequest (&request);
}
@@ -1313,7 +1306,14 @@
RK_TRACE (RBACKEND);
RBackendRequest request (synchronous, RBackendRequest::PlainGenericRequest);
- request.params["call"] = parameters;
+ if (parameters.value (0) == "getSessionInfo") {
+ QStringList dummy = parameters;
+ dummy.append (RKRBackendProtocolBackend::backendDebugFile ());
+ dummy.append (R_MAJOR "." R_MINOR " " R_STATUS " (" R_YEAR "-" R_MONTH "-" R_DAY " r" R_SVN_REVISION ")");
+ request.params["call"] = dummy;
+ } else {
+ request.params["call"] = parameters;
+ }
handleRequest (&request);
return request.params.value ("return").toStringList ();
}
Modified: trunk/rkward/rkward/rbackend/rkrbackend.h
===================================================================
--- trunk/rkward/rkward/rbackend/rkrbackend.h 2011-05-07 10:35:43 UTC (rev 3536)
+++ trunk/rkward/rkward/rbackend/rkrbackend.h 2011-05-07 12:01:39 UTC (rev 3537)
@@ -109,7 +109,8 @@
static void processX11Events ();
void handleRequest (RBackendRequest *request) { handleRequest (request, true); };
-/** A relic of history. See also handleGenericRequest */
+/** A relic of history. In contrast to handlePlainGenericRequest(), these requests support running sub-commands. However, the remaining requests which are currently handled this way
+should probably be converted to dedicated RKRBackendRequest's in the future. See also handlePlainGenericRequest(). */
void handleHistoricalSubstackRequest (const QStringList &list);
/** Sends a request to the frontend and returns the result (an empty QStringList in case of asynchronous requests). Note that this function has considerable overlap with
handleHistoricalSubstackRequest(). Exactly which requests get handled by which function is somewhat arbitrary, ATM. However, request that do not need sub-commands to be run, should generally be converted to use handlePlainGenericRequest(). (And probably all historicalSubstackRequests should be replaced!) */
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R 2011-05-07 10:35:43 UTC (rev 3536)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R 2011-05-07 12:01:39 UTC (rev 3537)
@@ -136,7 +136,8 @@
# overriding q, to ask via GUI instead. Arguments are not interpreted.
"q" <- function (save = "default", status = 0, runLast = TRUE, ...) {
- .rk.do.call ("quit")
+ res <- .rk.do.plain.call ("quit")
+ if (length (res) && (res == "FALSE")) stop ("Quitting was cancelled")
}
"quit" <- function (save = "default", status = 0, runLast = TRUE, ...) {
@@ -299,10 +300,8 @@
"Sys.setlocale" <- function (category = "LC_ALL", locale = "", ...) {
if (category == "LC_ALL" || category == "LC_CTYPE" || category == "LANG") {
- allow <- .rk.do.call ("preLocaleChange", NULL);
- if (!is.null (allow)) {
- if (allow == FALSE) stop ("Changing the locale was cancelled by user");
- }
+ allow <- .rk.do.plain.call ("preLocaleChange", NULL)
+ if (length (allow) && (allow == "FALSE")) stop ("Changing the locale was cancelled by user")
ret <- base::Sys.setlocale (category, locale, ...)
@@ -342,9 +341,9 @@
"rk.record.commands" <- function (filename, include.sync.commands = FALSE) {
if (is.null (filename)) filename = ""
- res <- .rk.do.call ("recordCommands", c(as.character (filename), if (include.sync.commands) "include.sync" else "normal"))
+ res <- .rk.do.plain.call ("recordCommands", c(as.character (filename), if (include.sync.commands) "include.sync" else "normal"))
- if (is.null (res)) invisible (TRUE)
+ if (!length (res)) invisible (TRUE)
else {
warning (res)
invisible (FALSE)
@@ -425,18 +424,18 @@
## History manipulation function (overloads for functions by the same name in package utils)
rk.replace.function ("loadhistory", as.environment ("package:utils"),
function (file = ".Rhistory") {
- invisible (.rk.do.call ("commandHistory", c ("set", readLines (file))))
+ invisible (.rk.do.plain.call ("commandHistory", c ("set", readLines (file))))
}, copy.formals = FALSE)
rk.replace.function ("savehistory", as.environment ("package:utils"),
function (file = ".Rhistory") {
- invisible (writeLines (.rk.do.call ("commandHistory", "get"), file))
+ invisible (writeLines (.rk.do.plain.call ("commandHistory", "get"), file))
}, copy.formals = FALSE)
rk.replace.function ("timestamp", as.environment ("package:utils"),
function (stamp = date(), prefix = "##------ ", suffix = " ------##", quiet = FALSE) {
stamp <- paste(prefix, stamp, suffix, sep = "")
- .rk.do.call (.rk.do.call ("commandHistory", c ("append", stamp)))
+ .rk.do.plain.call ("commandHistory", c ("append", stamp))
if (!quiet) cat(stamp, sep = "\n")
invisible(stamp)
}, copy.formals = FALSE)
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R 2011-05-07 10:35:43 UTC (rev 3536)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R 2011-05-07 12:01:39 UTC (rev 3537)
@@ -118,7 +118,9 @@
}
"rk.get.workspace.url" <- function () {
- return (.rk.do.call ("getWorkspaceUrl"))
+ res <- .rk.do.plain.call ("getWorkspaceUrl")
+ if (length (res)) res
+ else NULL
}
"rk.get.output.html.file" <- function () {
@@ -137,7 +139,8 @@
}
# needs to come after initialization, so initialization alone does not trigger an update during startup
- .rk.do.plain.call ("set.output.file", x, synchronous=FALSE);
+ .rk.do.plain.call ("set.output.file", x, synchronous=FALSE)
+ invisible (NULL)
}
"rk.save.workplace" <- function (file=NULL, description=NULL) {
@@ -146,7 +149,7 @@
if (is.null (file)) file <- rk.get.tempfile.name (prefix="unsaved", extension=".RData")
file <- paste (file, "rkworkplace", sep=".")
}
- if (is.null (description)) lines <- .rk.do.call ("workplace.layout", "get")
+ if (is.null (description)) lines <- .rk.do.plain.call ("workplace.layout", "get")
else lines <- description
writeLines (lines, file)
}
@@ -168,7 +171,8 @@
close <- "close"
if (!isTRUE (close.windows)) close <- "noclose"
if (!exists ("lines", inherits=FALSE)) lines <- readLines (file)
- .rk.do.call ("workplace.layout", c ("set", close, lines))
+ .rk.do.plain.call ("workplace.layout", c ("set", close, lines))
+ invisible (NULL)
}
# renames a named object in a data.frame/list without changing it's position
@@ -383,7 +387,7 @@
}
"rk.show.html" <- function (url) {
- invisible (.rk.do.call ("showHTML", as.character (url)));
+ invisible (.rk.do.plain.call ("showHTML", as.character (url), synchronous=FALSE));
}
"rk.call.plugin" <- function (plugin, ..., submit.mode = c ("manual", "auto", "submit")) {
@@ -420,7 +424,7 @@
# list all available plugins in RKWard; this is a companion function for rk.call.plugin:
# the output provides possible strings for "plugin" argument in rk.call.plugin
rk.list.plugins <- function () {
- .rk.do.call ("listPlugins")
+ .rk.do.plain.call ("listPlugins")
}
# a wrapper around chooseCRANmirror() without changing options ("repos"), permanently
@@ -466,7 +470,7 @@
}
}
- .rk.do.call ("select.list", params)
+ .rk.do.plain.call ("select.list", params)
}
"rk.show.message" <- function (message, caption = "Information", wait=TRUE) {
@@ -483,7 +487,7 @@
}
"rk.sessionInfo" <- function () {
- cat (.rk.do.call ("getSessionInfo"), sep="\n")
+ cat (.rk.do.plain.call ("getSessionInfo"), sep="\n")
cat ("R runtime session info:\n")
print (sessionInfo())
}
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