[Sciviews-commits] r227 - in komodo/SciViews-K: R content content/js content/js/tools
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Nov 12 09:24:02 CET 2009
Author: prezez
Date: 2009-11-12 09:24:02 +0100 (Thu, 12 Nov 2009)
New Revision: 227
Modified:
komodo/SciViews-K/R/svStart.R
komodo/SciViews-K/content/js/commands.js
komodo/SciViews-K/content/js/tools/file.js
komodo/SciViews-K/content/overlayMain.xul
Log:
Added "sv.tools.file.whereIs" - tries to find a full path of an application (tested only on Ubuntu and WinXP). Used in validating R applications in the menu.
Fixed a bug with R-tk (linux) closing on any error: "--interactive" was missing.
Modified: komodo/SciViews-K/R/svStart.R
===================================================================
--- komodo/SciViews-K/R/svStart.R 2009-11-11 14:10:56 UTC (rev 226)
+++ komodo/SciViews-K/R/svStart.R 2009-11-12 08:24:02 UTC (rev 227)
@@ -266,6 +266,7 @@
}
res <- all(res) # all packages are loaded
+
if (res) {
# Make sure Komodo is started now
# Note: in Mac OS X, you have to create the symbolic link manually
@@ -282,8 +283,8 @@
if (.Platform$OS.type == "unix") {
Komodo <- "/usr/local/bin/komodo" # default location
if (!file.exists(Komodo)) {
- Komodo <- system("which komodo", intern = T, ignore.stderr = TRUE)
- debugMsg("which komodo", "returned", Komodo)
+ Komodo <- Sys.which("komodo")[1]
+ debugMsg("which", "returned", Komodo)
}
if (length(Komodo) == 0 || Komodo == "") {
@@ -425,8 +426,15 @@
msg <- paste(msg, "[data loaded")
} else msg <- paste(msg, "[no data")
if (file.exists(".Rhistory")) {
- loadhistory()
- msg <- paste(msg, ... = "/history loaded]", sep = "")
+ # On R Tk gui:
+ # "Error in loadhistory(file) : no history mechanism available"
+ history.loaded <- try(loadhistory(), silent = TRUE)
+ if (inherits(history.loaded, "try-error")) {
+ msg <- paste(msg, "/history cannot be loaded]", sep = "")
+ } else {
+ msg <- paste(msg, "/history loaded]", sep = "")
+ }
+
} else msg <- paste(msg, "/no history]", sep = "")
} else msg <- paste(msg, "[data/history not loaded]")
cat(msg, "\n", sep = "", file = stderr())
Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js 2009-11-11 14:10:56 UTC (rev 226)
+++ komodo/SciViews-K/content/js/commands.js 2009-11-12 08:24:02 UTC (rev 227)
@@ -95,11 +95,21 @@
// Apply patch (koext_include_R_dir.patch) to <komodoInstallDir>/lib/sdk/pylib/koextlib.py,
// to make it include R directory in the .xpi
- // otherwise the directory can be added manually. Then replace following line:
- var cwd = sv.tools.file.path("ProfD", "extensions", "sciviewsk at sciviews.org", "templates");
+ // otherwise the directory can be added manually.
+
+ //Until we decide to keep R files in "R" or "templates"
+ if (sv.tools.file.exists(sv.tools.file.path(
+ "ProfD/extensions/sciviewsk at sciviews.org/R/.Rprofile"))) {
+ var cwd = sv.tools.file.path("ProfD", "extensions",
+ "sciviewsk at sciviews.org", "R");
+ } else {
+ var cwd = sv.tools.file.path("ProfD", "extensions",
+ "sciviewsk at sciviews.org", "templates");
+ }
+
// with:
//var cwd = sv.tools.file.path("ProfD", "extensions", "sciviewsk at sciviews.org", "R");
-
+
var command, runIn = "no-console";
sv.cmdout.message(sv.translate("Starting R... please wait"), 10000, true);
@@ -128,7 +138,8 @@
if (!XEnv.has("DISPLAY"))
env.push("DISPLAY=:0");
delete XEnv;
- command = "R --quiet --save --gui=Tk";
+ // without forced --interactive R-tk halts on any error!
+ command = "R ---interactive --gui=Tk";
// runIn = "no-console";
break;
case "r-app":
@@ -262,47 +273,38 @@
var isLinux = navigator.platform.toLowerCase().indexOf("linux") > -1;
var isMac = navigator.platform.toLowerCase().indexOf("mac") > -1;
+ var isWin = navigator.platform.toLowerCase().indexOf("win") == 0;
- // This will tell whether an app is present on the *nix system
- function whereis(app) {
- var runSvc = Components.
- classes["@activestate.com/koRunService;1"].
- getService(Components.interfaces.koIRunService);
- var err = {}, out = {};
- var res = runSvc.RunAndCaptureOutput("whereis -b " + app,
- null, null, null, out, err);
- var path = out.value.substr(app.length + 2);
- if (!path) return false;
- return out.value.substr(app.length + 2).split(" ");
- }
-
var validPlatforms, showItem;
var platform = navigator.platform;
for (var i = 0; i < siblings.length; i++) {
try {
validPlatforms = siblings[i].getAttribute("platform").
- split(/\s*[,\s]\s*/);
+ split(/[,\s]+/);
showItem = false;
for (var j in validPlatforms) {
if (platform.indexOf(validPlatforms[j]) > -1) {
// On linux, try to determine which terminals are
// not available and remove these items from menu
- if (isLinux) {
- if (whereis(siblings[i].getAttribute("app"))) {
+
+ var appName = siblings[i].getAttribute("app");
+ if (isLinux || isWin) {
+
+ //!!!!TODO: appName = appName.split(/[, ]+/);
+ //appName = appName.split(/[, ]+/);
+ var res = true;
+ for (var k in appName.split(/[, ]+/))
+ res = res && !!sv.tools.file.whereIs(appName);
+ if (res) {
showItem = true;
break;
}
} else if (isMac) {
// Check that we find the application
- var Rapp = siblings[i].getAttribute("app");
- if (Rapp == "R" || sv.tools.file.exists(Rapp)) {
+ if (appName == "R" || sv.tools.file.exists(appName)) {
showItem = true;
break;
}
- } else { // Windows, RGui & RTerm always available?
- // (assuming R is installed, yes.)
- showItem = true;
- break;
}
}
}
@@ -405,7 +407,6 @@
RHelpWin.go(uri);
} else {
- //alert("open help.");
_this.RHelpWin = _getWindowByURI(rHelpXulUri);
if (!RHelpWin || RHelpWin.closed) {
sv.log.debug("Starting R help with page " + uri);
@@ -487,7 +488,8 @@
}, 100);
};
- //TODO: check if R is working before any command is sent, rather than continously
+ //TODO: check if R is working before any command is sent,
+ //rather than continously
_keepCheckingR();
// This is no longer needed:
Modified: komodo/SciViews-K/content/js/tools/file.js
===================================================================
--- komodo/SciViews-K/content/js/tools/file.js 2009-11-11 14:10:56 UTC (rev 226)
+++ komodo/SciViews-K/content/js/tools/file.js 2009-11-12 08:24:02 UTC (rev 227)
@@ -21,6 +21,9 @@
// sv.tools.file.readURI(uri); // Read data from an URI
// sv.tools.file.list(dirname, pattern, noext); // List all files matching
// pattern in dirname (with/without extension)
+// sv.tools.file.whereIs(appName);
+ // Tries to find full application path,
+ // returns null if not found
////////////////////////////////////////////////////////////////////////////////
// Define the 'sv.tools' namespace
@@ -165,7 +168,6 @@
return file? file : dirName;
}
-
// Create nsILocalFile object from path
// concatenates arguments if needed
this.getfile = function (path) {
@@ -257,4 +259,70 @@
return(null);
}
+// TODO: check registry keys for Windows versions other than XP
+if (navigator.platform.indexOf("Win") == 0) {
+ function _findFileInPath(file) {
+ var os = Components.classes['@activestate.com/koOs;1'].
+ getService(Components.interfaces.koIOs);
+ var dirs = os.getenv("PATH").split(os.pathsep);
+ var res = [];
+ for (i in dirs)
+ if (os.path.exists(os.path.join(dirs[i], file))) res.push(dirs[i]);
+ return res.length? res : null;
+ }
+
+ this.whereIs = function(appName) {
+ if (appName.search(/\.exe$/i) == -1)
+ appName += ".exe";
+
+ var reg = Components.classes["@mozilla.org/windows-registry-key;1"]
+ .createInstance(Components.interfaces.nsIWindowsRegKey);
+ var key, path;
+
+ // Special treatment for R* apps:
+ if (appName.match(/^R(?:gui|term|cmd)?\.exe?$/i)) {
+ try {
+ key = "software\\R-core\\R";
+ reg.open(reg.ROOT_KEY_LOCAL_MACHINE, key, reg.ACCESS_READ)
+ } catch(e) {
+ key = "software\\wow6432Node\\r-core\\r";
+ reg.open(reg.ROOT_KEY_LOCAL_MACHINE, key, reg.ACCESS_READ);
+ }
+ if (!reg.hasValue("InstallPath") && reg.hasValue("Current Version")) {
+ reg = reg.openChild(reg.readStringValue("Current Version"),
+ reg.ACCESS_READ);
+ }
+ if (reg.hasValue("InstallPath"))
+ return reg.readStringValue("InstallPath") + "\\bin\\" + appName;
+ }
+
+ var key = "Applications\\" + appName + "\\shell\\Open\\Command";
+ try {
+ reg.open(reg.ROOT_KEY_CLASSES_ROOT, key, reg.ACCESS_READ);
+ path = reg.readStringValue("");
+ path = path.replace(/(^"|"?\s*"%\d.*$)/g, "");
+ return path;
+ } catch(e) {
+ // fallback: look for app in PATH:
+ return _findFileInPath(appName);
+ }
+ return null;
+ }
+} else {
+ // Will it work on Mac too?
+ this.whereIs = function(appName) {
+ var runSvc = Components.
+ classes["@activestate.com/koRunService;1"].
+ getService(Components.interfaces.koIRunService);
+ var err = {}, out = {};
+ var res = runSvc.RunAndCaptureOutput("which " + appName,
+ null, null, null, out, err);
+ var path = out.value.trim();
+ if (!path) return null;
+ return path.split(" ");
+ }
+
+}
+
+
}).apply(sv.tools.file);
Modified: komodo/SciViews-K/content/overlayMain.xul
===================================================================
--- komodo/SciViews-K/content/overlayMain.xul 2009-11-11 14:10:56 UTC (rev 226)
+++ komodo/SciViews-K/content/overlayMain.xul 2009-11-12 08:24:02 UTC (rev 227)
@@ -199,12 +199,13 @@
app="/Applications/SciViews R64.app" platform="Mac"/>
<!--<menuitem id="jgrmac-app" type="checkbox" checked="false" label="JGR"
app="/Applications/JGR.app" platform="Mac"/>-->
- <menuitem id="r-gnome-term" type="checkbox" checked="false" label="R Gnome terminal"
- app="gnome-terminal" platform="Linux"/>
+ <menuitem id="r-gnome-term" type="checkbox" checked="false"
+ label="R Gnome terminal"
+ app="gnome-terminal,R" platform="Linux"/>
<menuitem id="r-kde-term" type="checkbox" checked="false" label="R KDE terminal"
- app="konsole" platform="Linux"/>
+ app="konsole,R" platform="Linux"/>
<menuitem id="r-xfce4-term" type="checkbox" checked="false" label="R XFCE terminal"
- app="xfce4-terminal" platform="Linux"/>
+ app="xfce4-terminal,R" platform="Linux"/>
<menuitem id="r-gui" type="checkbox" checked="false" label="R GUI"
app="Rgui" platform="Win"/>
<menuitem id="r-terminal" type="checkbox" checked="false" label="R terminal"
More information about the Sciviews-commits
mailing list