[Sciviews-commits] r130 - in komodo/SciViews-K/content: . js
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue May 19 18:46:53 CEST 2009
Author: prezez
Date: 2009-05-19 18:46:52 +0200 (Tue, 19 May 2009)
New Revision: 130
Modified:
komodo/SciViews-K/content/RBrowserOverlay.xul
komodo/SciViews-K/content/js/commands.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/overlay.xul
komodo/SciViews-K/content/overlayMain.xul
Log:
added: global debugging flag: sv.debug and sv.debugMsg function (to be removed in final version).
object browser improvements: names are inserted in order they were selected; when items are removed, selection is now cleared.
added: observer of 'application terminated' event - detects when R quits (buggy, not always).
'preferred r application' menu: on Linux, only available terminals are listed.
Modified: komodo/SciViews-K/content/RBrowserOverlay.xul
===================================================================
--- komodo/SciViews-K/content/RBrowserOverlay.xul 2009-05-15 13:11:59 UTC (rev 129)
+++ komodo/SciViews-K/content/RBrowserOverlay.xul 2009-05-19 16:46:52 UTC (rev 130)
@@ -297,8 +297,8 @@
<tree flex="1" id="sciviews_robjects_objects_tree"
persist="sortDirection sortResource"
sortDirection="ascending" sortResource="r-name"
- enableColumnDrag="true"
- onkeypress = "rObjectsTree.onEvent(event);"
+ enableColumnDrag="true"
+ onkeyup = "rObjectsTree.onEvent(event);"
>
<treecols>
<treecol
@@ -339,6 +339,7 @@
</treecols>
<treechildren id="sciviews_robjects_objects_tree_main"
ondraggesture="nsDragAndDrop.startDrag(event, rObjectsTree.listObserver);"
+ onclick="rObjectsTree.onEvent(event);"
ondblclick="rObjectsTree.onEvent(event);"
context="rObjectsContext"
>
Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js 2009-05-15 13:11:59 UTC (rev 129)
+++ komodo/SciViews-K/content/js/commands.js 2009-05-19 16:46:52 UTC (rev 130)
@@ -1,230 +1,335 @@
-/*
-
-Controllers for R related commands.
-
-*/
-
-
-if (typeof(sv.command) == 'undefined') {
- sv.command = {};
-}
-
-
-// sv.cmd object constructor:
-(function() {
-
-// private methods:
-function _RControl_supported() {
- var currentView = ko.views.manager.currentView;
- if (!currentView || !currentView.document)
- return false;
-
- return(currentView.document.language == "R");
-}
-
-function _RControlSelection_supported() {
- var currentView = ko.views.manager.currentView;
- if (!currentView || !currentView.scimoz)
- return false;
-
- var anythingSelected = (currentView.scimoz.selectionEnd - currentView.scimoz.selectionStart) != 0;
- return(currentView.document.language == "R" && anythingSelected);
-}
-
-
-// selects the checkbox on selected element, while deselecting others
-this.getRApp = function(event) {
- var el = event.originalTarget;
- var siblings = el.parentNode.childNodes;
- for (var i = 0; i < siblings.length; i++) {
- try {
- siblings[i].setAttribute("checked", siblings[i] == el);
- } catch(e) {}
- }
- // this will preserve the selection:
- el.parentNode.setAttribute('selected', el.id);
- // set the preference string:
- sv.prefs.setString("sciviews.preferredRApp", el.id, true);
-
- document.getElementById("cmd_svStartR").setAttribute("label",
- sv.translate("StartR") + " (" + el.getAttribute('label') + ")");
-
-}
-
-
-// Selects checkbox on the 'preferred R application' menu on its first display
-// and hides unsupported commands
-// It is triggered on popupshowing event, onload would be better,
-// but it is for compatibility with komodo 4 which doesn't seem to support onload
-this.setMenuRApp = function (el) {
- var selected = el.getAttribute('selected');
- var siblings = el.childNodes;
-
- 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*/);
- showItem = false;
- for (var j in validPlatforms) {
- if (platform.indexOf(validPlatforms[j]) == 0) {
- showItem = true;
- break;
- }}
-
- if (!showItem) {
- siblings[i].style.display = "none";
- } else {
- siblings[i].setAttribute("checked", siblings[i].id == selected);
- }
-
- } catch(e) {}
- }
-
- // set the preference string:
- sv.prefs.setString("sciviews.preferredRApp", selected, false);
-
- document.getElementById("cmd_svStartR").setAttribute("label",
- sv.translate("StartR") + " (" + document.getElementById(selected).getAttribute('label') + ")"
- );
-
- // we do not need to run it anymore:
- el.removeAttribute("onpopupshowing");
-}
-
-this.openPkgManager = function() {
- window.openDialog(
- "chrome://sciviewsk/content/pkgManager.xul",
- "RPackageManager",
- "chrome=yes,dependent,centerscreen,resizable=yes,scrollbars=yes,status=no",
- sv);
-}
-
-
-this.setControllers = function() {
- // make these commands active only when current document language is R
- var cmdNames = ["RunAll", "SourceAll", "RunBlock", "RunFunction", "RunLine", "RunPara",
- "SourceBlock", "SourceFunction", "SourcePara"];
-
- var viewManager = ko.views.viewManager;
- for (i in cmdNames) {
- viewManager.prototype["is_cmd_sv_R" + cmdNames[i] + "_supported"] = _RControl_supported;
- viewManager.prototype["is_cmd_sv_R" + cmdNames[i] + "_enabled"] = _RControl_supported;
- }
-
- // make these commands active only when current document language is R
- // ... and if some text is selected
- cmdNames = [ "RunSelection", "SourceSelection"];
- for (i in cmdNames) {
- viewManager.prototype["is_cmd_sv_R" + cmdNames[i] + "_supported"] = _RControlSelection_supported;
- viewManager.prototype["is_cmd_sv_R" + cmdNames[i] + "_enabled"] = _RControlSelection_supported;
- }
-
- viewManager.prototype.do_cmd_sv_RRunLine = function() { sv.r.send("line"); };
-
- viewManager.prototype.do_cmd_sv_RRunAll = function() { sv.r.send("all"); };
- viewManager.prototype.do_cmd_sv_RSourceAll = function() { sv.r.source("all"); };
-
- viewManager.prototype.do_cmd_sv_RSourcePara = function() { sv.r.source("para"); };
- viewManager.prototype.do_cmd_sv_RRunPara = function() { sv.r.send("para"); };
-
- viewManager.prototype.do_cmd_sv_RRunSelection = function() { sv.r.send("sel"); };
- viewManager.prototype.do_cmd_sv_RSourceSelection = function() { sv.r.source("sel"); };
-
- viewManager.prototype.do_cmd_sv_RRunBlock = function() { sv.r.send("block"); };
- viewManager.prototype.do_cmd_sv_RSourceBlock = function() { sv.r.source("block"); };
-
- viewManager.prototype.do_cmd_sv_RRunFunction = function() { sv.r.send("function"); };
- viewManager.prototype.do_cmd_sv_RSourceFunction = function() { sv.r.source("function"); };
-
-
- viewManager.prototype.do_cmd_svStartR = function() {
- // runIn = "command-output-window", "new-console",
- //env strings: "ENV1=fooJ\nENV2=bar"
- //gPrefSvc.prefs.getStringPref("runEnv");
-
- var isWin = navigator.platform == "Win32";
- var preferredRApp = sv.prefs.getString("sciviews.preferredRApp", "r-terminal");
-
- var env = ["koId=" + sv.prefs.getString("sciviews.client.id", "SciViewsK"),
- "koHost=localhost",
- "koActivate=FALSE",
- "Rinitdir=" + sv.io.makePath(isWin? "Pers" : "Home"),
- "koServe=" + sv.prefs.getString("sciviews.client.socket", "8888"),
- "koPort=" + sv.prefs.getString("sciviews.server.socket", "7052"),
- "koAppFile=" + sv.io.makePath("CurProcD", ["komodo" + (isWin? ".exe" : "")])
- ];
-
- var cwd = sv.io.makePath("ProfD", ["extensions", "sciviewsk at sciviews.org", "templates"]);
-
- var command, mode = "no-console";
-
- switch (preferredRApp) {
- case "r-gui":
- env.push("Rid=Rgui");
- command = "Rgui --sdi";
- break;
- case "r-xfce4-term":
- env.push("Rid=R-xfce4-term");
- command = "xfce4-terminal --title \"R\" -x R --quiet";
- break;
- case "r-gnome-term":
- env.push("Rid=R-gnome-term");
- command = "gnome-terminal --hide-menubar --title=SciViews-R -x R --quiet";
- break;
- case "r-kde-term":
- env.push("Rid=R-kde-term");
- command = "konsole --nomenubar --notabbar --noframe -T SciViews-R -e R --quiet";
- break;
- case "r-tk":
- env.push("Rid=R-tk");
- env.push("DISPLAY=:0");
- command = "R --quiet --gui=Tk";
- mode = "new-console";
- break;
- case "r-app":
- env.push("Rid=R.app");
- command = "open -a /Applications/R.app \"" + cwd + "\"";
- break;
- default:
- env.push("Rid=R");
- command = "R --quiet";
- mode = "new-console";
-
- }
-
- ko.run.runCommand(window, command, cwd, env.join("\n"), false,
- false, false, mode, false, false, false);
- };
-}
-
-}).apply(sv.command);
-
-
-//sv.command.setControllers();
-addEventListener("load", sv.command.setControllers, false);
-
-/*
-
-//Useful garbage. delete it later.
-
-// command controllers template:
-vm.prototype.is_cmd_Test_supported
-vm.prototype.do_cmd_Test = function() { alert("do_cmd_Test!"); }
-vm.prototype.is_cmd_Test_supported = function() {
- alert("is_cmd_Test_supported?:" + ko.views.manager.currentView.document.language);
- return(ko.views.manager.currentView.document.language == "R");
-}
-vm.prototype.is_cmd_Test_enabled = function() { alert("is_cmd_Test_enabled?"); return false; }
-
-//commands sohuld be put in a commandset, so they can be enabled only if lang = R
-document.getElementById("cmdset_view_or_language_changed")
-
-select,current_view_changed,language_changed
-var x = document.getElementById("cmdset_r_control")
-x.oncommandupdate = function oncommandupdate(event) { ko.commands.updateCommandset(this); sv.cmdout.append(ko.views.manager.currentView.document.language) }
-
-id="cmdset_r_control"
-current_view_language_changed
-
-*/
+/*
+
+Controllers for R related commands.
+
+*/
+
+
+if (typeof(sv.command) == 'undefined') {
+ sv.command = {};
+}
+
+
+// sv.cmd object constructor:
+(function() {
+
+var isRRunning = false;
+
+// private methods:
+function _RControl_supported() {
+ var currentView = ko.views.manager.currentView;
+ if (!currentView || !currentView.document)
+ return false;
+
+ return(currentView.document.language == "R");
+}
+
+
+function _isRRunning() {
+ //sv.cmdout.append("is R Running? " + isRRunning);
+ return isRRunning;
+}
+
+function _RControlSelection_supported() {
+ var currentView = ko.views.manager.currentView;
+ if (!currentView || !currentView.scimoz)
+ return false;
+
+ var anythingSelected = (currentView.scimoz.selectionEnd - currentView.scimoz.selectionStart) != 0;
+ return(currentView.document.language == "R" && anythingSelected);
+}
+
+// selects the checkbox on selected element, while deselecting others
+this.getRApp = function(event) {
+ var el = event.originalTarget;
+ var siblings = el.parentNode.childNodes;
+ for (var i = 0; i < siblings.length; i++) {
+ try {
+ siblings[i].setAttribute("checked", siblings[i] == el);
+ } catch(e) {}
+ }
+ // this will preserve the selection:
+ el.parentNode.setAttribute('selected', el.id);
+ // set the preference string:
+ sv.prefs.setString("sciviews.preferredRApp", el.id, true);
+
+ document.getElementById("cmd_svStartR").setAttribute("label",
+ sv.translate("StartR") + " (" + el.getAttribute('label') + ")");
+
+}
+
+// Selects checkbox on the 'preferred R application' menu on its first display
+// and hides unsupported commands
+// It is triggered on popupshowing event, onload would be better,
+// but it is for compatibility with komodo 4 which doesn't seem to support onload
+this.setMenuRApp = function (el) {
+ var selected = el.getAttribute('selected');
+ var siblings = el.childNodes;
+
+ var isLinux = navigator.platform.toLowerCase().indexOf("linux") > -1;
+
+ // this will tell whether an app is present on the *nix system
+ if (isLinux) {
+ 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*/);
+ showItem = false;
+ for (var j in validPlatforms) {
+ if (platform.indexOf(validPlatforms[j]) == 0) {
+ // on linux, try to determine which terminals are not available
+ // and remove these items from menu
+ if (!isLinux || whereis(siblings[i].getAttribute("app"))) {
+ showItem = true;
+ break;
+ }
+ }
+ }
+
+ if (!showItem) {
+ siblings[i].style.display = "none";
+ } else {
+ siblings[i].setAttribute("checked", siblings[i].id == selected);
+ }
+
+ } catch(e) {}
+ }
+
+ // set the preference string:
+ sv.prefs.setString("sciviews.preferredRApp", selected, false);
+
+ document.getElementById("cmd_svStartR").setAttribute("label",
+ sv.translate("StartR") + " (" + document.getElementById(selected).getAttribute('label') + ")"
+ );
+
+ // we do not need to run it anymore:
+ el.removeAttribute("onpopupshowing");
+}
+
+this.openPkgManager = function() {
+ window.openDialog(
+ "chrome://sciviewsk/content/pkgManager.xul",
+ "RPackageManager",
+ "chrome=yes,dependent,centerscreen,resizable=yes,scrollbars=yes,status=no",
+ sv);
+}
+
+// this will observe status message notification. This is to get informed about
+// application being terminated. A more straightforward way would be to use runService.RunAndNotify
+// but, this woldn't allow to start app in a console window. So we have to do this trick here.
+
+
+function AppTerminateObserver(command) {
+ this.register(command);
+}
+
+
+AppTerminateObserver.prototype = {
+ command: "",
+ // this is launched when status message is set, we then check if it was about
+ // terminated application :
+ observe: function(subject, topic, data) {
+ var matches;
+
+ if ((subject.category == "run_command") &&
+ (matches = subject.msg.match(/^(['`"])(.+)\1 returned ([0-9]+).$/)) != null &&
+ matches[2] == this.command
+ ) {
+ // seems like this is a 'R quit' msg
+ this.unregister();
+ // do something here... activate/deactivate commands, stuff like that...
+ }
+ },
+ register: function(command) {
+ var observerSvc = Components.classes["@mozilla.org/observer-service;1"]
+ .getService(Components.interfaces.nsIObserverService);
+ this.command = command;
+ observerSvc.addObserver(this, 'status_message', false);
+ sv.debugMsg("R has been started with command: " + command);
+ isRRunning = true;
+
+ xtk.domutils.fireEvent(window, 'r_app_started_closed');
+ window.updateCommands('r_app_started_closed');
+ },
+ unregister: function() {
+ var observerSvc = Components.classes["@mozilla.org/observer-service;1"]
+ .getService(Components.interfaces.nsIObserverService);
+ observerSvc.removeObserver(this, 'status_message');
+
+ //sv.cmdout.append("debug: R process observer successfully unregistered.");
+ sv.debugMsg("R has been closed. Command was: " + this.command);
+
+ isRRunning = false;
+ xtk.domutils.fireEvent(window, 'r_app_started_closed');
+ window.updateCommands('r_app_started_closed');
+ }
+}
+
+
+
+this.setControllers = function() {
+ //alert("this.setControllers");
+ // allow some commands only whan R is running...
+ // using this needs solving an issue of running R in some terminals on linux (mac?)
+ // that send terminate signal right after start.
+ //viewManager.prototype.is_cmd_svOpenPkgManager_enabled = _isRRunning;
+ //viewManager.prototype.is_cmd_svOpenPkgManager_supported = _isRRunning;
+ //viewManager.prototype.is_cmd_svBrowseWD_enabled = _isRRunning;
+ //viewManager.prototype.is_cmd_svBrowseWD_supported = _isRRunning;
+
+ // make these commands active only when current document language is R
+ var cmdNames = ["RunAll", "SourceAll", "RunBlock", "RunFunction", "RunLine", "RunPara",
+ "SourceBlock", "SourceFunction", "SourcePara"];
+
+ var viewManager = ko.views.viewManager;
+ for (i in cmdNames) {
+ viewManager.prototype["is_cmd_sv_R" + cmdNames[i] + "_supported"] = _RControl_supported;
+ viewManager.prototype["is_cmd_sv_R" + cmdNames[i] + "_enabled"] = _RControl_supported;
+ }
+
+ // make these commands active only when current document language is R
+ // ... and if some text is selected
+ cmdNames = [ "RunSelection", "SourceSelection"];
+ for (i in cmdNames) {
+ viewManager.prototype["is_cmd_sv_R" + cmdNames[i] + "_supported"] = _RControlSelection_supported;
+ viewManager.prototype["is_cmd_sv_R" + cmdNames[i] + "_enabled"] = _RControlSelection_supported;
+ }
+
+ viewManager.prototype.do_cmd_sv_RRunLine = function() { sv.r.send("line"); };
+
+ viewManager.prototype.do_cmd_sv_RRunAll = function() { sv.r.send("all"); };
+ viewManager.prototype.do_cmd_sv_RSourceAll = function() { sv.r.source("all"); };
+
+ viewManager.prototype.do_cmd_sv_RSourcePara = function() { sv.r.source("para"); };
+ viewManager.prototype.do_cmd_sv_RRunPara = function() { sv.r.send("para"); };
+
+ viewManager.prototype.do_cmd_sv_RRunSelection = function() { sv.r.send("sel"); };
+ viewManager.prototype.do_cmd_sv_RSourceSelection = function() { sv.r.source("sel"); };
+
+ viewManager.prototype.do_cmd_sv_RRunBlock = function() { sv.r.send("block"); };
+ viewManager.prototype.do_cmd_sv_RSourceBlock = function() { sv.r.source("block"); };
+
+ viewManager.prototype.do_cmd_sv_RRunFunction = function() { sv.r.send("function"); };
+ viewManager.prototype.do_cmd_sv_RSourceFunction = function() { sv.r.source("function"); };
+
+
+ viewManager.prototype.do_cmd_svStartR = function() {
+ // runIn = "command-output-window", "new-console",
+ //env strings: "ENV1=fooJ\nENV2=bar"
+ //gPrefSvc.prefs.getStringPref("runEnv");
+
+ var isWin = navigator.platform == "Win32";
+ var preferredRApp = sv.prefs.getString("sciviews.preferredRApp", "r-terminal");
+
+ var env = ["koId=" + sv.prefs.getString("sciviews.client.id", "SciViewsK"),
+ "koHost=localhost",
+ "koActivate=FALSE",
+ "Rinitdir=" + sv.io.makePath(isWin? "Pers" : "Home"),
+ "koServe=" + sv.prefs.getString("sciviews.client.socket", "8888"),
+ "koPort=" + sv.prefs.getString("sciviews.server.socket", "7052"),
+ "koAppFile=" + sv.io.makePath("CurProcD", ["komodo" + (isWin? ".exe" : "")])
+ ];
+
+ var cwd = sv.io.makePath("ProfD",
+ ["extensions", "sciviewsk at sciviews.org", "templates"]);
+
+ var command, runIn = "no-console";
+
+ switch (preferredRApp) {
+ case "r-gui":
+ env.push("Rid=Rgui");
+ command = "Rgui --sdi";
+ break;
+ case "r-xfce4-term":
+ env.push("Rid=R-xfce4-term");
+ command = "xfce4-terminal --title \"SciViews-R\" -x R --quiet";
+ break;
+ case "r-gnome-term":
+ env.push("Rid=R-gnome-term");
+ command = "gnome-terminal --hide-menubar --title=SciViews-R -x R --quiet";
+ break;
+ case "r-kde-term":
+ env.push("Rid=R-kde-term");
+ command = "konsole --nomenubar --notabbar --noframe -T SciViews-R -e R --quiet";
+ break;
+ 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");
+ delete XEnv;
+ command = "R --quiet --save --gui=Tk";
+ //runIn = "no-console";
+ break;
+ case "r-app":
+ env.push("Rid=R.app");
+ command = "open -a /Applications/R.app \"" + cwd + "\"";
+ break;
+ default:
+ env.push("Rid=R");
+ command = "R --quiet";
+ runIn = "new-console";
+
+ }
+
+ // debugging garbage...
+ //var command = "CMD /C \"SET\" > c:\\env.txt & notepad c:\\env.txt";
+
+ //ko.run.runCommand(window, "CMD /C \"SET\" > c:\\env.txt & notepad c:\\env.txt", cwd, {});
+ //var runSvc = Components.classes["@activestate.com/koRunService;1"]
+ //.getService(Components.interfaces.koIRunService);
+ //var Rapp = runSvc.RunAndNotify(command, cwd, env.join("\n"), null);
+ //ko.run.runCommand(window, command, cwd, env.join("\n"), false,
+
+ ko.run.runCommand(window, command, cwd, env.join("\n"), false,
+ false, false, runIn, false, false, false);
+
+ // register observer of application termination.
+ this.rObserver = new AppTerminateObserver(command);
+ };
+}
+
+}).apply(sv.command);
+
+
+//sv.command.setControllers();
+addEventListener("load", sv.command.setControllers, false);
+
+/*
+
+//Useful garbage. delete it later.
+
+// command controllers template:
+vm.prototype.is_cmd_Test_supported
+vm.prototype.do_cmd_Test = function() { alert("do_cmd_Test!"); }
+vm.prototype.is_cmd_Test_supported = function() {
+ alert("is_cmd_Test_supported?:" + ko.views.manager.currentView.document.language);
+ return(ko.views.manager.currentView.document.language == "R");
+}
+vm.prototype.is_cmd_Test_enabled = function() { alert("is_cmd_Test_enabled?"); return false; }
+
+//commands sohuld be put in a commandset, so they can be enabled only if lang = R
+document.getElementById("cmdset_view_or_language_changed")
+
+select,current_view_changed,language_changed
+var x = document.getElementById("cmdset_r_control")
+x.oncommandupdate = function oncommandupdate(event) { ko.commands.updateCommandset(this); sv.cmdout.append(ko.views.manager.currentView.document.language) }
+
+id="cmdset_r_control"
+current_view_language_changed
+
+*/
Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js 2009-05-15 13:11:59 UTC (rev 129)
+++ komodo/SciViews-K/content/js/r.js 2009-05-19 16:46:52 UTC (rev 130)
@@ -215,7 +215,7 @@
if (navigator.platform.search(/^Win/) == 0) {
curDir = curDir.replace(/\//g, '\\');
}
- //sv.cmdout.append("curDir:"+curDir);
+ //sv.debugMsg("curDir:"+curDir);
sv.r.setwd(curDir, ask, "this");
});
return;
Modified: komodo/SciViews-K/content/js/robjects.js
===================================================================
--- komodo/SciViews-K/content/js/robjects.js 2009-05-15 13:11:59 UTC (rev 129)
+++ komodo/SciViews-K/content/js/robjects.js 2009-05-19 16:46:52 UTC (rev 130)
@@ -8,7 +8,7 @@
//TODO: context menu for search-paths list
//TODO: renaming objects on the list - editable names
//TODO: add context menu item for environments: remove all objects
-//TODO: tollbar: dropdown menu for packages maintenance (add, install, etc)
+//TODO: toolbar: dropdown menu for packages maintenance (add, install, etc)
//TODO: solve problems with selection, when removing objects
//DONE: "remove" command: Shift + Command - removes immediatelly (confirmation box first), Command - adds R code to the current document
@@ -109,7 +109,59 @@
*/
+// Compute the intersection of n arrays
+//Array.prototype.intersect = function() {
+// if (!arguments.length)
+// return [];
+// var a1 = this;
+// var a = a2 = null;
+// var n = 0;
+// while(n < arguments.length) {
+// a = [];
+// a2 = arguments[n];
+// var l = a1.length;
+// var l2 = a2.length;
+// for(var i=0; i<l; i++) {
+// for(var j=0; j<l2; j++) {
+// if (a1[i] === a2[j])
+// a.push(a1[i]);
+// }
+// }
+// a1 = a;
+// n++;
+// }
+// return a.unique();
+//};
+//
+//// Get the union of n arrays
+//Array.prototype.union = function() {
+// var a = [].concat(this);
+// var l = arguments.length;
+// for(var i=0; i<l; i++) {
+// a = a.concat(arguments[i]);
+// }
+// return a.unique();
+//};
+//
+//// Return new array with duplicate values removed
+//Array.prototype.unique = function() {
+// var a = [];
+// var l = this.length;
+// for(var i=0; i<l; i++) {
+// for(var j=i+1; j<l; j++) {
+// // If this[i] is found later in the array
+// if (this[i] === this[j])
+// j = ++i;
+// }
+// a.push(this[i]);
+// }
+// return a;
+//};
+//
+
+
+
var rObjectsTree = {};
// rObjectsTree constructor:
@@ -133,8 +185,9 @@
var filterBy = 0; // filter by name by default
var isInitialized = false;
+// set debug mode:
+this.debug = typeof(sv.debug) != "undefined"? sv.debug : false;
-this.debug = false;
this.visibleData = [];
this.treeData = [];
@@ -177,8 +230,7 @@
var cmd = 'print(objList(id = "' + id + '_' + pack + '", envir = "' + pack +
'", all.info = FALSE, compare = FALSE), sep = "' + sep + '", eol = "\\n", raw.output = TRUE, header = TRUE)';
- if (_this.debug)
- sv.cmdout.append(cmd);
+ sv.debugMsg(cmd);
sv.r.evalCallback(cmd, _parseObjectList, pack);
};
@@ -314,10 +366,8 @@
var cmd = 'print(objList(id = "' + id + '_' + env + '_' + objName + '", envir = "' + env +
'", object = "' + objName + '", all.info = FALSE, compare = FALSE), sep = "' + sep + '", eol = "\\n")';
+ sv.debugMsg(cmd);
- if (_this.debug)
- sv.cmdout.append(cmd);
-
sv.r.evalCallback(cmd, _parseSubObjectList, obj);
};
@@ -999,8 +1049,7 @@
var cmd = 'invisible(sapply(c("' + selectedPackages.join('","') + '"), function(x) '
+ 'print(objList(envir = x, all.info = FALSE, compare = FALSE), sep = "' + sep + '", raw.output = TRUE, header = TRUE)))';
- if (_this.debug)
- sv.cmdout.append(cmd);
+ sv.debugMsg(cmd);
sv.r.evalCallback(cmd, _parseObjectList);
}
@@ -1093,7 +1142,6 @@
if(doRemove) {
// remove immediately
sv.r.evalCallback(cmd.join("\n"), sv.cmdout.append);
- //sv.cmdout.append(cmd);
} else {
// insert commands to current document
var view = ko.views.manager.currentView;
@@ -1107,6 +1155,8 @@
scimoz.insertText(scimoz.currentPos, cmd.join(nl));
}
+ //_this.selection.select(rows[0]);
+ _this.selection.clearSelection();
return true;
}
@@ -1116,20 +1166,19 @@
var namesArr = new Array();
var cellText, item;
var name = fullNames? "fullName" : "name";
-
- for (i in rows) {
- item = this.visibleData[rows[i]];
- cellText = item.origItem[name];
+ var selectedItemsOrd = _this.selectedItemsOrd;
+ for (i in selectedItemsOrd) {
+ item = selectedItemsOrd[i];
+ cellText = item[name];
if (cellText != "") {
- if (item.level == 1 &&
+ if (item.type == 'object' &&
cellText.search(/^[a-z\.][\w\._]*$/i) == -1)
cellText = "`" + cellText + "`";
-
- cellText = item.origItem[name];
- if (item.origItem.type == "args")
- cellText += "=";
+ else if (item.type == "args" && name == "name")
+ cellText += "="; // attach '=' to function args, but not to full names
namesArr.push(cellText);
}
+
}
return (namesArr);
}
@@ -1252,27 +1301,83 @@
//scimoz.insertText(scimoz.currentPos, res.join(";" + ["\r\n", "\n", "\r"][scimoz.eOLMode]));
}
+
+
+
+this.selectedItemsOrd = [];
+/*
+this.getClickedRow(event) {
+ var row = {}, column = {}, part = {};
+
+ var boxobject = _this.treeBox;
+ boxobject.QueryInterface(Components.interfaces.nsITreeBoxObject);
+ boxobject.getCellAt(event.clientX, event.clientY, row, column, part);
+
+ //if (typeof column.value != "string") column.value = column.value.id;
+ return row.value;
+ //document.getElementById("row").value = row.value;
+ //document.getElementById("column").value = column.value;
+ //document.getElementById("part").value = part.value;
+}
+*/
+
+//rObjectsTree
+
this.onEvent = function(event) {
- if (event.type == "keypress") {
+ var selectedRows = _this.getSelectedRows();
+ var selectedItems = [];
+ for (var i = 0; i < selectedRows.length; i++)
+ selectedItems.push(_this.visibleData[selectedRows[i]].origItem);
+ var curRowIdx = selectedRows.indexOf(_this.selection.currentIndex);
+
+
+
+ // this maintains array of selected items in order they were added to selection
+ var prevItems = _this.selectedItemsOrd;
+ var newItems = [];
+ for (var i = 0; i < prevItems.length; i++) {
+ var j = selectedItems.indexOf(prevItems[i]);
+ if (j != -1) // present in Prev, but not in Cur
+ newItems.push(prevItems[i])
+ }
+ for (var i = 0; i < selectedItems.length; i++) {
+ if (prevItems.indexOf(selectedItems[i]) == -1) { // present in Cur, but not in Prev
+ newItems.push(selectedItems[i]);
+ }
+ }
+ _this.selectedItemsOrd = newItems;
+
+ sv.debugMsg(newItems);
+
+ //sv.debugMsg(event.type)
+ //sv.debugMsg("keyCode: " + event.keyCode + "; charCode: " + event.charCode +
+ //"; which: " + event.which + "; .ctrlKey: " + event.ctrlKey);
+
+ if (event.type == "keyup" || event.type == "keypress") {
var keyCode = event.keyCode;
+ if (typeof(keyCode) == "undefined")
+ keyCode = 0;
- if (this.debug)
- sv.cmdout.append("keyCode: " + keyCode);
+ switch (keyCode) {
+ //case 38: // up
+ //case 40: // down
+ // if (event.shiftKey) {
+ // sv.debugMsg("Select: " + _this.visibleData[_this.selection.currentIndex].origItem.name);
+ // }
+ // return;
- switch (keyCode) {
case 46: // Delete key
_this.removeSelected(event.shiftKey);
event.originalTarget.focus();
return;
case 45: //insert
- sv.cmdout.append("Insert");
+ sv.debugMsg("Insert");
break;
- case 0:
- // Ctrt + A
- if (event.ctrlKey && event.charCode == 97 || event.charCode == 65){
+ case 65: // Ctrt + A
+ if (event.ctrlKey){
_this.selection.selectAll();
-
}
+ case 0:
return;
case 93:
//windows context menu key
@@ -1289,8 +1394,8 @@
// TODO: Escape key stops retrieval of r objects
default:
- //sv.cmdout.append(String.fromCharCode(event.charCode));
- //sv.cmdout.append("keyCode: " + keyCode);
+ //sv.debugMsg(String.fromCharCode(event.charCode));
+ //sv.debugMsg("keyCode: " + keyCode);
return;
}
@@ -1301,6 +1406,8 @@
if (_this.selection && (_this.selection.currentIndex == -1
|| _this.isContainer(_this.selection.currentIndex)))
return;
+ } else if (event.type == "click") {
+ return;
}
// default action: insert selected names:
@@ -1356,7 +1463,7 @@
sv.r.evalCallback(
'tryCatch(detach("' + pkg + '"), error = function(e) cat("<error>"));', function(data) {
- sv.cmdout.append(data);
+ sv.debugMsg(data);
if (data.trim() != "<error>") {
_removeObjectList(pkg);
listbox.removeChild(listItem);
Modified: komodo/SciViews-K/content/js/sciviews.js
===================================================================
--- komodo/SciViews-K/content/js/sciviews.js 2009-05-15 13:11:59 UTC (rev 129)
+++ komodo/SciViews-K/content/js/sciviews.js 2009-05-19 16:46:52 UTC (rev 130)
@@ -60,6 +60,17 @@
}
};
}
+
+//DEBUG:
+// global debugging flag:
+sv.debug = false;
+
+sv.debugMsg = function(msg) {
+ if (sv.debug)
+ sv.cmdout.append("debug: " + msg);
+}
+
+
// Create the 'sv.tools' namespace
if (typeof(sv.tools) == 'undefined') sv.tools = new Object();
Modified: komodo/SciViews-K/content/overlay.xul
===================================================================
--- komodo/SciViews-K/content/overlay.xul 2009-05-15 13:11:59 UTC (rev 129)
+++ komodo/SciViews-K/content/overlay.xul 2009-05-19 16:46:52 UTC (rev 130)
@@ -91,8 +91,9 @@
<menuseparator keep="false" intoplevel="true" />
<menuitem id="menu_robjects_cmd_help" command="robjects_cmd_help" />
</menupopup>
+</popupset>
-</popupset>
+
<commandset id="allcommands">
<broadcasterset id="broadcasterset_global">
<broadcaster
@@ -106,7 +107,22 @@
state="open"
/>
</broadcasterset>
- <command id="Tasks:svAbout" oncommand="alert('SciViews-K (Komodo R Editor) version ' + sv.version + '\na Komodo extension to interact with R\n(see http://www.sciviews.org/SciViews-K)');"/>
+ <command id="Tasks:svAbout" oncommand="alert('SciViews-K (Komodo R Editor) version ' + sv.version + '\na Komodo extension to interact with R\n(see http://www.sciviews.org/SciViews-K)');"/>
+
+ <broadcasterset id="broadcasterset_global">
+ <broadcaster id="cmd_sv_RRunAll" key="keycmd_sv_RRunAll" keycode="VK_F5" modifiers="" oncommand="sv.r.send("all");" desc="R: Send file content" />
+ <broadcaster id="cmd_sv_RSourceAll" key="keycmd_sv_RSourceAll" modifiers="shift" keycode="VK_F5" oncommand="sv.r.source("all");" desc="R: Source file" />
+ <broadcaster id="cmd_sv_RRunBlock" key="keycmd_sv_RRunBlock" oncommand="sv.r.send("block");" desc="R: Send marked block" />
+ <broadcaster id="cmd_sv_RRunFunction" key="keycmd_sv_RRunFunction" oncommand="sv.r.send("function");" desc="R: Send function under cursor" />
+ <broadcaster id="cmd_sv_RRunLine" key="keycmd_sv_RRunLine" oncommand="sv.r.send("line");" desc="R: Send active line" />
+ <broadcaster id="cmd_sv_RRunPara" key="keycmd_sv_RRunPara" oncommand="sv.r.send("para");" desc="R: Send current paragraph" />
+ <broadcaster id="cmd_sv_RRunSelection" key="keycmd_sv_RRunSelection" oncommand="sv.r.send("sel");" desc="R: Send selection" />
+ <broadcaster id="cmd_sv_RSourceBlock" key="keycmd_sv_RSourceBlock" oncommand="sv.r.source("block");" desc="R: Source marked block" />
+ <broadcaster id="cmd_sv_RSourceFunction" key="keycmd_sv_RSourceFunction" oncommand="sv.r.source("function");" desc="R: Source function under cursor" />
+ <broadcaster id="cmd_sv_RSourcePara" key="keycmd_sv_RSourcePara" oncommand="sv.r.source("para");" desc="R: Source current paragraph" />
+ <broadcaster id="cmd_sv_RSourceSelection" key="keycmd_sv_RSourceSelection" oncommand="sv.r.source("sel");" desc="R: Source selection" />
+ </broadcasterset>
+
<commandset id="r-objects-commands">
<command id="robjects_cmd_insertname"
label="&sciviews.robjects.insName;"
@@ -119,7 +135,7 @@
<command id="robjects_cmd_removeobj"
label="&sciviews.robjects.rmObj;"
accesskey="R"
- oncommand="rObjectsTree.removeSelected();" />
+ oncommand="rObjectsTree.removeSelected(event.shiftKey);" />
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/sciviews -r 130
More information about the Sciviews-commits
mailing list