[Sciviews-commits] r197 - in komodo/SciViews-K/content: . js js/tools
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Sep 27 01:05:49 CEST 2009
Author: prezez
Date: 2009-09-27 01:05:49 +0200 (Sun, 27 Sep 2009)
New Revision: 197
Modified:
komodo/SciViews-K/content/RHelpOverlay.xul
komodo/SciViews-K/content/RObjectsOverlay.xul
komodo/SciViews-K/content/js/commands.js
komodo/SciViews-K/content/js/r.js
komodo/SciViews-K/content/js/sciviews.js
komodo/SciViews-K/content/js/tools/file.js
Log:
R help window: window title/location updated on page load, search text within document (Ctrl+F).
sv.r.pkg.install rewritten to replace all sv.r.pkg.install* functions.
sv.getText, .getLine, .getPart removed, replaced by sv.getTextRange.
Automatic start of R (temporarily) commented out from sv.r.eval - problems with multiple instances being started.
Modified: komodo/SciViews-K/content/RHelpOverlay.xul
===================================================================
--- komodo/SciViews-K/content/RHelpOverlay.xul 2009-09-24 13:43:47 UTC (rev 196)
+++ komodo/SciViews-K/content/RHelpOverlay.xul 2009-09-26 23:05:49 UTC (rev 197)
@@ -57,11 +57,11 @@
var rHelpBrowser;
var rHelpTopic;
var rHelpHome;
-
+
function display(page) {
rHelpBrowser.webNavigation.loadURI(page, null, null, null, null);
}
-
+
function go() {
var page = rHelpTopic.value;
rHelpTopic.select();
@@ -74,23 +74,24 @@
sv.r.help(rHelpTopic.value);
}
}
-
+
+
function txtInput(aEvent) {
if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN) {
go();
}
}
-
- function search() {
+
+ function search() {
rHelpTopic.select();
sv.r.search(rHelpTopic.value);
}
-
+
function print() {
alert("Print not implemented yet!");
//window.print();
}
-
+
function home() {
// Change rHelpHome (not set before to display quicker the first time)
rHelpHome = sv.prefs.getString("Rhelp.index",
@@ -98,36 +99,125 @@
rHelpBrowser.webNavigation.loadURI(rHelpHome,
null, null, null, null);
}
-
+
function goBack() {
- var webNavigation = rHelpBrowser.webNavigation;
+ var webNavigation = rHelpBrowser.webNavigation;
if (webNavigation.canGoBack)
webNavigation.goBack();
+
}
-
+
function goForward() {
var webNavigation = rHelpBrowser.webNavigation;
if (webNavigation.canGoForward)
webNavigation.goForward();
}
-
+
+
+ // Browser progress listener:
+ // so far used only to change title
+
+ // From: https://developer.mozilla.org/en/Code_snippets/Progress_Listeners
+ const STATE_START = Components.interfaces.nsIWebProgressListener.STATE_START;
+ const STATE_STOP = Components.interfaces.nsIWebProgressListener.STATE_STOP;
+ 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;
+ },
+
+ onStateChange: function(aWebProgress, aRequest, aFlag, aStatus) {
+ // If you use myListener for more than one tab/window, use
+ // aWebProgress.DOMWindow to obtain the tab/window which triggers the state change
+ if(aFlag & STATE_START) {
+ // This fires when the load event is initiated
+ rHelpTopic.value = aWebProgress.DOMWindow.document.location;
+ //sv.cmdout.append(">>" + aWebProgress.DOMWindow.document.location);
+ }
+ if(aFlag & STATE_STOP) {
+ // This fires when the load finishes
+ self.document.title = aWebProgress.DOMWindow.document.title;
+ }
+ },
+
+ onLocationChange: function(aProgress, aRequest, aURI){
+ // This fires when the location bar changes; i.e load event is confirmed
+ // or when the user switches tabs. If you use myListener for more than one tab/window,
+ // use aProgress.DOMWindow to obtain the tab/window which triggered the change.
+ },
+
+ // For definitions of the remaining functions see XULPlanet.com
+ onProgressChange: function(aWebProgress, aRequest, curSelf, maxSelf, curTot, maxTot) { },
+ onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) { },
+ onSecurityChange: function(aWebProgress, aRequest, aState) { }
+ }
+
+ function keyPressListener (event) {
+ //alert(event.ctrlKey + " * " + event.which);
+
+ if ((event.ctrlKey && event.which == 102)
+ || event.keyCode == 114) {
+ findInDoc(rHelpTopic.value, false);
+ }
+ }
+
+
self.onload = function () {
var args = window.arguments;
sv = args[0];
var page = rHelpHome;
if (typeof(args[1]) != "undefined") page = args[1];
rHelpTopic = document.getElementById("rhelp-topic");
+
+ rHelpTopic.clickSelectsAll = true;
+
rHelpBrowser = document.getElementById("rhelp-browser");
rHelpBrowser.webNavigation.loadURI(page,
null, null, null, null);
+
+
+ rHelpBrowser.addProgressListener(progressListener,
+ Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
+
+
+ document.addEventListener("keypress", keyPressListener, true);
+
+ /*rHelpBrowser.removeProgressListener(myListener,
+ Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
+ */
}
+
+
+ function findInDoc(searchString, findBackwards) {
+ findBackwards = findBackwards? true : false;
+
+ var rhb = rHelpBrowser;
+
+ if (!rhb.fastFind.searchString) {
+ //rHelpBrowser.fastFind.setDocShell(rhb.docShell)
+ rhb.fastFind.init(rhb.docShell);
+ }
+
+ if (searchString) {
+ if (searchString == rhb.fastFind.searchString) {
+ rhb.fastFind.findAgain(findBackwards, false);
+ } else {
+ rhb.fastFind.find(searchString, false);
+ }
+ }
+ }
+
+
]]>
</script>
<hbox>
<vbox align="stretch" flex="1">
<textbox id="rhelp-topic" flex="0" emptytext="topic or web page"
onkeypress="txtInput(event);"
- tooltiptext="Search topic or Web page"/>
+ tooltiptext="Search topic or Web page (or Ctrl+F/F3 to search in document)"/>
</vbox>
<toolbarbutton id="rhelp-go" class="macro-play-icon"
oncommand="go();" disabled="false" label="Go"
@@ -174,7 +264,7 @@
oncommand="print();" disabled="false" label="Print"
tooltiptext="Print this page" persist="buttonstyle" buttonstyle="pictures"/>
</hbox>
-
+
<vbox flex="1">
<hbox flex="1">
<browser id="rhelp-browser" type="content-primary"
Modified: komodo/SciViews-K/content/RObjectsOverlay.xul
===================================================================
--- komodo/SciViews-K/content/RObjectsOverlay.xul 2009-09-24 13:43:47 UTC (rev 196)
+++ komodo/SciViews-K/content/RObjectsOverlay.xul 2009-09-26 23:05:49 UTC (rev 197)
@@ -157,7 +157,7 @@
oncommand="sv.r.pkg.install();"/>
<menuitem id="r_objects_pkg_installLocal" label="Install from local files..."
accesskey="c" class="menuitem-iconic r-pkg-install-local-icon"
- oncommand="sv.r.pkg.installLocal();"/>
+ oncommand="sv.r.pkg.install(null, 'local');"/>
<menuitem id="r_objects_pkg_update" label="Update"
accesskey="u" class="menuitem-iconic r-pkg-update-icon"
oncommand="sv.r.pkg.update();"/>
Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js 2009-09-24 13:43:47 UTC (rev 196)
+++ komodo/SciViews-K/content/js/commands.js 2009-09-26 23:05:49 UTC (rev 197)
@@ -3,7 +3,7 @@
// Copyright (c) 2009, K. Barton & Ph. Grosjean (phgrosjean at sciviews.org)
// License: MPL 1.1/GPL 2.0/LGPL 2.1
////////////////////////////////////////////////////////////////////////////////
-// sv.command.getRApp(event); // Select a preferred R application in the list
+// sv.command.getRApp(event); // Select a preferred R application in the list
// sv.command.setMenuRApp(el); // Set up 'R application' submenu (checked item
// and hide incompatible items.
// sv.command.startR(); // Start the preferred R app and connect to it
@@ -30,30 +30,30 @@
}
setTimeout(window.updateCommands, 1000, 'r_app_started_closed');
}
-
+
function _isRRunning () {
//sv.log.debug("is R Running? " + sv.r.running);
return sv.r.running;
}
-
+
function _RControl_supported () {
var currentView = ko.views.manager.currentView;
if (!currentView || !currentView.document)
- return false;
+ 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);
}
-
+
// Start R, if not already running
this.startR = function () {
// runIn = "command-output-window", "new-console",
@@ -78,7 +78,7 @@
var cwd = sv.tools.file.path("ProfD",
["extensions", "sciviewsk at sciviews.org", "templates"]);
var command, runIn = "no-console";
-
+
ko.statusBar.AddMessage(sv.translate("Starting R... please wait"),
"StartR", 10000, true);
switch (preferredRApp) {
@@ -140,7 +140,7 @@
runIn = "new-console";
}
sv.log.debug("Running: " + command);
-
+
// Debugging garbage...
//var command = "CMD /C \"SET\" > c:\\env.txt & notepad c:\\env.txt";
//ko.run.runCommand(window,
@@ -149,14 +149,14 @@
// .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);
};
-
+
// 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
@@ -165,14 +165,14 @@
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) {
@@ -193,7 +193,7 @@
// Possibly refresh the GUI by running SciViews-specific
// R task callbacks and make sure R Objects pane is updated
sv.r.evalHidden("try(guiRefresh(force = TRUE), silent = TRUE)");
-
+
//xtk.domutils.fireEvent(window, 'r_app_started_closed');
window.updateCommands('r_app_started_closed');
},
@@ -202,15 +202,15 @@
classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
observerSvc.removeObserver(this, 'status_message');
-
+
sv.log.debug("R has been closed. Command was: " + this.command);
-
+
sv.r.running = false;
//xtk.domutils.fireEvent(window, 'r_app_started_closed');
window.updateCommands('r_app_started_closed');
}
};
-
+
// Selects the checkbox on selected element, while deselecting others
this.getRApp = function (event) {
var el = event.originalTarget;
@@ -224,11 +224,11 @@
el.parentNode.setAttribute('selected', el.id);
// Set the preference string
sv.prefs.setString("sciviews.preferredRApp", el.id, true);
-
+
document.getElementById("cmd_sv_start_R").setAttribute("label",
sv.translate("Start R") + " (" + 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,
@@ -239,7 +239,7 @@
var isLinux = navigator.platform.toLowerCase().indexOf("linux") > -1;
var isMac = navigator.platform.toLowerCase().indexOf("mac") > -1;
-
+
// This will tell whether an app is present on the *nix system
function whereis(app) {
var runSvc = Components.
@@ -252,7 +252,7 @@
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++) {
@@ -282,7 +282,7 @@
}
}
}
-
+
if (!showItem) {
siblings[i].style.display = "none";
// This does not work on the Mac, but the following is fine
@@ -297,19 +297,19 @@
sv.log.exception(e, "Error looking for R apps in setMenuRApp");
}
}
-
+
// Set the preference string
sv.prefs.setString("sciviews.preferredRApp", selected, false);
-
+
document.getElementById("cmd_sv_start_R").setAttribute("label",
sv.translate("Start R") + " (" + document.getElementById(selected).
getAttribute('label') + ")"
);
-
+
// We do not need to run it anymore
el.removeAttribute("onpopupshowing");
}
-
+
this.openPkgManager = function () {
window.openDialog(
"chrome://sciviewsk/content/pkgManagerOverlay.xul",
@@ -317,7 +317,7 @@
"chrome=yes,dependent,centerscreen,resizable=yes,scrollbars=yes,status=no",
sv);
}
-
+
this.openHelp = function (webpage) {
if (typeof(webpage) == "undefined") {
// We are asking for the R help home page
@@ -336,7 +336,7 @@
RHelpWin = window.openDialog(
"chrome://sciviewsk/content/RHelpOverlay.xul",
"RHelp",
- "chrome=yes,dependent,resizable=yes,scrollbars=yes,status=no",
+ "chrome=yes,dependent,resizable=yes,scrollbars=yes,status=no,close,dialog=no",
sv, webpage);
// Recalculate home page for R Help only
sv.r.helpStart(false);
@@ -346,26 +346,26 @@
RHelpWin.focus();
}
}
-
+
this.setControllers = function () {
//sv.log.debug("this.setControllers");
// Allow some commands only when 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.
-
+
var vmProto = ko.views.viewManager.prototype;
-
+
var cmdsIfRRunning = ['OpenPkgManager', 'BrowseWD', 'quit_R',
'update_charset'];
var cmdsIfRNotRunning = ['start_R'];
-
+
// Make these commands active only when current document language is R
var cmdsIfIsRView = ["RunAll", "SourceAll", "RunBlock", "RunFunction",
"RunLine", "RunPara", "SourceBlock", "SourceFunction", "SourcePara",
"TriggerCompletion"];
// ... and if some text is selected
var cmdsIfIsRViewAndSelection = ["RunSelection", "SourceSelection"];
-
+
function _setCommandCtrl1 (arr, fun, pfx) {
pfx = "is_cmd_" + pfx;
for (var i in arr) {
@@ -373,18 +373,18 @@
vmProto[pfx + arr[i] + "_enabled"] = fun;
}
}
-
+
_setCommandCtrl1(cmdsIfRRunning, _isRRunning, "sv_");
_setCommandCtrl1(cmdsIfRNotRunning, function() {
return !_isRRunning()}, "sv_");
_setCommandCtrl1(cmdsIfIsRView, _RControl_supported, "sv_R");
_setCommandCtrl1(cmdsIfIsRViewAndSelection,
_RControlSelection_supported, "sv_R");
-
+
vmProto.do_cmd_sv_quit_R = function () {
sv.r.quit();
};
-
+
vmProto.do_cmd_sv_update_charset = function () {
sv.socket.updateCharset(true);
window.setTimeout(function() {
@@ -392,9 +392,9 @@
sv.socket.charset));
}, 100);
};
-
+
_keepCheckingR();
-
+
// This is no longer needed:
// To run it with the same key as autocompletion with other languages
// command "cmd_triggerPrecedingCompletion" is replaced in XUL
@@ -402,7 +402,7 @@
//vmProto.do_cmd_sv_RTriggerCompletion = function () {
// sv.r.complete();
//};
-
+
vmProto.do_cmd_sv_RRunLine = function () {
sv.r.send("line");
};
@@ -440,7 +440,7 @@
sv.command.startR();
};
}
-
+
// Set default keybindings from file
// chrome://sciviewsk/content/default-keybindings.kkf
// preserving user modified ones and avoiding key conflicts
@@ -448,18 +448,18 @@
var keybindingSvc = Components
.classes["@activestate.com/koKeybindingSchemeService;1"]
.getService(Components.interfaces.koIKeybindingSchemeService);
-
+
var svSchemeDefault = sv.tools.file
.readURI("chrome://sciviewsk/content/default-keybindings.kkf");
var currentSchemeName = sv.prefs.getString("keybinding-scheme");
-
+
// Perhaps this should be redone for each scheme?
//var currentSchemeName = "Default";
//var schemeNames = {};
//keybindingSvc.getSchemeNames(schemeNames, {});
//schemeNames = schemeNames.value;
var sch = keybindingSvc.getScheme(currentSchemeName);
-
+
var bindingRx = /[\r\n]+(# *SciViews|binding cmd_sv_.*)/g;
if (clearOnly != true) {
function _getSvKeys (data, pattern) {
@@ -473,14 +473,14 @@
}
return res;
}
-
+
var svCmdPattern = "cmd_sv_";
var svKeysDefault = _getSvKeys (svSchemeDefault, svCmdPattern);
var svKeysCurrent = _getSvKeys (sch.data, svCmdPattern);
-
+
// Temporarily delete SciViews keybindings
sch.data = sch.data.replace(bindingRx, "");
-
+
// Check for key conflicts
var svKeysCurrentOther = _getSvKeys (sch.data, "");
var currKeyArr = [];
@@ -491,7 +491,7 @@
delete svKeysDefault[k];
}
}
-
+
var newSchemeData = "";
var key, updatedKeys = [];
for (var k in svKeysDefault) {
@@ -515,7 +515,7 @@
}
sch.save();
sv.log.debug("You may need to restart Komodo.");
-
+
// A (temporary) hack to allow for R autocompletion/calltips to be
// triggered with the same key-shortcut as for other languages.
// cmd_sv_RTriggerCompletion will exit for files other than R
@@ -526,5 +526,6 @@
}
}).apply(sv.command);
+
addEventListener("load", sv.command.setControllers, false);
addEventListener("load", sv.command.setKeybindings, false);
Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js 2009-09-24 13:43:47 UTC (rev 196)
+++ komodo/SciViews-K/content/js/r.js 2009-09-26 23:05:49 UTC (rev 197)
@@ -85,7 +85,10 @@
// sv.r.pkg.unload_select(pkgs); // Callback function for sv.r.pkg.unload()
// sv.r.pkg.remove(); // Remove one R package
// sv.r.pkg.remove_select(pkgs); // Callback function for sv.r.pkg.remove()
-// sv.r.pkg.install(isCRANMirrorSet); // Install R package(s) from repository
+// sv.r.pkg.install(pkgs, repos); // Install R package(s) from local files or repositories
+
+
+/// REMOVED! replaced by sv.r.pkg.install
// sv.r.pkg.installLocal(); // Install one or more R packages from local files
// sv.r.pkg.installSV(); // Install the SciViews-R packages from CRAN
// sv.r.pkg.installSVrforge(); // Install development versions of SciViews-R
@@ -169,7 +172,7 @@
// Indicate that we want to execute this command when R is started
sv.r.pendingCmd = cmd;
// and start R now
- sv.command.startR();
+ //sv.command.startR();
return null;
}
cmd = (new String(cmd)).trim();
@@ -222,7 +225,7 @@
sv.r.pendingFun = procfun;
sv.r.pendingContext = context;
// and start R now
- sv.command.startR();
+ //sv.command.startR();
return null;
}
// Evaluate a command in hidden mode (contextual help, calltip, etc.)
@@ -523,7 +526,7 @@
code = sv.getTextRange("codefrag");
}
code = code.replace(/(")/g, "\\$1");
-
+
var scimoz = ko.views.manager.currentView.scimoz;
var cmd = 'Complete("' + code + '", print = TRUE, types = "scintilla")';
@@ -562,7 +565,8 @@
// TODO: this duplicates rObjectsTree.do(), so do something with it
sv.r.display = function (topic, what) {
var res = false;
- if (typeof(topic) == "undefined" | topic == "") topic = sv.getText();
+ if (typeof(topic) == "undefined" | topic == "")
+ topic = sv.getTextRange("word");
if (topic == "") {
//sv.alert("Nothing is selected!");
} else {
@@ -619,7 +623,7 @@
var res = false;
if (!topic && !pkg) {
if (typeof(topic) == "undefined" || topic == "")
- topic = sv.getText();
+ topic = sv.getTextRange("word");
if (topic == "")
ko.statusBar.AddMessage(sv.translate("Selection is empty..."), "R",
1000, false);
@@ -641,7 +645,8 @@
// TODO: merge with sv.r.help
sv.r.example = function (topic) {
var res = false;
- if (typeof(topic) == "undefined" | topic == "") topic = sv.getText();
+ if (typeof(topic) == "undefined" | topic == "")
+ topic = sv.getTextRange("word");
if (topic == "") {
ko.statusBar.AddMessage(sv.translate("Selection is empty..."), "R",
1000, false);
@@ -657,7 +662,7 @@
sv.r.search = function (topic, internal) {
var res = false;
if (typeof(topic) == "undefined" | topic == "") {
- topic = sv.getText();
+ topic = sv.getTextRange("word");
// Ask for the search string
topic = ko.dialogs.prompt(sv.translate("Search R objects using a regular" +
" expression (e.g. '^log' for objects starting with 'log')"),
@@ -701,7 +706,8 @@
// Search R web sites for topic
sv.r.siteSearch = function (topic) {
var res = false;
- if (typeof(topic) == "undefined" | topic == "") topic = sv.getText();
+ if (typeof(topic) == "undefined" | topic == "")
+ topic = sv.getTextRange("word");
if (topic == "") {
ko.statusBar.AddMessage(sv.translate("Selection is empty..."), "R",
1000, false);
@@ -929,7 +935,7 @@
// Temporary code: at least set pref value
sv.prefs.setString("r.active." + objclass, objname, true);
// Refresh statusbar message in case an 'lm' object is changed
- if (objclass == "lm") sv.r.obj_message();
+ if (objclass == "lm") sv.r.obj_message();
}
}
}
@@ -964,7 +970,7 @@
' res <- paste(c(.active.data.frame$object, names(obj)), "\t",\n' +
' c(class(obj), sapply(obj, class)), "\n", sep = "")\n' +
' return(.active.data.frame$cache <<- res)\n' +
- ' } else return(.active.data.frame$cache <<- NULL)\n' +
+ ' } else return(.active.data.frame$cache <<- NULL)\n' +
'}, cache = "")\n' +
'cat(.active.data.frame$fun(), sep = "")',
sv.r.obj_refresh_dataframe);
@@ -989,7 +995,7 @@
sv.r.obj_message();
return(false);
}
-
+
var items = data.split("\n");
// First item contains the name of the active object and its class
var item = sv.tools.strings.removeLastCRLF(items[0]).split("\t");
@@ -1057,7 +1063,7 @@
sv.r.obj_message();
return(false);
}
-
+
var items = data.split("\n");
// First item contains the name of the active object and its class
var item = sv.tools.strings.removeLastCRLF(items[0]).split("\t");
@@ -1082,7 +1088,7 @@
if (items[i] != "")
ko.mru.add("datafile_mru", items[i], true);
}
-
+
// Refresh lists of scripts
items = sv.tools.file.list(sv.prefs.getString("sciviews.scripts.localdir"),
/\.[rR]$/, true);
@@ -1092,7 +1098,7 @@
if (items[i] != "")
ko.mru.add("scriptfile_mru", items[i], true);
}
-
+
// Refresh lists of reports
items = sv.tools.file.list(sv.prefs.getString("sciviews.reports.localdir"),
/\.[oO][dD][tT]$/, true);
@@ -1212,7 +1218,7 @@
// Initialize the session
dir = sv.r.initSession(dir, datadir, scriptdir, reportdir);
-
+
// Switch to the new session directory in R
cmd = cmd + 'setwd("' + dir + '")\noptions(R.initdir = "' + dir + '")\n';
@@ -1234,7 +1240,7 @@
sv.r.escape('cat("Session directory is now ' + dir +
'\n", file = stderr())');
// Refresh active objects support
-
+
// We most probably need to update the R Objects browser and active objs
//sv.r.objects.getPackageList(true); // Old command, but refresh only object browser
sv.r.evalHidden("try(guiRefresh(force = TRUE), silent = TRUE)");
@@ -1251,7 +1257,7 @@
var sessionDir = "";
// Base directory is different on Linux/Mac OS X and Windows
if (navigator.platform.indexOf("Win") > -1) {
- baseDir = "~"
+ baseDir = "~"
} else {
baseDir = "~/Documents"
}
@@ -1382,7 +1388,7 @@
'unlink(".RData"); unlink(".Rhistory")\n' +
'setwd(.savdir.); rm(.savdir.)';
sv.r.evalHidden(cmd);
- }
+ }
}
// Quit R (ask to save in save in not defined)
@@ -1414,55 +1420,50 @@
return(res);
}
-// Select CRAN mirror
-//TODO: remove?
-sv.r.pkg.CRANmirror = function () {
- sv.r.pkg.chooseCRANMirror(false);
-}
+// Select CRAN mirror, with optional callback
+sv.r.pkg.chooseCRANMirror = function (callback) {
+ var res = false;
-// Replacement for sv.r.pkg.CRANmirror, optionaly calls .install after execution
-sv.r.pkg.chooseCRANMirror = function (andInstall) {
- var res = false;
- res = sv.r.evalCallback(
- '.sv.tmp <- getCRANmirrors(all = FALSE, local.only = FALSE); ' +
- 'cat(.sv.tmp$Name[.sv.tmp$OK == 1], sep="' + sv.r.sep + '"); rm(.sv.tmp)',
- function (repos) {
- ko.statusBar.AddMessage("", "R");
+ var cmd = 'assignTemp("cranMirrors", getCRANmirrors(all = FALSE, local.only = FALSE));' +
+ 'write.table(getTemp("cranMirrors")[, c("Name", "URL")], col.names = FALSE, quote = FALSE, sep ="' + sv.r.sep + '", row.names = FALSE)';
+
+ res = sv.r.evalCallback(cmd, function (repos) {
var res = false;
if (repos.trim() == "") {
sv.alert("Error getting CRAN Mirrors list.");
} else {
- var items = repos.split(sv.r.sep);
+ repos = repos.split(/[\n\r]+/);
+ var names = [], urls = [];
+ for (i in repos) {
+ var m = repos[i].split(sv.r.sep);
+ names.push(m[0]);
+ urls.push(m[1]);
+ }
items = ko.dialogs.selectFromList(sv.translate("CRAN mirrors"),
- sv.translate("Select CRAN mirror to use:"), items, "one");
+ sv.translate("Select CRAN mirror to use:"), names, "one");
- if (items != null) {
- res = sv.r.evalCallback(".sv.tmp <- getCRANmirrors(all = FALSE, " +
- "local.only = FALSE); .sv.repos <- getOption(\"repos\"); " +
- ".sv.repos[\"CRAN\"] <- gsub(\"/$\", \"\", " +
- ".sv.tmp$URL[.sv.tmp$Name == \"" + items[0] + "\"]); " +
- "options(repos =.sv.repos); rm(.sv.repos, .sv.tmp); " +
- "cat(getOption(\"repos\")['CRAN']);",
- function(url) {
- ko.statusBar.AddMessage(
- sv.translate("Current CRAN mirror is set to %S",
- url), "R", 5000, false);
- if (andInstall)
- sv.r.pkg.install(true);
- },
- andInstall);
- }
+ repos = urls[names.indexOf(items[0])].replace(/\/$/, "");
+ ko.statusBar.AddMessage(sv.translate("Current CRAN mirror is set to %S",
+ repos), "R", 5000, false);
+
+ sv.r.eval('with(TempEnv(), { repos <- getOption("repos");' +
+ 'repos["CRAN"] <- "' + repos + '"; ' +
+ 'options(repos = repos) } )');
+ sv.r.pkg.repos = repos;
+ if (callback)
+ callback();
+
}
return(res);
- }
- );
+ });
ko.statusBar.AddMessage(
sv.translate("Retrieving CRAN mirrors list... please wait."), "R",
20000, true);
return(res);
}
+
// List available packages on the selected repositories
sv.r.pkg.available = function () {
var res = sv.r.eval('.pkgAvailable <- available.packages()\n' +
@@ -1628,109 +1629,131 @@
return(res);
}
-sv.r.pkg.install = function (isCRANMirrorSet) {
+
+
+
+
+// sv.r.pkg.install - install R packages
+// examples:
+// sv.r.pkg.install() // use default CRAN mirror
+// sv.r.pkg.install("", true) // re-set CRAN mirror
+// sv.r.pkg.install(["boot", "lme4"])
+// sv.r.pkg.install("", "local") // local installation, popups "Open file" dialog
+// sv.r.pkg.install("/path/to/packages", "local") // with initial path
+// sv.r.pkg.install("sciviews") // install all sciViews packages
+// sv.r.pkg.install("sciviews", "r-forge") // ... from R-Forge
+// sv.r.pkg.install("sciviews", "http://r.meteo.uni.wroc.pl") // use different CRAN mirror
+
+sv.r.pkg.install = function (pkgs, repos) {
+ // Just in case, to prevent infinite callbacks
+ // but such should never happen
+ var allowCCM = arguments.length < 3;
+
var res = false;
- if (!isCRANMirrorSet) {
+ var reset = repos === true;
+
+ function _installCallback() {
+ sv.r.pkg.install(pkgs, sv.r.pkg.repos, true);
+ };
+
+ if (!repos && sv.r.pkg.repos) {
+ repos = sv.r.pkg.repos;
+ } else if (reset && allowCCM) {
+ res = sv.r.pkg.chooseCRANMirror(_installCallback);
+ return;
+ } else if (!repos && allowCCM) {
res = sv.r.evalCallback("cat(getOption(\"repos\")[\"CRAN\"])",
function(cran) {
var res = false;
- if (cran.trim() == "@CRAN@") {
- res = sv.r.pkg.chooseCRANMirror("install");
+ cran = cran.trim();
+ if (cran == "@CRAN@") {
+ res = sv.r.pkg.chooseCRANMirror(_installCallback);
} else {
- res = sv.r.pkg.install(true);
+ sv.r.pkg.repos = cran;
+ res = sv.r.pkg.install(pkgs, sv.r.pkg.repos, true);
}
- return (res);
+ return;
}
);
- } else {
- ko.statusBar.AddMessage(sv.translate("ListingPackages"),
- "R", 20000, true);
+ return;
+ }
+
+ // At this point repos should be always set
+ sv.cmdout.append(">> Using " + repos);
+
+ repos = repos.toLowerCase();
+
+ var startDir = null;
+ if (typeof pkgs == "string" &&
+ sv.tools.file.exists(pkgs) == sv.tools.file.TYPE_DIRECTORY) {
+ repos = "local";
+ startDir = pkgs;
+ }
+
+ // no packages provided, popup a list with available ones
+ // then callback again
+ if (!pkgs && repos != "local") {
+ sv.cmdout.message(sv.translate("Listing available packages..."), 5000);
res = sv.r.evalCallback('cat(available.packages()[,1], sep="' +
sv.r.sep + '")', function (pkgs) {
- ko.statusBar.AddMessage("", "R");
+ sv.cmdout.message("");
+
var res = false;
if (pkgs.trim() != "") {
- var items = pkgs.split(sv.r.sep);
- items = ko.dialogs.selectFromList(
+ pkgs = pkgs.split(sv.r.sep);
+ pkgs = ko.dialogs.selectFromList(
sv.translate("Install R package"),
- sv.translate("Select package(s) to install") + ":",
- items);
+ sv.translate("Select package(s) to install") + ":", pkgs);
- if (items != null) {
- items = '"' + items.join('", "') + '"';
- ko.statusBar.AddMessage(
- sv.translate("Installing packages... please wait"),
- "R");
- sv.socket.rCommand("install.packages(c(" + items + "))",
- true, null, function(data) {
- ko.statusBar.AddMessage("", "R");
- }
- );
+ if (pkgs != null) {
+ res = sv.r.pkg.install(pkgs, repos, true);
}
}
- return(res);
- }
- );
+ });
+ return;
+
}
- return(res);
-}
-// Install R packages from local files (either source, or binaries)
-// TODO: combine with: sv.r.pkg.install
-sv.r.pkg.installLocal = function () {
- var res = false;
- // Get list of files to install
- var files = sv.fileOpen(null, null,
- sv.translate("Select package(s) to install"),
- ['Zip archive (*.zip)|*.zip', 'Gzip archive (*.tgz;*.tar.gz)|*.tgz;*.tar.gz'],
- true);
+ // Expand short names
+ if (repos == "r-forge") {
+ repos = "http://r-forge.r-project.org";
+ } else if (repos == "local") {
+ repos = "NULL";
- if (files != null) {
- var cmd = "install.packages("
+ if (!pkgs || startDir) {
+ // Get list of files to install
+ pkgs = sv.fileOpen(startDir, null,
+ sv.translate("Select package(s) to install"),
+ ['Zip archive (*.zip)|*.zip', 'Gzip archive (*.tgz;*.tar.gz)|*.tgz;*.tar.gz'], true);
- if (typeof(files) == "object") {
- cmd += 'c("' + files.join('", "').addslashes() + '")';
+ if (pkgs == null)
+ return;
+
+ for (i in pkgs)
+ pkgs[i] = pkgs[i].addslashes();
+ }
+ }
+
+ if (repos != "NULL")
+ repos = "\"" + repos + "\"";
+
+ if (typeof pkgs == "string") {
+ if (pkgs.toLowerCase() == "sciviews") {
+ pkgs = ["svMisc", "svSocket", "svGUI", "svIDE", "svDialogs", "svWidgets",
+ "svSweave", "svTools", "svUnit", "tcltk2"];
} else {
- cmd += '"' + files.addslashes() + '"';
+ pkgs = [pkgs];
}
- cmd += ', repos = NULL)';
-
- res = sv.r.eval(cmd);
- ko.statusBar.AddMessage(sv.translate("InstallingPackages"),
- "R", 5000, true);
}
- return(res);
-}
-// Install the SciViews bundle from CRAN
-// TODO: combine with: sv.r.pkg.install
-sv.r.pkg.installSV = function () {
- var res = false;
- res = sv.r.eval('install.packages(c("svMisc", "svSocket", "svGUI", "svIDE"' +
- ', "svDialogs", "svWidgets", "svSweave", "svTools", "svUnit", "tcltk2"))');
- ko.statusBar.AddMessage("Installing SciViews-R packages... please wait",
- "R", 5000, true);
- return(res);
-}
+ var cmd = "install.packages(c(\"" + pkgs.join('", "') + "\"), repos = " +
+ repos + ")";
+ //sv.cmdout.append(cmd);
-// Install the latest development version of Sciviews packages from R-Forge
-// TODO: combine with: sv.r.pkg.install
-sv.r.pkg.installSVrforge = function () {
- var res = false;
- var response = ko.dialogs.customButtons(
- "R-Forge distributes latest development\n" +
- "version of the SciViews-R bundle.\nThis is NOT the lastest stable one!" +
- "\nInstall it anyway?", ["&Continue...", "Cancel"], "Continue...", null,
- "Install the SciViews-R bundle from R-Forge");
- if (response == "Cancel") { return res; }
- res = sv.r.eval('install.packages(c("svMisc", "svSocket", "svGUI", "svIDE"' +
- ', "svDialogs", "svWidgets", "svSweave", "svTools", "svUnit", "tcltk2")' +
- ', repos = "http://R-Forge.R-project.org")');
- ko.statusBar.AddMessage("Installing SciViews R packages from R-Forge..." +
- " please wait", "R", 5000, true);
- return(res);
+ sv.r.eval(cmd);
}
+
// Initialize the default (last used) R session
sv.r.initSession();
@@ -1741,4 +1764,4 @@
// .getService(Components.interfaces.svIRinterpreter);
//
// return R.calltip(code);
-//}
\ No newline at end of file
+//}
Modified: komodo/SciViews-K/content/js/sciviews.js
===================================================================
--- komodo/SciViews-K/content/js/sciviews.js 2009-09-24 13:43:47 UTC (rev 196)
+++ komodo/SciViews-K/content/js/sciviews.js 2009-09-26 23:05:49 UTC (rev 197)
@@ -10,11 +10,6 @@
//
// Various functions defined in the 'sv' namespace directly
// sv.alert(header, text); // Own alert box; text is optional
-// sv.getText(); // Get current selection, or word under the cursor
-// sv.getLine(); // Get current line in the active buffer
-// sv.getPart(what, resel, clipboard); // Get a part of text in the buffer
- // or copy it to the clipboard (reset selection if resel == false)
-
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/sciviews -r 197
More information about the Sciviews-commits
mailing list