[Sciviews-commits] r321 - in komodo/SciViews-K: . components content content/js content/js/tools defaults skin skin/icons/misc udl
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Sep 29 09:54:42 CEST 2010
Author: phgrosjean
Date: 2010-09-29 09:54:41 +0200 (Wed, 29 Sep 2010)
New Revision: 321
Added:
komodo/SciViews-K/content/js/rjson.js
komodo/SciViews-K/defaults/R reference (0.9.18).kpz
komodo/SciViews-K/defaults/SciViews-K (0.9.18).kpz
komodo/SciViews-K/defaults/SciViews_0.9-2.tar.gz
komodo/SciViews-K/defaults/SciViews_0.9-2.zip
komodo/SciViews-K/defaults/svGUI_0.9-49.tar.gz
komodo/SciViews-K/defaults/svGUI_0.9-49.zip
komodo/SciViews-K/defaults/svMisc_0.9-60.tar.gz
komodo/SciViews-K/defaults/svMisc_0.9-60.zip
komodo/SciViews-K/defaults/svSocket_0.9-50.tar.gz
komodo/SciViews-K/defaults/svSocket_0.9-50.zip
Removed:
komodo/SciViews-K/defaults/R reference (0.9.15).kpz
komodo/SciViews-K/defaults/SciViews-K (0.9.15).kpz
komodo/SciViews-K/defaults/SciViews_0.9-1.tar.gz
komodo/SciViews-K/defaults/SciViews_0.9-1.zip
komodo/SciViews-K/defaults/svGUI_0.9-47.tar.gz
komodo/SciViews-K/defaults/svGUI_0.9-47.zip
komodo/SciViews-K/defaults/svMisc_0.9-57.tar.gz
komodo/SciViews-K/defaults/svMisc_0.9-57.zip
komodo/SciViews-K/defaults/svSocket_0.9-48.tar.gz
komodo/SciViews-K/defaults/svSocket_0.9-48.zip
Modified:
komodo/SciViews-K/.DS_Store
komodo/SciViews-K/components/svIRinterpreter.idl
komodo/SciViews-K/components/svRinterpreter.js
komodo/SciViews-K/content/RHelpWindow.xul
komodo/SciViews-K/content/js/ask.js
komodo/SciViews-K/content/js/commands.js
komodo/SciViews-K/content/js/interpolate.js
komodo/SciViews-K/content/js/misc.js
komodo/SciViews-K/content/js/pref-R.js
komodo/SciViews-K/content/js/prefs.js
komodo/SciViews-K/content/js/r.js
komodo/SciViews-K/content/js/rconsole.js
komodo/SciViews-K/content/js/rinterpolationquery.js
komodo/SciViews-K/content/js/robjects.js
komodo/SciViews-K/content/js/sciviews.js
komodo/SciViews-K/content/js/socket.js
komodo/SciViews-K/content/js/tools/array.js
komodo/SciViews-K/content/js/tools/e4x2dom.js
komodo/SciViews-K/content/js/tools/file.js
komodo/SciViews-K/content/js/tools/strings.js
komodo/SciViews-K/content/overlayMain.xul
komodo/SciViews-K/content/rsearch.html
komodo/SciViews-K/content/sessions.xul
komodo/SciViews-K/defaults/.DS_Store
komodo/SciViews-K/defaults/svStart.R
komodo/SciViews-K/install.rdf
komodo/SciViews-K/skin/.DS_Store
komodo/SciViews-K/skin/icons/misc/.DS_Store
komodo/SciViews-K/udl/Rlex.udl
Log:
Version 0.9.18. Adding rjson and http server. Slight reworking of most JS code. Upgrade to latest svXXX R packages.
Modified: komodo/SciViews-K/.DS_Store
===================================================================
(Binary files differ)
Modified: komodo/SciViews-K/components/svIRinterpreter.idl
===================================================================
--- komodo/SciViews-K/components/svIRinterpreter.idl 2010-09-26 21:17:37 UTC (rev 320)
+++ komodo/SciViews-K/components/svIRinterpreter.idl 2010-09-29 07:54:41 UTC (rev 321)
@@ -36,18 +36,6 @@
[scriptable, uuid(5e04a8de-ac01-4df1-af7a-184130e645b8)]
interface svIRinterpreter : nsISupports {
/**
- * Execute code in the R interpreter and return result.
- * @param cmd - The command to evaluate in R.
- */
- /*string eval(in string cmd);*/
-
- /**
- * Execute code in the R interpreter in hidden way and return result.
- * @param cmd - The command to evaluate in R.
- */
- /*string evalHidden(in string cmd, in boolean earlyExit);*/
-
- /**
* Escape from multiline mode in the R interpreter.
*/
string escape();
Modified: komodo/SciViews-K/components/svRinterpreter.js
===================================================================
--- komodo/SciViews-K/components/svRinterpreter.js 2010-09-26 21:17:37 UTC (rev 320)
+++ komodo/SciViews-K/components/svRinterpreter.js 2010-09-29 07:54:41 UTC (rev 321)
@@ -1,6 +1,6 @@
// SciViews-K R interpreter XPCOM
// Define functions to pilot R from Komodo Edit
-// Copyright (c) 2008-2009, Ph. Grosjean (phgrosjean at sciviews.org) et al.
+// Copyright (c) 2008-2010, Ph. Grosjean (phgrosjean at sciviews.org) et al.
// License: MPL 1.1/GPL 2.0/LGPL 2.1
////////////////////////////////////////////////////////////////////////////////
// In Javascript:
@@ -11,14 +11,11 @@
// R = components.classes["@sciviews.org/svRinterpreter;1"].\
// getService(components.interfaces.svIRinterpreter)
////////////////////////////////////////////////////////////////////////////////
-// Not yet! R.eval(cmd); // Evaluate a command in the R interpreter
-// Not yet! R.evalHidden(cmd); // Evaluate a command in hidden mode in R
-// R.escape(); // Escape from multiline mode in R
-// R.calltip(code); // Get a calltip for this code
-// R.complete(code); // Get completion list for this code
+// R.escape(); // Escape R code
+// R.calltip(code); // Get a calltip for this code
+// R.complete(code); // Get completion list for this code
////////////////////////////////////////////////////////////////////////////////
-// TODO: implement rCharset(), rClient() and rCommand() here only. Rework the
-// version in sv.socket to use this one.
+// TODO: add HTTP version + rework to avoid duplication with sv.socket/sv.http!
// TODO: rework calltip() and complete() in sv.r to use this one.
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
@@ -59,55 +56,32 @@
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.svIRinterpreter]),
//chromeURL: "chrome://komodo/content/colorpicker/colorpicker.html",
-
+
/**
- * Execute code in the R interpreter and return result.
- * @param code - The code to evaluate in R.
- */
- //eval: function(cmd) {
- // // Does not work yet (return NULL)
- // return sv.r.eval(cmd);
- //},
-
- /**
- * Execute code in the R interpreter in hidden way and return result.
- * @param cmd - The command to evaluate in R.
- */
- //evalHidden: function(cmd, earlyExit) {
- // // Does not work yet (return NULL)
- // return sv.r.evalHidden(cmd, earlyExit);
- //},
-
- /**
* Escape from multiline mode in the R interpreter.
*/
- escape: function() {
- // Send an <<<esc>>> sequence that breaks multiline mode
- cmd = "";
- prompt == ":> ";
- // TODO: put this only in sv.r.escape()! if (cmdout) { sv.cmdout.clear(); }
- var listener = { finished: function(data) {} }
- var res = rCommand('<<<esc>>>', false);
- return(res);
- },
+ escape: function () {
+ // Currently do noting
+ return null;
+ },
/**
* Query the R interpreter to get a calltip.
* @param code - The piece of code currently edited requiring calltip.
*/
- calltip: function(code) {
+ calltip: function (code) {
if (typeof(code) == "undefined" | code == "") {
return "";
}
- var cmd = 'cat(CallTip("' + code.replace(/(")/g, "\\$1") +
- '", location = TRUE))';
- var res = rCommand("<<<h>>>" + cmd, false, null,
+ var cmd = 'cat(callTip("' + code.replace(/(")/g, "\\$1") +
+ '", location = TRUE, description = TRUE, methods = FALSE, width = 80))';
+ var res = rCommand("<<<h>>>" + cmd,
function (tip) {
if (tip != "") {
koLogger.debug(tip);
- var kvSvc = Components.
- classes["@activestate.com/koViewService;1"].
- getService(Components.interfaces.koIViewService);
+ var kvSvc = Components
+ .classes["@activestate.com/koViewService;1"]
+ .getService(Components.interfaces.koIViewService);
var ke = kvSvc.currentView.document.getView().scimoz;
ke.callTipCancel();
ke.callTipShow(ke.anchor, tip.replace(/[\r\n]+/g, "\n"));
@@ -121,22 +95,22 @@
* Query the R interpreter to get a completion list.
* @param code - The piece of code currently edited requiring completion.
*/
- complete: function(code) {
+ complete: function (code) {
if (typeof(code) == "undefined" | code == "") {
return "";
}
code = code.replace(/(")/g, "\\$1");
- var kvSvc = Components.
- classes["@activestate.com/koViewService;1"].
- getService(Components.interfaces.koIViewService);
+ var kvSvc = Components
+ .classes["@activestate.com/koViewService;1"]
+ .getService(Components.interfaces.koIViewService);
var ke = kvSvc.currentView.document.getView().scimoz;
// Record current position (could change, because asynch trigger of autoC)
var lastPos = ke.anchor;
- var cmd = 'Complete("' + code + '", print = TRUE, types = "scintilla")';
- koLogger.debug("Complete: ..." + code.substring(code.length - 20));
- var res = rCommand("<<<h>>>" + cmd, false, null,
+ var cmd = 'completion("' + code + '", print = TRUE, types = "scintilla", field.sep = "?")';
+ koLogger.debug("completion: ..." + code.substring(code.length - 20));
+ var res = rCommand("<<<h>>>" + cmd,
function (autoCstring) {
- // these should be set only once?:
+ // These should be set only once?:
ke.autoCSeparator = 9;
//ke.autoCSetFillUps(" []{}<>/():;%+-*@!\t\n\r=$`");
var autoCSeparatorChar = String.fromCharCode(ke.autoCSeparator);
@@ -144,9 +118,9 @@
// Get length of the triggering text
var trigLen = parseInt(RegExp.$1);
koLogger.debug("trigLen: " + trigLen);
- // Is something returned by Complete()?
+ // Is something returned by completion()?
if (isNaN(trigLen)) { return; }
- // There is a bug (or feature?) in Complete(): if it returns all the code, better set trigLen to 0!
+ // There is a bug (or feature?) in completion(): if it returns all the code, better set trigLen to 0!
if (trigLen == code.length) { trigLen = 0; }
// TODO: we need to sort AutoCString with uppercase first
// otherwise, the algorithm does not find them (try: typing T, then ctrl+J, then R)
@@ -167,7 +141,7 @@
// getPixmap("chrome://komodo/skin/images/ac_interface.xpm"));
ke.autoCChooseSingle = false;
// Take into account if we entered more characters
- Delta = ke.anchor - lastPos;
+ Delta = ke.anchor - lastPos;
koLogger.debug("Delta: " + Delta);
// Only display completion list if 0 <= Delta < 5
// Otherwise, it means we moved away for the triggering area
@@ -184,7 +158,7 @@
//// XPCOM registration of the class ///////////////////////////////////////////
var components = [svRinterpreter];
-function NSGetModule(compMgr, fileSpec) {
+function NSGetModule (compMgr, fileSpec) {
return XPCOMUtils.generateModule(components);
}
@@ -195,81 +169,90 @@
.getService(Components.interfaces.koILoggingService);
var koLogger = koLogging.getLogger("svRinterpreter");
+function koLoggerException(e, msg, showMsg) {
+ if (typeof(showMsg) != 'undefined' && showMsg == true)
+ alert("Error", msg);
+ koLogger.exception(e, msg);
+}
+
//koLogger.setLevel(koLogging.DEBUG);
//// Komodo preferences access /////////////////////////////////////////////////
-var prefsSvc = Components.classes["@activestate.com/koPrefService;1"].
- getService(Components.interfaces.koIPrefService);
+var prefsSvc = Components.classes["@activestate.com/koPrefService;1"]
+ .getService(Components.interfaces.koIPrefService);
var prefs = prefsSvc.prefs;
// Get a string preference, or default value
-function getPrefString(pref, def) {
+function getPrefString (pref, def) {
if (prefs.hasStringPref(pref)) {
return(prefs.getStringPref(pref));
} else return(def);
}
// Set a string preference
-function setPrefString(pref, value, overwrite) {
+function setPrefString (pref, value, overwrite) {
if (overwrite == false & prefs.hasStringPref(pref)) return;
prefs.setStringPref(pref, value);
}
//// R socket server configuration /////////////////////////////////////////////
-var svSocketMinVersion = "0.9-44"; // Will be used later for compatibility
- // checking between R and Komodo tools
-var host = "127.0.0.1"; // Host to connect to (local host only, currently)
-var cmdout = false; // Do we write to 'Command Output'?
-var prompt = ":> "; // The prompt, could be changed to continue prompt
-var cmd = ""; // The command to send to R
-
-var millis = 500; // ms to wait for input, with synchroneous com only
-var charsetUpdated = false; // Character set used by R is updated?
+// String converter used between Komodo and R (localeToCharset()[1] in R)
var converter = Components
.classes["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
+// Use UTF-8 encoding by default
+try { converter.charset = "UTF-8"; } catch (e) { }
-// Function to set up the charset used by R
-// TODO: should we have to reset this, i.e., can R change this during a session?
-function rCharset(force) {
- if (!force && charsetUpdated) return;
- koLogger.debug("charsetUpdate");
- charsetUpdated = true;
-
- this.rCommand("<<<h>>>cat(localeToCharset()[1])", false, null,
- function (s) {
- // TODO: check s first, otherwise, we got an exception in next
- // command if R is not running
- this.converter.charset = s;
- koLogger.debug("R character set is " + s);
- }
- );
+// The conversion functions
+function _fromUnicode (str, charset) {
+ if (charset !== undefined && converter.charset != charset) {
+ converter.charset = charset;
+ }
+ try {
+ str = converter.ConvertFromUnicode(str);
+ } catch(e) {
+ koLoggerException(e, "Unable to convert from Unicode");
+ }
+ return(str);
}
+
+function _toUnicode (str, charset) {
+ if (charset !== undefined && converter.charset != charset) {
+ converter.charset = charset;
+ }
+ try {
+ str = converter.ConvertToUnicode(str);
+ } catch(e) {
+ koLoggerException(e, "Unable to convert from Unicode");
+ }
+ return(str);
+}
// The main socket client function to connect to R socket server
-function rClient(host, port, outputData, listener, echo, echofun) {
+function rClient(host, port, cmd, listener) {
+ // Workaround for NS_ERROR_OFFLINE returned by 'createTransport' when
+ // there is no network connection (when network goes down). Based on
+ // toggleOfflineStatus() in chrome://browser/content/browser.js.
+// TODO: navigator unknown at this stage...
+// if (!navigator.onLine) Components
+// .classes["@mozilla.org/network/io-service;1"]
+// .getService(Components.interfaces.nsIIOService2).offline = false;
+
try {
- var transportService = Components.
- classes["@mozilla.org/network/socket-transport-service;1"]
- .getService(Components.interfaces.nsISocketTransportService);
- var transport = transportService.createTransport(null, 0,
- host, port, null);
+ var transport = Components
+ .classes["@mozilla.org/network/socket-transport-service;1"]
+ .getService(Components.interfaces.nsISocketTransportService)
+ .createTransport(null, 0, host, port, null);
- if (converter.charset) try {
- // Convert output string from unicode to R's charset (Bug #240)
- outputData = converter.ConvertFromUnicode(outputData);
- } catch(e) {
- koLogger.error("rClient() is unable to convert from Unicode: " + e);
- }
-
var outstream = transport.openOutputStream(0, 0, 0);
- outstream.write(outputData, outputData.length);
+ cmd = _fromUnicode(cmd);
+ outstream.write(cmd, cmd.length);
var stream = transport.openInputStream(0, 0, 0);
- var instream = Components.
- classes["@mozilla.org/scriptableinputstream;1"]
+ var instream = Components
+ .classes["@mozilla.org/scriptableinputstream;1"]
.createInstance(Components.interfaces.nsIScriptableInputStream);
instream.init(stream);
@@ -278,56 +261,37 @@
onStartRequest: function(request, context) { this.data = ""; },
onStopRequest: function(request, context, status) {
instream.close();
+ stream.close();
outstream.close();
- // Remove last CRLF
this.data = this.data.replace(/[\n\r]{1,2}$/, "");
listener.finished(this.data);
},
- onDataAvailable: function(request, context,
- inputStream, offset, count) {
- // TODO: limit the amount of data send through the socket!
- var chunk = instream.read(count);
+ onDataAvailable: function(request, context, inputStream,
+ offset, count) {
+ var chunk = _toUnicode(instream.read(count));
- if (converter.charset)
- try { // Convert read string to unicode (Bug #240)
- chunk = converter.ConvertToUnicode(chunk);
- } catch(e) {
- koLogger.error("rClient() is unable to convert " +
- "to Unicode: " + e);
- }
-
- // Determine if we have a prompt at the end
- if (chunk.search(/\+\s+$/) > -1) {
- this.prompt = ":+ ";
- // Remove endline from prompt if it is a continuation
- chunk = chunk.rtrim() + " ";
- } else if (chunk.search(/>\s+$/) > -1) {
- this.prompt = ":> ";
- }
-
// Do we need to close the connection
// (\f received, followed by \n, \r, or both)?
if (chunk.match("\n\f") == "\n\f") {
instream.close();
+ stream.close();
outstream.close();
// Eliminate trailing (\r)\n\f chars before the prompt
// Eliminate the last carriage return after the prompt
chunk = chunk.replace(/(\r?\n\f|\s+$)/, "");
}
- this.data += chunk;
- // Do we "echo" these results somewhere?
- if (echo) {
- if (echofun == null) {
- // Use default echo function (to the Command Output)
-//// TODO: eliminate this from here! sv.cmdout.append(chunk, newline = false);
- } else echofun(chunk);
+
+ // Determine if we have a prompt at the end
+ if (chunk.search(/\+\s+$/) > -1) {
+ chunk = chunk.rtrim() + " ";
}
+ this.data += chunk;
}
}
- var pump = Components.
- classes["@mozilla.org/network/input-stream-pump;1"].
- createInstance(Components.interfaces.nsIInputStreamPump);
+ var pump = Components
+ .classes["@mozilla.org/network/input-stream-pump;1"]
+ .createInstance(Components.interfaces.nsIInputStreamPump);
pump.init(stream, -1, -1, 0, 0, false);
pump.asyncRead(dataListener, null);
} catch (e) {
@@ -338,30 +302,34 @@
}
// Send an R command through the socket
-function rCommand(cmd, echo, echofun, procfun, context) {
- // Get R's charset before first request and set converter.charset (Bug #240)
- this.rCharset();
- // Replace CRLF
- cmd = cmd.replace(/(\r?\n|\r)/g, "<<<n>>>");
-
+function rCommand(cmd, procfun) {
+ var host = getPrefString("sciviews.server.host", "127.0.0.1");
+ var port = getPrefString("sciviews.client.socket", "8888");
+ var id = "<<<id=" +
+ getPrefString("sciviews.client.id", "SciViewsK") + ">>>";
+ cmd = cmd.replace(/(\r?\n|\r)/g, "<<<n>>>"); // Replace CRLF
var listener;
if (procfun == null) { // Do nothing at the end
listener = { finished: function(data) {} }
} else { // Call procfun at the end
- listener = { finished: function(data) { procfun(data, context); } }
+ // Convert all arguments to an Array
+ var args = Array.apply(null, arguments);
+ listener = {
+ finished: function (data) {
+ // Keep only arguments after procfun, and add "data"
+ args.splice(0, 3, data);
+ if (typeof(procfun) == "function") {
+ procfun.apply(null, args);
+ } else { // In fact we can add a property even to a function
+ procfun.value = data;
+ }
+ }
+ }
}
- // TODO: deal with error checking for this command
- var port = getPrefString("sciviews.client.socket", "8888");
- var id = "<<<id=" +
- getPrefString("sciviews.client.id", "SciViewsK") + ">>>";
- var res = this.rClient(this.host, port, id + cmd + "\n",
- listener, echo, echofun);
-
- // if exception was returned:
+ var res = rClient(host, port, id + cmd + "\n", listener);
if (res && res.name && res.name == "NS_ERROR_OFFLINE") {
- koLogger.error("R is unreacheable: " + res);
+ koLogger.error("Error: Komodo went offline! " + res);
}
return(res);
}
//Test: rCommand("<<<q>>>cat('library = '); str(library)");
-
Modified: komodo/SciViews-K/content/RHelpWindow.xul
===================================================================
--- komodo/SciViews-K/content/RHelpWindow.xul 2010-09-26 21:17:37 UTC (rev 320)
+++ komodo/SciViews-K/content/RHelpWindow.xul 2010-09-29 07:54:41 UTC (rev 321)
@@ -61,28 +61,24 @@
var rHelpTopic;
function go(uri, loadFlags) {
- // these are still undefined when calling .go on load event,
- // so define them here:
-
+ // These are still undefined when calling .go on load event,
+ // so define them here
rHelpBrowser = document.getElementById("rhelp-browser");
-
switch (uri) {
- case "":
- case "@home@":
- rHelpBrowser.goHome();
- return;
- case "@CRAN@":
- uri = sv.prefs.getString("CRANMirror");
- if (!uri || uri.indexOf("ftp:/") === 0)
- uri = "http://cran.r-project.org/";
+ case "":
+ case "@home@":
+ rHelpBrowser.goHome();
+ return;
+ case "@CRAN@":
+ uri = sv.prefs.getString("CRANMirror");
+ if (!uri || uri.indexOf("ftp:/") === 0)
+ uri = "http://cran.r-project.org/";
}
rHelpTopic = document.getElementById("rhelp-topic");
// In case the window was not yet fully loaded.
if (!rHelpTopic) {
- self.addEventListener("load", function(event) {
- go(uri);
- }, false);
+ self.addEventListener("load", function(event) { go(uri); }, false);
return;
}
@@ -93,7 +89,6 @@
}
rHelpTopic.select();
-
// Try to differentiate an URL from a help topic
var isUri = uri.search(/^((f|ht)tps?|chrome|about|file):\/{0,3}/) === 0;
@@ -120,8 +115,7 @@
}
function search(topic) {
- if (!topic) return;
-
+ if (!topic) return;
rHelpTopic.select();
sv.r.search(topic);
}
@@ -151,18 +145,14 @@
}
}
-// Browser progress listener:
-// so far used only to change title and location text
-
+// Browser progress listener: so far used only to change title and location text
// From: https://developer.mozilla.org/en/Code_snippets/Progress_Listeners
-
var progressListener = {
QueryInterface: function(aIID) {
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
- aIID.equals(Components.interfaces.nsISupports))
- return this;
- throw Components.results.NS_NOINTERFACE;
+ aIID.equals(Components.interfaces.nsISupports)) return(this);
+ throw(Components.results.NS_NOINTERFACE);
},
onStateChange: function(aWebProgress, aRequest, aFlag, aStatus) {
@@ -172,9 +162,7 @@
if (aFlag & Components.interfaces.nsIWebProgressListener.STATE_START) {
// This fires when the load event is initiated
- document.getElementById("cmd_stop")
- .setAttribute("disabled", false);
-
+ document.getElementById("cmd_stop").setAttribute("disabled", false);
document.getElementById("cmd_stop").hidden = false;
document.getElementById("cmd_reload").hidden = true;
}
@@ -184,18 +172,13 @@
self.document.title = aWebProgress.DOMWindow.document.title;
rHelpTopic.value = aWebProgress.DOMWindow.document.location;
- document.getElementById("cmd_stop")
- .setAttribute("disabled", true);
-
+ document.getElementById("cmd_stop").setAttribute("disabled", true);
document.getElementById("cmd_stop").hidden = true;
document.getElementById("cmd_reload").hidden = false;
-
document.getElementById("cmd_go_back")
- .setAttribute("disabled", !rHelpBrowser.webNavigation
- .canGoBack)
+ .setAttribute("disabled", !rHelpBrowser.webNavigation.canGoBack)
document.getElementById("cmd_go_forward")
- .setAttribute("disabled", !rHelpBrowser.webNavigation
- .canGoForward);
+ .setAttribute("disabled", !rHelpBrowser.webNavigation.canGoForward);
}
},
@@ -209,11 +192,9 @@
// This redirects result page from html search form to rHelpSearch results:
//FIXME: on the results page, when .goBack is invoked, page will be redirected again
if (aProgress.DOMWindow.document.location.href
- .search(/search\/SearchEngine\.html\?.*SEARCHTERM=([a-z0-9+%]*)(?=&|$)/) != -1) {
-
- rHelpSearch(RegExp.$1);
+ .search(/search\/SearchEngine\.html\?.*SEARCHTERM=([a-z0-9+%]*)(?=&|$)/) != -1) {
+ rHelpSearch(RegExp.$1);
}
-
},
// For definitions of the remaining functions see XULPlanet.com
@@ -232,13 +213,9 @@
}
function rHelpBrowserContextOnShow(event) {
-
- var selText = sv.tools.strings.trim(window._content.getSelection()
- .toString());
-
+ var selText = sv.tools.strings.trim(window._content.getSelection().toString());
var el = document.getElementById("cmd_rsearch_for");
var elLabel;
-
var nothingSelected = !selText;
if (nothingSelected) {
@@ -255,7 +232,7 @@
function runSelAsRCode() {
var selText = sv.tools.strings.trim(window._content.getSelection()
- .getRangeAt(0).toString());
+ .getRangeAt(0).toString());
// Looks like R help page, so require package first
win = window._content;
@@ -264,16 +241,13 @@
var docTables = doc.getElementsByTagName("table");
if (docTables.length > 0
&& docTables[0].summary.search(/page for (\S+) \{([\w\.]+)\}/) == 0) {
-
selText = "require(" + RegExp.$2 + ")\n" + selText;
-
//TODO: for remote help files, ask to install package in not available
}
}
sv.r.eval(selText);
}
-
// display formatted search results in a help window
function rHelpSearch(topic) {
if (!topic) return;
@@ -295,30 +269,40 @@
//var cmd = 'suppressMessages(make.packages.html()); ';
//cmd += 'options(htmlhelp = TRUE); ';
//cmd += "cat(" + (isWin? "R.home()" : "tempdir()") + ");";
- // Make sure that help is started, but do not open a browser
- var cmd = 'invisible(capture.output(suppressMessages(help.start(browser = function(...) return())))); ';
- // return the home page of R 2.10 help system
- cmd += 'cat(paste("\n", "http://127.0.0.1:", tools:::httpdPort, "/doc/html/index.html", sep = ""))';
-
- var res = sv.r.evalCallback(cmd, function (path) {
- path = sv.tools.strings.removeLastCRLF(path);
- // Old treatment for R < 2.10
- //path = sv.tools.file.getfile(path,
- // [(isWin? null : ".R"), "doc", "html", "index.html"]);
- //path = sv.tools.file.getURI(path);
-
- // get just the last line, get rid of the help.start's message
- path = path.substring(path.lastIndexOf("\n") + 1);
-
+
+ // If it is the http server, we know that the help server is launched
+ // (it is the same), and we also know the port!
+ var res = false;
+ var cmd = "";
+ if (sv.r.server == "http") {
+ var port = sv.prefs.getString("sciviews.client.socket", "8888");
+ var path = "http://127.0.0.1:" + port + "/doc/html/index.html";
browser.homePage = sv.helpStartURI = path;
-
//alert(browser.homePage);
+ if (goTo) go(path);
+ } else { // socket, we must start the help server and ask for its port
+ // Make sure that help is started, but do not open a browser
+ cmd = 'invisible(capture.output(suppressMessages(help.start(browser = function(...) return())))); ';
+ // return the home page of R >= 2.10 help system
+ cmd += 'cat(paste("\n", "http://127.0.0.1:", tools:::httpdPort, "/doc/html/index.html", sep = ""))';
- if (goTo) go(path);
- });
-}
+ res = sv.r.evalCallback(cmd, function (path) {
+ path = sv.tools.strings.removeLastCRLF(path);
+ // Old treatment for R < 2.10
+ //path = sv.tools.file.getfile(path,
+ // [(isWin ? null : ".R"), "doc", "html", "index.html"]);
+ //path = sv.tools.file.getURI(path);
+ // Get just the last line, get rid of the help.start's message
+ path = path.substring(path.lastIndexOf("\n") + 1);
+ browser.homePage = sv.helpStartURI = path;
+ //alert(browser.homePage);
+ if (goTo) go(path);
+ });
+ }
+}
+
var browserUtils = {};
(function() {
@@ -326,28 +310,21 @@
this.purgeCache = function() {
var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
.getService(Components.interfaces.nsICacheService);
-
cacheService.evictEntries(Components.interfaces.nsICache.STORE_ANYWHERE);
}
this.purgeHistory = function() {
- if (rHelpBrowser.docShell.sessionHistory.count) {
+ if (rHelpBrowser.docShell.sessionHistory.count)
rHelpBrowser.docShell
.sessionHistory.PurgeHistory(rHelpBrowser.docShell.sessionHistory.count);
- }
}
-
-
}).apply(browserUtils);
function OnLoad (event) {
// DOMContentLoaded is fired also for HTML content
- if (event.target != self.document)
- return;
-
+ if (event.target != self.document) return;
var page;
-
if (window.arguments) {
var args = window.arguments;
sv = args[0];
@@ -364,18 +341,16 @@
rHelpTopic = document.getElementById("rhelp-topic");
rHelpTopic.clickSelectsAll = true;
-
rHelpBrowser = document.getElementById("rhelp-browser");
-
rHelpBrowser.addProgressListener(progressListener,
- Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
+ Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
var findToolbar = document.getElementById("FindToolbar");
// Listen to find toolbar attribute modifications:
findToolbar.addEventListener("DOMAttrModified",
onFindToolbarAttrModified, false);
- go(page? page : "about:blank");
+ go(page ? page : "about:blank");
_getHomePage(rHelpBrowser, !page);
// Print preview does not work on a Mac, disable that command then
Modified: komodo/SciViews-K/content/js/ask.js
===================================================================
--- komodo/SciViews-K/content/js/ask.js 2010-09-26 21:17:37 UTC (rev 320)
+++ komodo/SciViews-K/content/js/ask.js 2010-09-29 07:54:41 UTC (rev 321)
@@ -9,6 +9,7 @@
//
////////////////////////////////////////////////////////////////////////////////
// TODO: list files in a directory and a given extension
+// implement sv.ask.vars and sv.ask.factors
if (typeof(sv.ask) == 'undefined') sv.ask = new Object();
@@ -19,7 +20,7 @@
// Otherwise, ask R for the classes (also look if it is data.frame or lm)!
var cls, i;
switch (arguments.length) {
- case 1:
+ case 1:
// No class provided => send code to R to set it according to the
// actual class of the object
res = sv.r.evalCallback('if (exists("' + object + '")) ' +
@@ -40,8 +41,7 @@
}
);
break;
-
- case 2:
+ case 2:
// Classes are provided (separated by |)
cls = classes.split("|");
for (i = 0; i < cls.length; i++) {
@@ -56,6 +56,25 @@
}
}
+// The callback function for sv.ask.setDefault
+// TODO: use a RJSONP object instead
+sv.ask.setDefault_callback = function (msg) {
+ // In the case of http server, we got a more complex object!
+ if (msg.result !== undefined) msg = msg.result;
+
+ var cls = sv.tools.strings.removeLastCRLF(msg).split("|");
+ var obj = cls[0];
+ for (i = 1; i < cls.length; i++) {
+ if (cls[i] != null & cls[i] != "") {
+ sv.prefs.setString("r.active." + cls[i], obj, true);
+ if (cls[i] == "data.frame") {
+ sv.prefs.setString("r.active.data.frame.d", obj + "$", true);
+ sv.r.obj_message();
+ } else if (cls[i] == "lm") sv.r.obj_message();
+ }
+ }
+}
+
// List all numeric variables for object
sv.ask.vars = function (object, restrict) {
// TODO...
Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js 2010-09-26 21:17:37 UTC (rev 320)
+++ komodo/SciViews-K/content/js/commands.js 2010-09-29 07:54:41 UTC (rev 321)
@@ -1,6 +1,6 @@
// SciViews-K command functions
// Define the 'sv.command' namespace
-// Copyright (c) 2009, K. Barton & Ph. Grosjean (phgrosjean at sciviews.org)
+// Copyright (c) 2009-2010, K. Barton & Ph. Grosjean (phgrosjean at sciviews.org)
// License: MPL 1.1/GPL 2.0/LGPL 2.1
////////////////////////////////////////////////////////////////////////////////
// sv.command.startR(); // Start the preferred R app and connect to it
@@ -28,36 +28,30 @@
var win;
while (en.hasMoreElements()) {
win = en.getNext();
- if (win.location.href == uri)
- return win;
+ if (win.location.href == uri) return(win);
}
}
- return null;
+ return(null);
}
- //Get reference to a window, opening it if is closed
- function _getWindowRef(uri, name, features, focus) {//, ...
+ // Get reference to a window, opening it if is closed
+ function _getWindowRef(uri, name, features, focus) { //, ...
var win = _getWindowByURI(uri);
if (!win || win.closed) {
try {
var args = Array.apply(null, arguments);
- args = args.slice(0,3).concat(args.slice(4));
- //return(args);
-
- if (!features)
- args[2] = "chrome,modal,titlebar";
-
+ args = args.slice(0, 3).concat(args.slice(4));
+ if (!features) args[2] = "chrome,modal,titlebar";
win = window.openDialog.apply(null, args);
} catch (e) {
- alert(e);
sv.log.exception(e, "Error opening window: " + uri);
}
}
if (focus) win.focus();
}
- // private methods
- // continuous checking is now disabled - R often hanged
+ // Private methods
+ // Continuous checking is now disabled - R often hanged
function _keepCheckingR (stopMe) {
/*
//clearInterval(sv.r.testInterval);
@@ -73,136 +67,129 @@
function _isRRunning () {
//TODO: temporary solution
- return true;
- //return sv.r.running;
+ return(true);
+ //return(sv.r.running);
}
function _RControl_supported () {
var currentView = ko.views.manager.currentView;
- if (!currentView || !currentView.document)
- return false;
+ if (!currentView || !currentView.document) return(false);
//return(_isRRunning() && currentView.document.language == "R");
return(currentView.document.language == "R");
}
function _RControlSelection_supported () {
var currentView = ko.views.manager.currentView;
- if (!currentView || !currentView.scimoz)
- return false;
-
- return _RControl_supported()
- && ((currentView.scimoz.selectionEnd -
- currentView.scimoz.selectionStart) != 0);
+ if (!currentView || !currentView.scimoz) return(false);
+ return (_RControl_supported() &&
+ ((currentView.scimoz.selectionEnd -
+ currentView.scimoz.selectionStart) != 0));
}
-// Start R
-this.startR = function () {
- var cwd = sv.tools.file.path("ProfD", "extensions",
- "sciviewsk at sciviews.org", "defaults");
- var cmd = sv.prefs.getString("svRApplication");
-
- // PhG: there is a bug in the way R starts: at the begining, a dummy '00LOCK'
- // file is created that prevents to config another R process as SciViews socket
- // server. Everytime svStart.R is run, it looks if this '00LOCK' file exists,
- // and if it finds it, it refuses to configure R as a socket server.
- // OK, but what happens if the config of the SciViews R server fails in the
- // middle of the process? Well, '00LOCK' is not removed, and it is not possible
- // any more to configure R (automatically) as a SciViews socket server.
- // To cope with this problem, I make sure '00LOCK' is deleted everytime the
- // SciViews-K plugin is loaded in Komodo Edit. That way, restarting Komodo
- // solves the problem of the remaining '00LOCK' file, in case R failed...
-
- // KB: The '00LOCK' semaphore is used mainly to prevent infinite loop when
- // R restarts after installing missing libraries (as it is done in svStart).
- // So, it should be ok to delete it everytime user chooses a command to
- // start R from Komodo.
- try {
- var lockFile = sv.tools.file.getfile(cwd, "00LOCK");
- if (lockFile.exists()) lockFile.remove(true);
- } catch(e) { }
-
- // trim just in case
- var path = sv.tools.strings.trim(sv.prefs.getString("svRDefaultInterpreter"));
-
- // PhG: on Mac OS X, R.app is not a file, but a dir!!!
- if (!path || (sv.tools.file.exists(path) == sv.tools.file.TYPE_NONE)) {
- if(ko.dialogs.okCancel(
- sv.translate("Default R interpreter is not (correctly) set in " +
- "Preferences. Do you want to do it now?"),
- "OK", null, "SciViews-K") == "OK") {
- prefs_doGlobalPrefs("svPrefRItem", true);
- }
- return;
- }
-
- // PhG: %Path% has changed: it is now the full application path, like "/usr/bin/R"!
- // So, the following code should be eliminated!
- //var os = Components.classes['@activestate.com/koOs;1']
- //.getService(Components.interfaces.koIOs);
- //path = os.path.dirname(path);
- //if (path) path += os.sep;
- //TODO: shouldn't we replace this with a command line argument which would
- // be more flexible, because it should allow much more than just --quiet???
- // KB: work in progress...
-
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/sciviews -r 321
More information about the Sciviews-commits
mailing list