[Sciviews-commits] r326 - komodo/SciViews-K/content komodo/SciViews-K/content/js komodo/SciViews-K/content/js/tools komodo/SciViews-K/locale/en-GB komodo/SciViews-K/skin komodo/SciViews-K/skin/images pkg/svGUI/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Oct 4 16:26:51 CEST 2010
Author: prezez
Date: 2010-10-04 16:26:51 +0200 (Mon, 04 Oct 2010)
New Revision: 326
Modified:
komodo/SciViews-K/content/RObjectsOverlay.xul
komodo/SciViews-K/content/js/commands.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-help.js
komodo/SciViews-K/content/js/r.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/file.js
komodo/SciViews-K/content/overlayMain.xul
komodo/SciViews-K/content/pref-R.xul
komodo/SciViews-K/content/prefOverlay.xul
komodo/SciViews-K/content/sessions.xul
komodo/SciViews-K/locale/en-GB/sciviewsk.dtd
komodo/SciViews-K/skin/images/arrow_refresh_disabled.png
komodo/SciViews-K/skin/images/stop_disabled.png
komodo/SciViews-K/skin/sciviewsk.css
pkg/svGUI/R/guiInstall.R
pkg/svGUI/R/guiRefresh.R
Log:
A load of changes that accumulated over longer time. Hopefully no regression. Seems to work fine on Win7 and Ubuntu.
pref-R.xul: Preferences moved into Languages->R (This is a suggestion. It is a more obvious location for these settings). On Win and Linux system is searched for all R installations. This now resembles other languages in Komodo. Added custom arguments for the R command line.
overlayMain.xul: added R toolbar with most important commands.
robjects.js: many small fixes (together with svGUI::guiRefresh)
sv.socket.serverStart: user is offered a change of port number if current port is used
sv.tools.file.whereIs: returns now an *array* of all R installation paths (previously only the default one). Previously returned a *string*.
sessions.xul: option to set session directory as 'Places' root.
Modified: komodo/SciViews-K/content/RObjectsOverlay.xul
===================================================================
--- komodo/SciViews-K/content/RObjectsOverlay.xul 2010-10-04 09:46:50 UTC (rev 325)
+++ komodo/SciViews-K/content/RObjectsOverlay.xul 2010-10-04 14:26:51 UTC (rev 326)
@@ -49,6 +49,10 @@
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
+<script type="application/x-javascript" src="chrome://sciviewsk/content/js/robjects.js"/>
+
+
<popupset id="extensionPopupSet">
<menupopup id="rObjectsContext"
onpopupshowing="sv.r.objects.contextOnShow();">
Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js 2010-10-04 09:46:50 UTC (rev 325)
+++ komodo/SciViews-K/content/js/commands.js 2010-10-04 14:26:51 UTC (rev 326)
@@ -34,13 +34,13 @@
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));
+ args = args.slice(0,3).concat(args.slice(4));
if (!features) args[2] = "chrome,modal,titlebar";
win = window.openDialog.apply(null, args);
} catch (e) {
@@ -73,123 +73,90 @@
function _RControl_supported () {
var currentView = ko.views.manager.currentView;
- if (!currentView || !currentView.document) return(false);
- //return(_isRRunning() && currentView.document.language == "R");
- return(currentView.document.language == "R");
+ if (!currentView || !currentView.koDoc) return(false);
+ //return(_isRRunning() && currentView.koDoc.language == "R");
+ return(currentView.koDoc.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));
}
- // 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;
+// Start R
+this.startR = function () {
+ var cwd = sv.tools.file.path("ProfD", "extensions",
+ "sciviewsk at sciviews.org", "defaults");
+ var cmd = sv.prefs.getString("svRCommand");
+
+ // Remove /defaults/00LOCK if remained after a fail-start
+ try {
+ var lockFile = sv.tools.file.getfile(cwd, "00LOCK");
+ if (lockFile.exists()) lockFile.remove(true);
+ } catch(e) { }
+
+
+ if (!cmd || (sv.tools.file.exists(sv.prefs.getString("svRDefaultInterpreter"))
+ == 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...
- var Quiet = sv.prefs.getString("svRQuiet") ? "--quiet " : " ";
- cmd = cmd.replace("%Path%", path).replace("%cwd%", cwd)
- .replace("%title%", "SciViews-R").replace("%quiet%", Quiet);
-
- //var Args = sv.prefs.getString("svRArgs");
- //cmd = cmd.replace("%Path%", path).replace("%cwd%", cwd)
- // .replace("%title%", "SciViews-R").replace("%args%", Args);
-
+
+ var id=sv.prefs.getString("svRApplication",
+ isWin? "r-gui" : "r-terminal");
+
var id = sv.prefs.getString("svRApplicationId");
-
- // runIn = "command-output-window", "new-console",
- // env strings: "ENV1=fooJ\nENV2=bar"
- // gPrefSvc.prefs.getStringPref("runEnv");
-
- // Reasonable default values are set in prefs.js... but just in case, we
- // make sure to redefine reasonable default values here
- var isWin = navigator.platform.indexOf("Win") === 0;
- // Default preferredRApp on Windows is r-gui
- var preferredRApp = sv.prefs.getString("svRApplicationId",
- isWin ? "r-gui" : "r-terminal");
- var env = ["koId=" + sv.prefs.getString("sciviews.client.id",
- "SciViewsK"),
- "koHost=localhost",
- "koActivate=FALSE",
- "Rinitdir=" + sv.prefs.getString("sciviews.session.dir", "~"),
- "koServe=" + sv.prefs.getString("sciviews.client.socket", "8888"),
- "koPort=" + sv.prefs.getString("sciviews.server.socket", "7052"),
- "koDebug=" + String(sv.socket.debug).toUpperCase(),
- "koAppFile=" + sv.tools.file.path("binDir", "komodo" + (isWin ? ".exe" : ""))
- ];
- var runIn = "no-console";
- env.push("Rid=" + preferredRApp);
-
- switch (preferredRApp) {
- case "r-tk":
+ // runIn = "command-output-window", "new-console",
+ // env strings: "ENV1=fooJ\nENV2=bar"
+ // gPrefSvc.prefs.getStringPref("runEnv");
+
+ // Reasonable default values are set in prefs.js... but just in case, we
+ // make sure to redefine reasonable default values here
+ var isWin = navigator.platform.indexOf("Win") === 0;
+ // Default preferredRApp on Windows is r-gui
+ var preferredRApp = sv.prefs.getString("svRApplicationId",
+ isWin? "r-gui" : "r-terminal");
+
+ var env = ["koId=" + sv.prefs.getString("sciviews.client.id",
+ "SciViewsK"),
+ "koHost=localhost",
+ "koActivate=FALSE",
+ "Rinitdir=" + sv.prefs.getString("sciviews.session.dir", "~"),
+ "koServe=" + sv.prefs.getString("sciviews.client.socket", "8888"),
+ "koPort=" + sv.prefs.getString("sciviews.server.socket", "7052"),
+ "koDebug=" + String(sv.socket.debug).toUpperCase(),
+ "koAppFile=" + sv.tools.file.path("binDir", "komodo" + (isWin? ".exe" : ""))
+ ];
+ var runIn = "no-console";
+
+ env.push("Rid=" + id);
+
+ switch (id) {
+ case "r-tk":
env.push("Rid=R-tk");
// Set DISPLAY only when not set:
var XEnv = Components.classes["@activestate.com/koEnviron;1"]
.createInstance(Components.interfaces.koIEnviron);
- if (!XEnv.has("DISPLAY")) env.push("DISPLAY=:0");
+ if (!XEnv.has("DISPLAY")) env.push("DISPLAY=:0");
delete(XEnv);
break;
- case "r-terminal":
+ case "r-terminal":
runIn = "new-console";
break;
- default:
- }
-
- ko.run.runCommand(window, cmd, cwd, env.join("\n"), false,
- false, false, runIn, false, false, false);
-
- // Register observer of application termination.
- this.rObserver = new AppTerminateObserver(cmd);
+ default:
}
+ ko.run.runCommand(window, cmd, cwd, env.join("\n"), false,
+ false, false, runIn, false, false, false);
+
+ // Register observer of application termination.
+ this.rObserver = new AppTerminateObserver(cmd);
+}
+
// This will observe status message notification to be informed about
// application being terminated. A more straightforward way would be to use
// runService.RunAndNotify but this wouldn't allow to start app in a console
@@ -220,6 +187,7 @@
this.command = command;
observerSvc.addObserver(this, 'status_message', false);
sv.log.debug("R has been started with command: " + command);
+
// Sending commands to R does not seem to work, I think it is
// too early, R is still starting. This should be in .Rprofile
//sv.socket.rUpdate();
@@ -244,13 +212,21 @@
this.updateRStatus = function (running) {
running = !!running;
- if (running != sv.r.running) {
- sv.r.running = !!running;
+ // Toggle status if no argument
+ if(typeof running == "undefined")
+ running = !sv.r.running;
+ else
+ running = true;
+ //running = !!running; // ensure it is boolean
+
+ if (running != sv.r.running) {
+ sv.r.running = running;
+ //sv.r.running = running;
//xtk.domutils.fireEvent(window, 'r_app_started_closed');
// PhG: these events are disabled for now, because menus are
// sometimes disabled when they shouldn't be!!! Very ennoying!
//window.updateCommands('r_app_started_closed');
- sv.log.debug("R status updated: " + (running ? "" : "not ") + "running");
+ //sv.cmdout.message("R status: " + (running? "" : "not ") + "running" );
}
}
@@ -267,8 +243,8 @@
return(win);
}
- // sv.command.openHelp - returns reference to the RHelpWindow
- //FIXME: help in tab still buggy
+// sv.command.openHelp - returns reference to the RHelpWindow
+//FIXME: help in tab still buggy
this.openHelp = function (uri) {
var RHelpWin = _this.RHelpWin;
@@ -300,7 +276,7 @@
// Open R-help in a right tab
if (rhelpTabbed) {
- // make sure tab is visible and select it
+ // Make sure tab is visible and select it
var tabPanel = document.getElementById("rhelpviewbox");
var tab = document.getElementById("rhelp_tab");
var tabBox = tabPanel.parentNode.parentNode;
@@ -339,7 +315,7 @@
}
// Close r-help tab
- this.closeHelp = function () {
+ this.closeHelp = function() {
var tabPanel = document.getElementById("rhelpviewbox");
var tab = document.getElementById("rhelp_tab");
var tabBox = tabPanel.parentNode.parentNode;
@@ -350,6 +326,7 @@
tabBox.tabs.itemCount) - 1;
document.getElementById("rhelpview-frame")
.setAttribute("src", "about:blank");
+
//_this.RHelpWin.closed = true;
}
@@ -361,81 +338,105 @@
const XRRunning = 1, XRStopped = 2, XisRDoc = 4, XHasSelection = 8;
var handlers = {
- 'cmd_svOpenPkgManager': ["sv.command.openPkgManager();", XRRunning],
- 'cmd_svBrowseWD': ['sv.r.setwd(\'current\', true);', XRRunning],
- 'cmd_svQuitR': ['sv.r.quit();', XRRunning],
- 'cmd_svOpenHelp': ["sv.command.openHelp();", XRRunning],
- 'cmd_svSessionMgr': ["sv.command.openSessionMgr();", XRRunning],
- 'cmd_svStartR': ['sv.command.startR();', XRStopped],
- 'cmd_svUpdateRInfo': ['sv.socket.rUpdate();', XRRunning],
- 'cmd_svRRunAll': ['sv.r.send("all");', XisRDoc | XRRunning],
- 'cmd_svRSourceAll': ['sv.r.source("all");', XisRDoc | XRRunning],
- 'cmd_svRRunBlock': ['sv.r.send("block");', XisRDoc | XRRunning],
- 'cmd_svRRunFunction': ['sv.r.send("function");', XisRDoc | XRRunning],
- 'cmd_svRRunLine': ['sv.r.send("line");', XisRDoc | XRRunning],
- 'cmd_svRRunPara': ['sv.r.send("para");', XisRDoc | XRRunning],
- 'cmd_svRSourceBlock': ['sv.r.source("block");', XisRDoc | XRRunning],
- 'cmd_svRSourceFunction': ['sv.r.source("function");', XisRDoc | XRRunning],
- 'cmd_svRSourcePara': ['sv.r.source("para");', XisRDoc | XRRunning],
+ 'cmd_svOpenPkgManager': [ "sv.command.openPkgManager();", XRRunning ],
+ 'cmd_svBrowseWD': [ 'sv.r.setwd(\'current\', true);', XRRunning ],
+ 'cmd_svQuitR': [ 'sv.r.quit();', XRRunning ],
+ 'cmd_svOpenHelp': [ "sv.command.openHelp();", XRRunning ],
+ 'cmd_svSessionMgr': [ "sv.command.openSessionMgr();", XRRunning ],
+ 'cmd_svStartR': [ 'sv.command.startR();', 0 ], // XRStopped
+ 'cmd_svREscape': [ 'sv.r.escape();', XRRunning ],
+ // 'cmd_svUpdateRInfo': ['sv.socket.rUpdate();', XRRunning],
+ 'cmd_svRRunAll': [ 'sv.r.send("all");',XisRDoc | XRRunning ],
+ 'cmd_svRSourceAll': [ 'sv.r.source("all");',XisRDoc | XRRunning ],
+ 'cmd_svRRunBlock': [ 'sv.r.send("block");',XisRDoc | XRRunning ],
+ 'cmd_svRRunFunction': [ 'sv.r.send("function");',XisRDoc | XRRunning ],
+ 'cmd_svRRunLine': [ 'sv.r.send("line");',XisRDoc | XRRunning ],
+ 'cmd_svRRunPara': [ 'sv.r.send("para");',XisRDoc | XRRunning ],
+ 'cmd_svRSourceBlock': [ 'sv.r.source("block");',XisRDoc | XRRunning ],
+ 'cmd_svRSourceFunction': [ 'sv.r.source("function");',XisRDoc | XRRunning ],
+ 'cmd_svRSourcePara': [ 'sv.r.source("para");',XisRDoc | XRRunning ],
// PhG: this should really be sv.r.run(), which is supposed to be "more
// intelligent" and can be used to run code step by step because it
// moves the cursor to the next line each time...
- 'cmd_svRRunLineOrSelection': ['sv.r.run();', XisRDoc | XRRunning],
- 'cmd_svRSourceLineOrSelection': ['sv.r.source("line/sel");', XisRDoc | XRRunning],
- 'cmd_svRRunSelection': ['sv.r.send("sel");', XisRDoc | XRRunning | XHasSelection],
- 'cmd_svRSourceSelection': ['sv.r.source("sel");', XisRDoc | XRRunning | XHasSelection]
+ 'cmd_svRRunLineOrSelection': [ 'sv.r.run();', XisRDoc | XRRunning ],
+ 'cmd_svRSourceLineOrSelection': [ 'sv.r.source("line/sel");',XisRDoc | XRRunning ],
+ 'cmd_svRRunSelection': [ 'sv.r.send("sel");',XisRDoc | XRRunning | XHasSelection ],
+ 'cmd_svRSourceSelection': [ 'sv.r.source("sel");', XisRDoc | XRRunning | XHasSelection ],
+ 'cmd_viewrtoolbar': [ 'ko.uilayout.toggleToolbarVisibility(\'RToolbar\')', 0 ]
}
// Temporary
function _isRRunning () {
- return(true);
+ return true;
+
}
-
+
function _isRCurLanguage () {
var view = ko.views.manager.currentView;
- if (!view || !view.document) return(false);
- return(view.document.language == "R");
+ if (!view || !view.document)
+ return false;
+ return(view.document.language == 'R');
+/*
+// This would be useful if Komodo had event for language change at cursor position,
+// and lexers allowed for R as sub-language
+ if (!view || !view.koDoc || !view.scimoz)
+ return (false);
+ var lang = view.koDoc.languageForPosition(view.scimoz.currentPos);
+ return(lang == 'R');
+*/
}
-
+
function _hasSelection () {
var view = ko.views.manager.currentView;
if (!view || !view.scimoz) return(false);
- return((view.scimoz.selectionEnd - view.scimoz.selectionStart) != 0);
+
+ return ((view.scimoz.selectionEnd - view.scimoz.selectionStart) != 0);
}
function svController() {}
-
- svController.prototype = new Controller();
-
- svController.prototype.constructor = svController;
-
- svController.prototype.destructor = function () { }
-
- svController.prototype.isCommandEnabled = function (command) {
+
+ svController.prototype = new Controller();
+
+ svController.prototype.constructor = svController;
+
+ svController.prototype.destructor = function() { }
+
+ svController.prototype.isCommandEnabled = function(command) {
if(!command in handlers) return(false);
+ // TODO: Clean up the mess here.
+ return(true);
- var test = handlers[command][1];
+ //var test = handlers[command][1];
// PhG: since _isRRunning() returns always true, we are currently
// NOT able to start R!
- return((((test & XRRunning) != XRRunning) || true) //_isRRunning())
- && (((test & XRStopped) != XRStopped) || true) //!_isRRunning())
- // PhG: it is NOT the program, but the user who decides when it possible
- // to send a command to R... There are possibles situations where
- // executable R code live somewhere else than in a .R document
- // Let's think at examples in .Rd files, <code R> sections in a
- // wiki page, etc.
- // Thus, for the nth time, I don't want this restriction on commands
- // running code to R: I want them available EVERYWHERE!
- && (((test & XisRDoc) != XisRDoc) || true) //_isRCurLanguage())
- && (((test & XHasSelection) != XHasSelection) || _hasSelection()));
+ // KB: Yes, but startR is enabled by on Komodo load and event "r_app_started_closed"
+ // is never fired.
+ //return (((test & XRRunning) != XRRunning) || _isRRunning())
+ //&& (((test & XRStopped) != XRStopped) || !_isRRunning())
+ // PhG: it is NOT the program, but the user who decides when it possible
+ // to send a command to R... There are possibles situations where
+ // executable R code live somewhere else than in a .R document
+ // Let's think at examples in .Rd files, <code R> sections in a
+ // wiki page, etc.
+ // Thus, for the nth time, I don't want this restriction on commands
+ // running code to R: I want them available EVERYWHERE!
+
+ // KB: the reasons for that were: (1) I do not like feeding R with lots of text pressing an F-key accidentally
+ // (2) I want to use e.g. F5 for running currently active code in an appropriate interpreter (like in SciTe),
+ // Unfortunately, Komodo does not allow for defining multiple commands for a single key combination
+ //&& (((test & XisRDoc) != XisRDoc) || true) //_isRCurLanguage())
+ //&& (((test & XisRDoc) != XisRDoc) || _isRCurLanguage())
+ // && (((test & XHasSelection) != XHasSelection) || _hasSelection());
+ // && (((test & XHasSelection) != XHasSelection) || _hasSelection()));
+//
+ //return true;
}
- svController.prototype.supportsCommand = svController.prototype
- .isCommandEnabled;
+ svController.prototype.supportsCommand = svController.prototype.isCommandEnabled;
- svController.prototype.doCommand = function (command) {
+ svController.prototype.doCommand = function(command) {
if (command in handlers) return(eval(handlers[command][0]));
- return(false);
+ return (false);
}
window.controllers.appendController(new svController());
@@ -449,13 +450,13 @@
//
// var ids = ["editor-context-sep-sv", "editor-context-sv-r-send-line-sel"];
//
-// var langNotR = ko.views.manager.currentView.document.language != "R";
-// var visibility = langNotR ? "collapse" : "visible";
+// var langNotR = ko.views.manager.currentView.koDoc.language != "R";
+// var visibility = langNotR? "collapse" : "visible";
///*
// for (i in ids)
// document.getElementById(ids[i]).style.visibility = visibility;
//*/
-// //} catch(e) { }
+// //} catch(e) {}
//
// }
//var editorContextMenu = document.getElementById("editorContextMenu");
@@ -469,7 +470,7 @@
.classes["@activestate.com/koKeybindingSchemeService;1"]
.getService(Components.interfaces.koIKeybindingSchemeService);
- //TODO: use of gKeybindingMgr could simplify this code
+//TODO: use of gKeybindingMgr could simplify this code
//gKeybindingMgr.keybindingSchemeService
var svSchemeDefault = sv.tools.file
Modified: komodo/SciViews-K/content/js/misc.js
===================================================================
--- komodo/SciViews-K/content/js/misc.js 2010-10-04 09:46:50 UTC (rev 325)
+++ komodo/SciViews-K/content/js/misc.js 2010-10-04 14:26:51 UTC (rev 326)
@@ -405,7 +405,7 @@
var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"].
getService(Components.interfaces.nsIClipboardHelper);
try {
- var path = ko.views.manager.currentView.document.file.path;
+ var path = ko.views.manager.currentView.koDoc.file.path;
if (unix) path = path.replace(/\\/g, "/");
ch.copyString(path);
} catch(e) {
Modified: komodo/SciViews-K/content/js/pref-R.js
===================================================================
--- komodo/SciViews-K/content/js/pref-R.js 2010-10-04 09:46:50 UTC (rev 325)
+++ komodo/SciViews-K/content/js/pref-R.js 2010-10-04 14:26:51 UTC (rev 326)
@@ -1,12 +1,11 @@
// SciViews-K R preferences panel functions
-// Copyright (c) 2009-2010, Ph. Grosjean (phgrosjean at sciviews.org) & Kamil Barton
+// Copyright (c) 2009, Ph. Grosjean (phgrosjean at sciviews.org) & Kamil Barton
// License: MPL 1.1/GPL 2.0/LGPL 2.1
////////////////////////////////////////////////////////////////////////////////
// svPrefR_OnPreferencePageOK(prefset); // User click OK
// PrefR_OnLoad(); // R preference widow loaded
-// svPrefR_loadRExecutable(); // Select R executable
-// svPrefR_finishSpecifyingExecutable(path); // Set R executable
-////////////////////////////////////////////////////////////////////////////////
+// TODO: update this list...
+//////////////////////////////////////////////////////////////////////////////
//
// TODO: use 'R' simply as default R (terminal on Win/Mac, or on Linux)
@@ -16,15 +15,13 @@
* R Site search url (%S replaced by topic)
*/
-// TODO: rework R applications list, include "Find in path" item, similar to other
-// languages' interpeters in Komodo. Add new function to find installed R's and
-// populate the interpreter list (depending on the platform).
var sv;
-// For editable menulists: append new element if necessary
-function editMenulist(el) {
- var curValue = sv.tools.strings.trim(el.value);
+// For menulists, take the value argument/(or text in the textbox), and append
+// it as new element to the list if it is new, otherwise set as selected
+function editMenulist(el, value) {
+ var curValue = (!value)? sv.tools.strings.trim(el.value) : value;
if (!curValue) return;
var values = [], val;
for (var j = 0; j < el.itemCount; j++) {
@@ -42,13 +39,14 @@
function menuListSetValues(attribute) {
if (!attribute) attribute = 'values';
var ml = document.getElementsByTagName('menulist');
- var el, values;
+ var el, values, v;
for (var i = 0; i < ml.length; i++) {
el = ml[i];
if (el.hasAttribute(attribute)) {
values = el.getAttribute(attribute).split(/\s+/);
for (var k in values) {
- el.appendItem(values[k], values[k], null);
+ v = unescape(values[k]);
+ el.appendItem(v, v, null);
}
}
}
@@ -63,20 +61,22 @@
el = ml[i];
if (el.hasAttribute(attribute)) {
values = [];
- for (var k = 0; k < el.itemCount; k++)
- values.push(el.getItemAtIndex(k).value);
+ for (var k = 0; k < el.itemCount; k++) {
+ values.push(escape(el.getItemAtIndex(k).value));
+ }
el.setAttribute(attribute, values.join(" "));
}
}
}
-function PrefR_menulistSetValue(menuList, value, attr, vdefault) {
+function PrefR_menulistSetValue(menuList, value, attrName, vdefault) {
var n = menuList.itemCount;
var item;
for (var i = 0; i <= n; i++) {
item = menuList.getItemAtIndex(i);
if (item) {
- var attr1 = item.hasAttribute(attr)? item.getAttribute(attr) : vdefault;
+ var attr1 = item.hasAttribute(attrName)? item.getAttribute(attrName)
+ : vdefault;
if (attr1 == value) {
menuList.selectedIndex = i;
break;
@@ -85,54 +85,146 @@
}
}
+// List of R applications
+var apps = [
+{ id:"r-terminal", label:"in default terminal", path:"\"%Path%\" %args%",
+ app:"R", required:"R", platform:"Lin,Mac"},
+{id:"r-terminal", label:"in console window", path:"\"%Path%\" %args%",
+ app:"R.exe", required:"R", platform:"Win"},
+{id:"r-gnome-term", label:"in Gnome terminal",
+ path:"gnome-terminal --hide-menubar --working-directory='%cwd%' -t '%title%' -x '%Path%' %args%",
+ app:"R", required:"gnome-terminal,R", platform:"Lin"},
+{id:"r-kde-term", label:"in Konsole", app:"R",
+ path:"konsole --workdir '%cwd%' --title %title% -e \"%Path%\" %args%",
+ required:"konsole,R", platform:"Lin"},
+{id:"r-xfce4-term", label:"in XFCE terminal", app:"R",
+ path:"xfce4-terminal --title \"%title%\" -x \"%Path%\" %args%",
+ required:"xfce4-terminal,R", platform:"Lin"},
+{id:"r-app", label:"R app", path:"open -a \"%Path%\" \"%cwd%\"",
+ app:"R.app",
+ required:"/Applications/R.app", platform:"Mac"},
+{id:"r64-app", label:"R64 app", path:"open -a \"%Path%\" \"%cwd%\"",
+ app:"R64.app",
+ required:"/Applications/R64.app", platform:"Mac"},
+{id:"svr-app", label:"SciViews R app", path:"open -a \"%Path%\" \"%cwd%\"",
+ app:"SciViews R.app",
+ required:"/Applications/SciViews R.app", platform: "Mac"},
+{id:"svr64-app", label:"SciViews R64 app", path:"open -a \"%Path%\" \"%cwd%\"",
+ app:"SciViews R64.app",
+ required:"/Applications/SciViews R64.app", platform:"Mac"},
+{id:"r-gui", label:"R GUI", app:"Rgui.exe", path:"\"%Path%\" --sdi %args%",
+ required:"Rgui",
+ platform:"Win"},
+{id:"r-tk", label:"R Tk GUI", path:"\"%Path%\" --interactive --gui:Tk %args%",
+ app:"R", required:"R", platform:"Lin,Mac"}
+];
+
+
function PrefR_OnLoad() {
// Get the sv object:
var p = parent;
while (p.opener && (p = p.opener) && !sv) if (p.sv) sv = p.sv;
+ //p = parent;
+ //while (p.opener && (p = p.opener) && !ko) if (p.ko) ko = p.ko;
var os = Components.classes['@activestate.com/koOs;1']
- .getService(Components.interfaces.koIOs);
+ .getService(Components.interfaces.koIOs);
var prefExecutable;
var prefset = parent.hPrefWindow.prefset;
var prefName = 'svRDefaultInterpreter';
- document.getElementById("svRQuiet")
- .setAttribute("checked", sv.prefs.getString("svRQuiet"));
- if (!prefset.hasStringPref(prefName) || !prefset.getStringPref(prefName)) {
- prefExecutable = sv.tools.file.whereIs("R");
- prefset.setStringPref(prefName, prefExecutable);
- }
- prefExecutable = sv.prefs.getString("svRDefaultInterpreter")
- PrefR_setRAppMenu(document.getElementById("svRApplication"));
- PrefR_menulistSetValue(document.getElementById("svRApplication"),
- os.path.basename(prefExecutable), "app", "R");
- document.getElementById("svRDefaultInterpreter").value = prefExecutable;
+ var menu = document.getElementById("svRApplication");
+ menu.removeAllItems();
- if (!PrefR_UpdateCranMirrors(true)) PrefR_UpdateCranMirrors(false);
+ var platform = navigator.platform.substr(0,3);
- menuListSetValues();
- sv.prefs.checkAll();
- PrefR_svRApplicationUpdate(null);
+ var tmp = {}, required, res;
+ for (var i in apps)
+ if (apps[i].platform.split(',').indexOf(platform) != -1) {
+ required = apps[i].required.split(',');
+ res = true;
+ for (var k in required)
+ res = res && !!sv.tools.file.whereIs(required[k]);
+ if (res)
+ tmp[apps[i].id] = apps[i];
+ }
+ apps = tmp;
+
+ for (var i in apps)
+ menu.appendItem(apps[i].label, i, null);
+
+ // update cran mirror list (first local, then tries remote at CRAN)
+ if (!PrefR_UpdateCranMirrors(true))
+ PrefR_UpdateCranMirrors(false);
+
+ menuListSetValues(); // Restores saved menu values
+ sv.prefs.checkAll(); // Check if all preference values are ok, if not, restore defaults
+ PrefR_PopulateRInterps();
parent.hPrefWindow.onpageload();
+ PrefR_updateCommandLine(true);
}
+
+//TODO: check if there is new R version installed and ask whether to switch to it.
+function PrefR_PopulateRInterps() {
+
+ var prefExecutable = sv.prefs.getString('svRDefaultInterpreter');
+ var rs = new Array();
+ var os = Components.classes['@activestate.com/koOs;1']
+ .getService(Components.interfaces.koIOs);
+ var menu = document.getElementById("svRDefaultInterpreter");
+
+ // windows:
+ ////////////////////////////////////
+ switch (os.name) { //'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos'.
+ case "nt":
+ rs = rs.concat(sv.tools.file.whereIs("Rgui"));
+ rs = rs.concat(sv.tools.file.whereIs("R"));
+ break;
+ case "mac":
+ //FIXME: as I understand there are only 2 options on Mac, is it right?:
+ rs = ["/Applications/R.app", "/Applications/R64.app"];
+ // What about "SciViews R*.app" ???
+ break;
+ case "posix":
+ default:
+ rs = rs.concat(sv.tools.file.whereIs("R"));
+ }
+ rs.unshift(prefExecutable);
+
+ for (var i in rs) {
+ rs[i] = os.path.normpath(rs[i]);
+ if (sv.tools.file.exists(rs[i]) == sv.tools.file.TYPE_NONE) {
+ rs.splice(i, 1);
+ }
+ }
+
+ rs = sv.tools.array.unique(rs); // Get rid of duplicates
+ menu.removeAllItems();
+ for (var i in rs) {
+ menu.appendItem(rs[i], rs[i], null);
+ }
+
+ if (rs.length > 0) {
+ document.getElementById("no-avail-interps-message").hidden = true;
+ }
+
+}
+
function OnPreferencePageLoading(prefset) {
- //PrefR_svRApplicationOnSelect(null);
}
function OnPreferencePageOK(prefset) {
prefset = parent.hPrefWindow.prefset;
prefset.setStringPref("svRDefaultInterpreter",
- document.getElementById("svRDefaultInterpreter").value);
+ document.getElementById("svRDefaultInterpreter").value);
prefset.setStringPref("svRApplication",
- document.getElementById('svRApplication')
- .selectedItem.getAttribute("value"));
+ document.getElementById('svRApplication')
+ .selectedItem.getAttribute("value"));
prefset.setStringPref("svRApplicationId",
- document.getElementById('svRApplication').selectedItem.id);
- prefset.setStringPref("svRQuiet",
- document.getElementById('svRQuiet')
- .getAttribute("checked") == "true");
+ document.getElementById('svRApplication').selectedItem.id);
+
var outDec = document.getElementById('r.csv.dec').value;
var outSep = document.getElementById('r.csv.sep').value;
@@ -142,158 +234,134 @@
if (outDec == outSep) {
parent.switchToPanel("svPrefRItem");
ko.dialogs.alert(
- "Decimal separator cannot be the same as field separator.", null,
- "SciViews-K preferences");
+ "Decimal separator cannot be the same as field separator.", null,
+ "SciViews-K preferences");
return(false);
}
//The 'r.csv.*.arg' prefs are replaced by simply 'r.csv.dec'/'r.csv.sep'
//as they escaped strings anyway (e.g. string "\\t" not tab character)
- if (sv.r.running)
- sv.r.eval('options(OutDec = "' + outDec + '", ' +
- 'OutSep = "' + outSep + '")');
+ if (sv.r.running) {
+ sv.r.eval('options(OutDec="' + outDec + '", ' +
+ 'OutSep="' + outSep + '")', true);
+ }
menuListGetValues();
+
+ // Restart socket server if running and port changed
+ var serverPort = document.getElementById('sciviews.server.socket').value;
+ if(sv.socket.serverIsStarted &&
+ serverPort != prefset.getStringPref("sciviews.server.socket")){
+ prefset.setStringPref("sciviews.server.socket", serverPort);
+ sv.socket.serverStart();
+ }
+
+
+
+
+
+
+
return(true);
}
-function PrefR_svRApplicationOnSelect(event) {
- var el = document.getElementById("svRApplication");
- var sel = el.selectedItem;
- var app = sel.hasAttribute("app")? sel.getAttribute("app") : "R";
- // PhG: always get a good starting value - DO NOT ELIMINATE THIS!
- var svRDefaultInterpreter = PrefR_locateApp(app);
- document.getElementById("svRDefaultInterpreter").value
- = svRDefaultInterpreter;
-
- // Delegate to PrefR_svRApplicationUpdate()
- return(PrefR_svRApplicationUpdate(event));
+function svRDefaultInterpreterOnSelect(event) {
+ var os = Components.classes['@activestate.com/koOs;1']
+ .getService(Components.interfaces.koIOs);
+
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/sciviews -r 326
More information about the Sciviews-commits
mailing list