[Sciviews-commits] r157 - in komodo/SciViews-K: components content content/js content/js/tools locale/en-GB locale/fr-FR skin
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jul 29 16:03:10 CEST 2009
Author: prezez
Date: 2009-07-29 16:03:00 +0200 (Wed, 29 Jul 2009)
New Revision: 157
Added:
komodo/SciViews-K/content/default-keybindings.kkf
Modified:
komodo/SciViews-K/components/koR_UDL_Language.py
komodo/SciViews-K/content/RBrowserOverlay.xul
komodo/SciViews-K/content/js/commands.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/io.js
komodo/SciViews-K/content/overlayMain.xul
komodo/SciViews-K/locale/en-GB/main.properties
komodo/SciViews-K/locale/en-GB/sciviewsk.dtd
komodo/SciViews-K/locale/fr-FR/main.properties
komodo/SciViews-K/locale/fr-FR/sciviewsk.dtd
komodo/SciViews-K/skin/pkgManager.css
Log:
Default keybindings ("content/default-keybindings.kkf") are now set if there is no user-defined (sv.command.setKeybindings).
ko.help.language rewritten in a more general form to accept javascript urls, searchURL in "components/koR_UDL_Language.py" changed accordingly.
State of R connection is now checked periodically (sv.r.test), availability of R menu items changes according to R state.
Drag&drop support for package list (loads into R dropped package names).
sv.socket - rewritten with a constructor.
Many other smaller changes.
Modified: komodo/SciViews-K/components/koR_UDL_Language.py
===================================================================
--- komodo/SciViews-K/components/koR_UDL_Language.py 2009-07-23 05:54:32 UTC (rev 156)
+++ komodo/SciViews-K/components/koR_UDL_Language.py 2009-07-29 14:03:00 UTC (rev 157)
@@ -71,9 +71,10 @@
# TODO: we probably have to rework and complete these lists!
_dedenting_statements = ['return', 'break', 'else', 'next']
_indenting_statements = ['switch', 'if', 'ifelse', 'while', 'for', 'repeat']
- searchURL = "http://wiki.r-project.org/rwiki/rhelp.php?id=%W"
- namedBlockDescription = 'R functions and classes'
-
+ #searchURL = "http://wiki.r-project.org/rwiki/rhelp.php?id=%W"
+ searchURL = "javascript: sv.r.help('%w');"
+ namedBlockDescription = 'R functions'
+
# TODO: I need to change this!
# this matches R function now, but I cannot see any effect / KB
namedBlockRE = r'^[ \t]*(?:[\.\w\x80-\xff][_\.\w\x80-\xff]+|(`).+\1)\s*<-\s*function\s*\(.*$'
Modified: komodo/SciViews-K/content/RBrowserOverlay.xul
===================================================================
--- komodo/SciViews-K/content/RBrowserOverlay.xul 2009-07-23 05:54:32 UTC (rev 156)
+++ komodo/SciViews-K/content/RBrowserOverlay.xul 2009-07-29 14:03:00 UTC (rev 157)
@@ -275,9 +275,10 @@
persist="height collapsed"
flex="1"
>
- <listbox flex="1" id="sciviews_robjects_searchpath_listbox"
- ondragdrop="nsDragAndDrop.drop(event, window.rObjectsTree.packageListObserver);"
+ <listbox flex="1" id="sciviews_robjects_searchpath_listbox"
+ ondragdrop="nsDragAndDrop.drop(event, rObjectsTree.packageListObserver);"
ondragover="nsDragAndDrop.dragOver(event, rObjectsTree.packageListObserver);"
+ ondraggesture="nsDragAndDrop.startDrag(event, rObjectsTree.packageListObserver);"
onkeypress="rObjectsTree.packageListKeyEvent(event);"
oncommand="rObjectsTree.packageSelectedEvent(event);"
/>
@@ -337,8 +338,10 @@
flex="1"
ordinal="9"/>
</treecols>
- <treechildren id="sciviews_robjects_objects_tree_main"
+ <treechildren id="sciviews_robjects_objects_tree_main"
ondraggesture="nsDragAndDrop.startDrag(event, rObjectsTree.listObserver);"
+ ondragdrop="nsDragAndDrop.drop(event, rObjectsTree.listObserver);"
+ ondragover="nsDragAndDrop.dragOver(event, rObjectsTree.listObserver);"
onclick="rObjectsTree.onEvent(event);"
ondblclick="rObjectsTree.onEvent(event);"
context="rObjectsContext"
Added: komodo/SciViews-K/content/default-keybindings.kkf
===================================================================
--- komodo/SciViews-K/content/default-keybindings.kkf (rev 0)
+++ komodo/SciViews-K/content/default-keybindings.kkf 2009-07-29 14:03:00 UTC (rev 157)
@@ -0,0 +1,19 @@
+version 15
+
+# Default keybindings for SciViews-K, will be applied if no other key has been
+# assigned by user, and if a key combination is not used.
+# Commands' ids must start with "cmd_sv_" and be defined in the XUL overlay.
+
+
+binding cmd_sv_RRunAll F5
+binding cmd_sv_RSourceAll Shift+F5
+binding cmd_sv_RRunSelection F6
+binding cmd_sv_RSourceSelection Shift+F6
+binding cmd_sv_RRunBlock F7
+binding cmd_sv_RSourceBlock Shift+F7
+binding cmd_sv_RRunLine F11
+binding cmd_sv_RRunPara F12
+binding cmd_sv_RSourcePara Shift+F12
+binding cmd_sv_RRunFunction Ctrl+F12
+binding cmd_sv_RSourceFunction Ctrl+Shift+F12
+binding cmd_sv_start_R Ctrl+F10
\ No newline at end of file
Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js 2009-07-23 05:54:32 UTC (rev 156)
+++ komodo/SciViews-K/content/js/commands.js 2009-07-29 14:03:00 UTC (rev 157)
@@ -1,7 +1,13 @@
/*
-Controllers for R related commands.
+Defines sv.command object.
+sv.command.setMenuRApp, sv.command.getRApp; // manage 'R application' submenu
+sv.command.setControllers; // sets controllers for R related commands
+sv.command.isRRunning; // tells if R has been started/closed with cmd_sv_start_R
+sv.command.setKeybindings; // sets default keybindings
+sv.command.openPkgManager; // opens package manager window
+
*/
@@ -13,21 +19,28 @@
// sv.command 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");
+ return(_isRRunning() && currentView.document.language == "R");
}
+function _keepCheckingR(stopMe) {
+ clearInterval(sv.r.testInterval);
+ if (!stopMe) {
+ sv.r.testInterval = window.setInterval(sv.r.test, 10000);
+ } else {
+ clearInterval(sv.r.testInterval);
+ }
+ setTimeout(window.updateCommands, 1000, 'r_app_started_closed');
+}
function _isRRunning() {
- //sv.cmdout.append("is R Running? " + isRRunning);
- return isRRunning;
+ //sv.debugMsg("is R Running? " + sv.r.running);
+ return sv.r.running;
}
function _RControlSelection_supported() {
@@ -35,8 +48,11 @@
if (!currentView || !currentView.scimoz)
return false;
- var anythingSelected = (currentView.scimoz.selectionEnd - currentView.scimoz.selectionStart) != 0;
- return(currentView.document.language == "R" && anythingSelected);
+ var anythingSelected = (currentView.scimoz.selectionEnd -
+ currentView.scimoz.selectionStart) != 0;
+ return(_isRRunning()
+ && currentView.document.language == "R"
+ && anythingSelected);
}
// selects the checkbox on selected element, while deselecting others
@@ -53,8 +69,8 @@
// set the preference string:
sv.prefs.setString("sciviews.preferredRApp", el.id, true);
- document.getElementById("cmd_svStartR").setAttribute("label",
- sv.translate("StartR") + " (" + el.getAttribute('label') + ")");
+ document.getElementById("cmd_sv_start_R").setAttribute("label",
+ sv.translate("Start R") + " (" + el.getAttribute('label') + ")");
}
@@ -110,8 +126,8 @@
// 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') + ")"
+ 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:
@@ -128,14 +144,13 @@
// 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 wouldn't allow to start app in a console window. So we have to do this trick here.
-
-
+// but this wouldn't allow to start app in a console window. So we have to do this trick here.
+//
+// This is not used for anything yet.
function AppTerminateObserver(command) {
this.register(command);
}
-
AppTerminateObserver.prototype = {
command: "",
// this is launched when status message is set, we then check if it was about
@@ -158,9 +173,9 @@
this.command = command;
observerSvc.addObserver(this, 'status_message', false);
sv.debugMsg("R has been started with command: " + command);
- isRRunning = true;
+ sv.r.running = true;
- xtk.domutils.fireEvent(window, 'r_app_started_closed');
+ //xtk.domutils.fireEvent(window, 'r_app_started_closed');
window.updateCommands('r_app_started_closed');
},
unregister: function() {
@@ -171,29 +186,45 @@
//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');
+ sv.r.running = 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;
+ var viewManager = ko.views.viewManager;
+
+ viewManager.prototype.is_cmd_sv_OpenPkgManager_enabled =
+ viewManager.prototype.is_cmd_sv_OpenPkgManager_supported =
+ _isRRunning;
+ viewManager.prototype.is_cmd_sv_BrowseWD_enabled =
+ viewManager.prototype.is_cmd_sv_BrowseWD_supported =
+ _isRRunning;
+
+ viewManager.prototype.is_cmd_sv_quit_R_supported =
+ viewManager.prototype.is_cmd_sv_quit_R_enabled =
+ _isRRunning;
+
+ viewManager.prototype.do_cmd_sv_quit_R = function() { sv.r.quit(); };
+
+ viewManager.prototype.is_cmd_sv_start_R_enabled =
+ viewManager.prototype.is_cmd_sv_start_R_supported =
+ function() { return !_isRRunning();};
+
+ _keepCheckingR();
+
// make these commands active only when current document language is R
var cmdNames = ["RunAll", "SourceAll", "RunBlock", "RunFunction", "RunLine", "RunPara",
- "SourceBlock", "SourceFunction", "SourcePara"];
+ "SourceBlock", "SourceFunction", "SourcePara", "TriggerCompletion"];
- 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;
@@ -207,6 +238,13 @@
viewManager.prototype["is_cmd_sv_R" + cmdNames[i] + "_enabled"] = _RControlSelection_supported;
}
+ // to run it with the same key as autocompletion with other languages
+ // command "cmd_triggerPrecedingCompletion" is replaced in XUL
+ // ko.commands.doCommandAsync('cmd_sv_RTriggerCompletion', event)
+ viewManager.prototype.do_cmd_sv_RTriggerCompletion = function() {
+ sv.r.autoComplete();
+ };
+
viewManager.prototype.do_cmd_sv_RRunLine = function() { sv.r.send("line"); };
viewManager.prototype.do_cmd_sv_RRunAll = function() { sv.r.send("all"); };
@@ -224,8 +262,7 @@
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() {
+ viewManager.prototype.do_cmd_sv_start_R = function() {
// runIn = "command-output-window", "new-console",
//env strings: "ENV1=fooJ\nENV2=bar"
//gPrefSvc.prefs.getStringPref("runEnv");
@@ -303,12 +340,88 @@
};
}
+// set default keybindings from file:
+// chrome://sciviewsk/content/default-keybindings.kkf
+// preserving user modified ones and avoiding key conflicts
+this.setKeybindings = function(clearOnly) {
+
+ var keybindingSvc = Components.classes["@activestate.com/koKeybindingSchemeService;1"]
+ .getService(Components.interfaces.koIKeybindingSchemeService);
+
+ var svSchemeDefault = sv.io.readURI("chrome://sciviewsk/content/default-keybindings.kkf");
+ var currentSchemeName = sv.prefs.getString("keybinding-scheme");
+
+ // perhaps this should be redone for each sheme?
+ //var currentSchemeName = "Default";
+ //var schemeNames = {};
+ //keybindingSvc.getSchemeNames(schemeNames, {});
+ //schemeNames = schemeNames.value;
+ var sch = keybindingSvc.getScheme(currentSchemeName);
+
+ if (clearOnly != true) {
+ function _getSvKeys (data, pattern) {
+ if (!pattern) pattern = "";
+ var keys = data.match(new RegExp("^binding " + pattern + ".*$", "gm"));
+ var res = {};
+ for (var j in keys) {
+ keys[j].search(/^binding\s+(\S+)\s+(\S+)$/);
+ res[RegExp.$1] = RegExp.$2;
+ }
+ 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(/[\r\n]+(# *SciViews|binding cmd_sv_.*)/g, "");
+
+ // check for key conflicts:
+ var svKeysCurrentOther = _getSvKeys (sch.data, "");
+ var currKeyArr = [];
+ for (var k in svKeysCurrentOther)
+ currKeyArr.push(svKeysCurrentOther[k]);
+ for (var k in svKeysDefault) {
+ if (currKeyArr.indexOf(svKeysDefault[k]) != -1) {
+ delete svKeysDefault[k];
+ }
+ }
+
+ var newSchemeData = "";
+ var key, updatedKeys = [];
+ for (var k in svKeysDefault) {
+ sv.debugMsg(k);
+ if (svKeysCurrent[k]) {
+ key = svKeysCurrent[k];
+ } else {
+ key = svKeysDefault[k];
+ updatedKeys.push(k);
+ }
+ newSchemeData += "binding " + k + " " + key + "\n";
+ }
+
+ sch.data += "\n\n# SciViews\n" + newSchemeData;
+
+ sv.debugMsg(updatedKeys.length +
+ "SciViews keybindings have been updated in \"" +
+ currentSchemeName + "\" scheme.");
+
+ } else {
+ sch.data = sch.data.replace(/[\r\n]+(# *SciViews|binding cmd_sv_.*)/g, "");
+ sv.debugMsg("SciViews keybindings have been cleared in \"" + currentSchemeName + "\" scheme.");
+
+ }
+ sch.save();
+
+ sv.debugMsg("You may need to restart Komodo.");
+}
+
}).apply(sv.command);
-//sv.command.setControllers();
addEventListener("load", sv.command.setControllers, false);
-
+addEventListener("load", sv.command.setKeybindings, false);
/*
//Useful garbage. delete it later.
Modified: komodo/SciViews-K/content/js/r-help.js
===================================================================
--- komodo/SciViews-K/content/js/r-help.js 2009-07-23 05:54:32 UTC (rev 156)
+++ komodo/SciViews-K/content/js/r-help.js 2009-07-29 14:03:00 UTC (rev 157)
@@ -22,21 +22,11 @@
var command = null, name = null;
if (language) {
- //////////////////////// R help mod:
- if (language == "R") {
- var topic;
- try {
- topic = ko.interpolate.interpolateStrings("%w").trim();
- sv.r.help(topic);
- return;
- } catch (e) {}
-
- } //////////////// end: R help mod
-
if (gPrefs.hasStringPref(language + "HelpCommand")) {
command = gPrefs.getStringPref(language + "HelpCommand");
} else {
- var langRegistrySvc = Components.classes['@activestate.com/koLanguageRegistryService;1'].getService(Components.interfaces.koILanguageRegistryService);
+ var langRegistrySvc = Components.classes['@activestate.com/koLanguageRegistryService;1']
+ .getService(Components.interfaces.koILanguageRegistryService);
var languageObj = langRegistrySvc.getLanguage(language);
if (languageObj.searchURL) {
command = "%(browser) " + languageObj.searchURL;
@@ -50,5 +40,12 @@
command = gPrefs.getStringPref("DefaultHelpCommand");
name = "Help";
}
- ko.run.runCommand(window, command, null, null, false, false, true, "no-console", 0, "", 0, name);
+
+ if (command.search(/^\s*javascript:\s*(\S.*)\s*$/) != -1) {
+ command = ko.interpolate.interpolateStrings(RegExp.$1);
+ eval(command);
+ } else {
+ ko.run.runCommand(window, command, null, null, false, false, true, "no-console", 0, "", 0, name);
+ }
+
}
Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js 2009-07-23 05:54:32 UTC (rev 156)
+++ komodo/SciViews-K/content/js/r.js 2009-07-29 14:03:00 UTC (rev 157)
@@ -67,8 +67,6 @@
// TODO: in overlay: add "source file" context menu item in the project tab
-
-
// Define the 'sv.r' namespace
if (typeof(sv.r) == 'undefined')
sv.r = {
@@ -80,10 +78,28 @@
//sv.r.init = function(cmd) {
//}
+sv.r.running = false;
+
+sv.r.test = function sv_RTest() {
+ function sv_RTest_callback (response) {
+ var wasRRunning = sv.r.running;
+ var isRRunning = response == "ok!";
+
+ sv.r.running = isRRunning;
+ if (wasRRunning != isRRunning) {
+ //xtk.domutils.fireEvent(window, 'r_app_started_closed');
+ window.updateCommands('r_app_started_closed');
+ sv.debugMsg("R state changed: " + wasRRunning + "->" + isRRunning);
+ }
+ }
+ var res = sv.r.evalCallback("cat('ok!');", sv_RTest_callback);
+ return res;
+}
+
// Evaluate code in R
sv.r.eval = function(cmd) {
- cmd = cmd.trim();
+ cmd = (new String(cmd)).trim();
// Store the current R command
if (sv.socket.prompt == ":> ") {
// Special case for q() and quit() => use sv.r.quit() instead
@@ -103,7 +119,8 @@
sv.cmdout.append(cmd);
}
}
- var res = sv.socket.rCommand('<<<e>>>' + cmd, sv.socket.cmdout, null, sv.r.addHistory, sv.socket.cmd);
+ var res = sv.socket.rCommand('<<<e>>>' + cmd, sv.socket.cmdout, null,
+ sv.r.addHistory, sv.socket.cmd);
return(res);
}
@@ -210,28 +227,33 @@
}
}
+ var res;
if (getDirFromR) {
var cmd = "cat(path.expand(" + getDirFromR + "))";
+ sv.cmdout.message(sv.translate("Asking R for directory..."));
- sv.r.evalCallback(cmd, function(curDir) {
+ res = sv.r.evalCallback(cmd, function(curDir) {
+ sv.cmdout.message();
+ if (!curDir) {
+ ko.dialogs.alert(sv.translate("Cannot retrieve directory from R. Make sure R is running."));
+ return null;
+ }
if (navigator.platform.search(/^Win/) == 0) {
curDir = curDir.replace(/\//g, '\\');
}
- //sv.debugMsg("curDir:"+curDir);
- sv.r.setwd(curDir, ask, "this");
+ return sv.r.setwd(curDir, ask, "this");
});
- return;
+ return res;
}
- if (ask || !dir) {
- dir = ko.filepicker.getFolder(dir, sv.translate("ChooseWorkingDir"));
- }
+ if (ask || !dir)
+ dir = ko.filepicker.getFolder(dir, sv.translate("Choose working directory"));
if (dir != null) {
- sv.r.evalHidden(".odir <- setwd(\"" + dir.addslashes() + "\")");
- sv.cmdout.message(sv.translate("WorkingDirSetTo", dir), 10000);
+ res = sv.r.evalHidden(".odir <- setwd(\"" + dir.addslashes() + "\")");
+ sv.cmdout.message(sv.translate("Current R's working directory is: \"%S\"", dir), 10000);
}
- return;
+ return res;
}
// Run current selection or line buffer in R
@@ -414,7 +436,9 @@
// Get a calltip for a R function
sv.r.calltip = function(codestrip) {
- res = sv.r.evalCallback('cat(CallTip("' + codestrip + '", location = TRUE))', sv.r.calltip_show);
+ var cmd = 'cat(CallTip("' + codestrip.replace(/(")/g, "\\$1") + '", location = TRUE))';
+ sv.cmdout.append(cmd);
+ var res = sv.r.evalCallback(cmd, sv.r.calltip_show);
return(res);
}
@@ -424,25 +448,77 @@
//ko.statusBar.AddMessage(tip, "R", 2000, true);
var ke = ko.views.manager.currentView.scimoz;
ke.callTipCancel();
- ke.callTipShow(ke.anchor, tip);
+ ke.callTipShow(ke.anchor, tip.replace(/[\r\n]+/g, "\n"));
}
}
+//
+sv.r.autoComplete = function() {
+ if (ko.views.manager.currentView.languageObj.name != "R")
+ return false;
+
+ var text = sv.getTextRange("linetobegin").replace(/(")/g, "\\$1");
+ var scimoz = ko.views.manager.currentView.scimoz;
+ //var cmd = 'cat(Complete("' + text + '"))';
+ //var cmd = 'scintillaCompletions("' + text + '", printit=TRUE, )';
+ var cmd = 'Complete2("' + text + '", print = TRUE, types = svMisc:::.scintilla.completion.types)';
+
+ //Complete2("' + text + '", print=TRUE)';
+ //sv.cmdout.append(cmd)
+
+ var res = sv.r.evalCallback(cmd, function(autoCstring) {
+ // these should be set only once?:
+ scimoz.autoCSeparator = 9;
+ scimoz.autoCSetFillUps(" []{}<>/():;%+-*@!\t\n\r=$`");
+
+ var autoCSeparatorChar = String.fromCharCode(scimoz.autoCSeparator);
+ autoCstring = autoCstring.replace(/^(.*)[\r\n]+/, "");
+
+ var trigPos = RegExp.$1;
+ //var trigPos = RegExp.$1.split(/;/g)[1];
+
+ autoCstring = autoCstring.replace(/\r?\n/g, autoCSeparatorChar);
+
+ // code below taken from "CodeIntelCompletionUIHandler"
+ var iface = Components.interfaces.koICodeIntelCompletionUIHandler;
+ scimoz.registerImage(iface.ACIID_FUNCTION,
+ ko.markers.getPixmap("chrome://komodo/skin/images/ac_function.xpm"));
+ scimoz.registerImage(iface.ACIID_VARIABLE,
+ ko.markers.getPixmap("chrome://komodo/skin/images/ac_variable.xpm"));
+ scimoz.registerImage(iface.ACIID_XML_ATTRIBUTE,
+ ko.markers.getPixmap("chrome://komodo/skin/images/ac_xml_attribute.xpm"));
+ scimoz.registerImage(iface.ACIID_NAMESPACE,
+ ko.markers.getPixmap("chrome://komodo/skin/images/ac_namespace.xpm"));
+ scimoz.registerImage(iface.ACIID_KEYWORD,
+ ko.markers.getPixmap("chrome://komodo/skin/images/ac_interface.xpm"));
+ scimoz.autoCChooseSingle = true;
+ scimoz.autoCShow(trigPos, autoCstring);
+ });
+ return res;
+}
+
+
// The trigger for sv.r.calltip (when '(' is entered)
sv.r.callTip_trigger = function(event) {
+ //sv.cmdout.append("keyCode " + event.keyCode);
+ if (ko.views.manager.currentView.languageObj.name != "R")
+ return;
+
try {
- if (event.keyCode == 53) { // 53 is code for '('
- var codestrip = sv.getPart("linetobegin", true);
+ if (event.keyCode == 57) { // 57 is code for '('
+ var codestrip = sv.getTextRange("linetobegin");
var res = sv.r.calltip(codestrip);
}
} catch(e) { log.exception(e); }
}
-window.addEventListener("keyup", sv.r.callTip_trigger, true);
+// TODO: better way to trigger calltips - with the same mechanism as
+// for other languages
+//window.addEventListener("keyup", sv.r.callTip_trigger, true);
// Start R help in the default browser
sv.r.helpStart = function() {
var res = sv.r.eval("help.start()");
- ko.statusBar.AddMessage(sv.translate("RHelpStarted"), "R", 5000, true);
+ ko.statusBar.AddMessage(sv.translate("R help started... should display in browser soon"), "R", 5000, true);
return(res);
}
@@ -455,7 +531,7 @@
if (topic == "") {
// let's not cry so much about an empty selection
- ko.statusBar.AddMessage(sv.translate("SelectionEmpty"), "R", 1000, false);
+ ko.statusBar.AddMessage(sv.translate("Selection is empty..."), "R", 1000, false);
//alert("Nothing is selected!");
}
@@ -470,7 +546,7 @@
// TODO: error handling when package does not exists
res = sv.r.evalCallback(cmd, sv.browseURI);
- ko.statusBar.AddMessage(sv.translate("RHelpAskedFor", topic),
+ ko.statusBar.AddMessage(sv.translate("R help asked for \"%S\"", topic),
"R", 5000, true);
}
@@ -485,7 +561,7 @@
//alert("Nothing is selected!");
} else {
res = sv.r.eval("example(" + topic + ")");
- ko.statusBar.AddMessage(sv.translate("RExampleFor", topic),
+ ko.statusBar.AddMessage(sv.translate("R example run for \"%S\"", topic),
"R", 5000, true);
}
return(res);
@@ -496,9 +572,9 @@
var res = false;
if (typeof(topic) == "undefined" | topic == "") topic = sv.getText();
// Ask for the search string
- topic = ko.dialogs.prompt(sv.translate("Search_R_objects_using_a_regular_expression"),
+ topic = ko.dialogs.prompt(sv.translate("Search R objects using a regular expression (e.g. '^log' for objects starting with 'log')"),
sv.translate("Pattern"), topic,
- sv.translate("Search_R_help"), "okRsearchPattern");
+ sv.translate("Search R help"), "okRsearchPattern");
if (topic != null & topic != "") {
// Get list of matching items and evaluate it with sv.r.search_select()
res = sv.r.evalCallback('cat(apropos("' + topic + '"), sep = "' + sv.r.sep + '")',
@@ -514,7 +590,7 @@
ko.statusBar.AddMessage("", "R");
var res = false;
if (sv.tools.strings.removeLastCRLF(topics) == "") {
- sv.cmdout.message(sv.translate("No_item_found_in_R_help"));
+ sv.cmdout.message(sv.translate("R help for %S not found.", topics));
} else { // Something is returned
var items = topics.split(sv.r.sep);
if (items.length == 1) {
@@ -612,12 +688,12 @@
// Load the content of a .RData file into the workspace, or attach it
-sv.r.loadWorkspace = function(file, attach) {
+sv.r.loadWorkspace = function(file, attach, callback, param) {
// Ask for the filename if not provided
if (!file) {
- file = sv.fileOpen("", ".RData", sv.translate("Browse_for_workspace"),
- [sv.translate("R_workspace") + " (*.RData)|*.RData"], true);
- } else if (typeof files == "string") {
+ file = sv.fileOpen("", ".RData", sv.translate("Browse for R workspace file"),
+ [sv.translate("R workspace") + " (*.RData)|*.RData"], true);
+ } else if (typeof file == "string") {
file = file.split(/[;,]/);
}
if (!file || !file.length)
@@ -626,9 +702,16 @@
var load = attach? "attach" : "load";
var cmd = [];
- for (var i in file)
- cmd[i] = load + "(\"" + file[i].addslashes() + "\")";
- sv.r.eval(cmd.join("\n"));
+ for (var i in file) {
+ cmd[i] = load + "(\"" + (new String(file[i])).addslashes() + "\")";
+ }
+
+ cmd = cmd.join("\n");
+ if (callback)
+ sv.r.evalCallback(cmd, callback, param);
+ else
+ sv.r.eval(cmd);
+
}
// Save the history in a file
@@ -766,8 +849,8 @@
} else { // Something is returned
var items = pkgs.split(sv.r.sep);
// Select the item you want in the list
- var topic = ko.dialogs.selectFromList(sv.translate("titleLoadPackage"),
- sv.translate("SelectPkgToLoad") + ":", items);
+ var topic = ko.dialogs.selectFromList(sv.translate("Load R package"),
+ sv.translate("Select R package(s) to load") + ":", items);
if (topic != null) {
res = sv.r.evalCallback('cat(paste(lapply(c("' + topic.join('", "') + '"), function(pkg) { res <- try(library(package = pkg, character.only = TRUE)); paste ("Package", sQuote(pkg), if (inherits(res, "try-error")) "could not be loaded" else "loaded") }), collapse = "\\n"), "\\n")',
sv.cmdout.append);
@@ -886,16 +969,14 @@
function(pkgs) {
ko.statusBar.AddMessage("", "R");
var res = false;
- if (pkgs.trim() == "") {
- alert("Error?"); // TODO: remove this later
- } else {
+ if (pkgs.trim() != "") {
var items = pkgs.split(sv.r.sep);
- items = ko.dialogs.selectFromList(sv.translate("titleInstallPackage"),
- sv.translate("SelectPkgsToInstall") + ":", items);
+ items = ko.dialogs.selectFromList(sv.translate("Install R package"),
+ sv.translate("Select package(s) to install") + ":", items);
if (items != null) {
items = '"' + items.join('", "') + '"';
- ko.statusBar.AddMessage(sv.translate("InstallingPkgs"), "R");
+ 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");
@@ -910,7 +991,6 @@
return(res);
}
-
// replacement for .CRANmirror, optionally calls .install after execution
sv.r.pkg.chooseCRANMirror = function(andInstall) {
var res = false;
@@ -924,13 +1004,13 @@
alert("Error getting CRAN Mirrors list.");
} else {
var items = repos.split(sv.r.sep);
- items = ko.dialogs.selectFromList(sv.translate("CRANMirrors"),
- sv.translate("SelectCRANMirror"), items, "one");
+ items = ko.dialogs.selectFromList(sv.translate("CRAN mirrors"),
+ sv.translate("Select CRAN mirror to use:"), items, "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("CRANMirrorSetTo", url), "R", 5000, false);
+ ko.statusBar.AddMessage(sv.translate("Current CRAN mirror is set to %S", url), "R", 5000, false);
if (andInstall)
sv.r.pkg.install(true);
},
@@ -940,7 +1020,7 @@
return(res);
}
);
- ko.statusBar.AddMessage(sv.translate("RetrievingCRANMirrors"),
+ ko.statusBar.AddMessage(sv.translate("Retrieving CRAN mirrors list... please wait."),
"R", 20000, true);
return(res);
}
@@ -954,7 +1034,7 @@
//var files = ko.filepicker.openFiles(null, null,
// "Select R package(s) to install (.tar.gz, .zip or .tgz)");
- var files = sv.fileOpen(null, null, sv.translate("SelectPkgsToInstall"),
+ 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);
Modified: komodo/SciViews-K/content/js/robjects.js
===================================================================
--- komodo/SciViews-K/content/js/robjects.js 2009-07-23 05:54:32 UTC (rev 156)
+++ komodo/SciViews-K/content/js/robjects.js 2009-07-29 14:03:00 UTC (rev 157)
@@ -887,21 +887,6 @@
this.getColumnProperties = function(column, element, prop) {};
-/*// used for debugging
-this.toString = function() {
- var vd = this.visibleData;
- var ret = "", indent;
- ret = "length: " + vd.length + "\n";
- for (var i = 0; i < vd.length; i++) {
- indent = ""; for (var j = 0; j < vd[i].level; j++) { indent += "+ "; }
-
- ret += vd[i].origItem.index + indent + " ^"+ vd[i].parentIndex + "-> " + vd[i].uid + " (" + vd[i].name + ")" +
- (vd[i].isContainer? "*" : "" )
- + "\n";
- }
- return ret;
-};*/
-
this.getSelectedRows = function() {
var start = new Object();
var end = new Object();
@@ -921,10 +906,38 @@
this.listObserver = {
onDragStart: function (event, transferData, action) {
_this.onEvent(event);
- var namesArr = _this.getSelectedNames(event.ctrlKey);
+ var namesArr = _this.getSelectedNames(event.ctrlKey, event.shiftKey);
transferData.data = new TransferData();
transferData.data.addDataForFlavour("text/unicode", namesArr.join(', '));
return true;
+ },
+
+ onDrop : function (event, transferData, session) {
+ var path, pos;
+ var data = transferData;
+ if (transferData.flavour.contentType == "text/unicode")
+ path = new String(transferData.data).trim();
+ else
+ return false;
+ pos = _this.searchPaths.indexOf(path);
+ if (pos == -1) return false;
+
+ document.getElementById("sciviews_robjects_searchpath_listbox")
+ .getItemAtIndex(pos).checked = true;
+ _addObjectList(path);
+ return true;
+ },
+
+ onDragOver : function(event, flavour, session) {
+ session.canDrop = flavour.contentType == 'text/unicode'
+ || flavour.contentType == 'text/x-r-package-name';
+ },
+
+ getSupportedFlavours : function () {
+ var flavours = new FlavourSet();
+ flavours.appendFlavour("text/x-r-package-name");
+ flavours.appendFlavour("text/unicode");
+ return flavours;
}
};
@@ -1027,7 +1040,6 @@
};
-
this.refreshAll = function () {
var selectedPackages = new Array(_this.treeData.length);
for (var i = 0; i < selectedPackages.length; i++)
@@ -1048,8 +1060,8 @@
this.removeSelected = function(doRemove) {
var item, type, name, vItem, cmd = [];
var rmItems = {}, ObjectsToRemove = {}, envToDetach = [], ObjectsToSetNull = {};
-
var rows = this.getSelectedRows();
+ if (rows.length == 0) return false;
for (i in rows) {
vItem = this.visibleData[rows[i]];
@@ -1086,9 +1098,7 @@
if (type == "sub-object") {
if (typeof ObjectsToSetNull[env] == "undefined")
ObjectsToSetNull[env] = [];
-
ObjectsToSetNull[env].push(name);
-
} else {
if (typeof ObjectsToRemove[env] == "undefined")
ObjectsToRemove[env] = [];
@@ -1116,7 +1126,6 @@
break;
}
}
-
}
for (var env in ObjectsToRemove)
@@ -1128,25 +1137,24 @@
_createVisibleData();
+ if (!cmd.length) return false;
+
if(doRemove) {
// remove immediately
sv.r.evalCallback(cmd.join("\n"), sv.cmdout.append);
} else {
// insert commands to current document
var view = ko.views.manager.currentView;
- if (!view)
- return false;
- view.setFocus();
-
+ if (!view) return false;
+ //view.setFocus();
var scimoz = view.scimoz;
-
- var nl = ["\r\n", "\n", "\r"][scimoz.eOLMode];
- scimoz.insertText(scimoz.currentPos, cmd.join(nl));
+ var nl = ";" + ["\r\n", "\n", "\r"][scimoz.eOLMode];
+ scimoz.scrollCaret();
+ scimoz.insertText(scimoz.currentPos, cmd.join(nl) + nl);
}
- //_this.selection.select(rows[0]);
- _this.selection.clearSelection();
-
+ _this.selection.select(Math.min(rows[0], _this.rowCount - 1));
+ //_this.selection.clearSelection();
return true;
}
@@ -1182,17 +1190,20 @@
}
this.insertName = function(fullNames, extended) {
+ //TODO: `quote` non-syntactic names of 1st level (.type = 'object')
+ // extended mode: object[c('sub1', 'sub2', 'sub3')]
var view = ko.views.manager.currentView;
- if (!view)
- return;
+ if (!view) return;
var text = _this.getSelectedNames(fullNames, extended).join(', ');
//view.setFocus();
var scimoz = view.scimoz;
var length = scimoz.length;
- if (scimoz.getWCharAt(scimoz.selectionStart - 1).search(/^[\w\.\u0100-\uFFFF"'`,\.;:=]$/) != -1)
+ if (scimoz.getWCharAt(scimoz.selectionStart - 1)
+ .search(/^[\w\.\u0100-\uFFFF"'`,\.;:=]$/) != -1)
text = " " + text;
- if (scimoz.getWCharAt(scimoz.selectionEnd).search(/^[\w\.\u0100-\uFFFF"'`]$/) != -1)
+ if (scimoz.getWCharAt(scimoz.selectionEnd)
+ .search(/^[\w\.\u0100-\uFFFF"'`]$/) != -1)
text += " ";
scimoz.insertText(scimoz.currentPos, text);
@@ -1392,9 +1403,7 @@
//document.getElementById("sciviews_robjects_objects_tree").focus();
event.originalTarget.focus();
}
-//fsplitbodymass.mosdyday
-
// drag & drop handling for search paths list
this.packageListObserver = {
onDrop : function (event, transferData, session) {
@@ -1406,15 +1415,51 @@
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/sciviews -r 157
More information about the Sciviews-commits
mailing list