[Sciviews-commits] r222 - in komodo/SciViews-K: content content/js content/js/tools templates

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 9 11:53:41 CET 2009


Author: prezez
Date: 2009-11-09 11:53:39 +0100 (Mon, 09 Nov 2009)
New Revision: 222

Added:
   komodo/SciViews-K/templates/svStart.R
Modified:
   komodo/SciViews-K/content/RHelpWindow.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/socket.js
   komodo/SciViews-K/content/js/tools/file.js
   komodo/SciViews-K/templates/.Rprofile
Log:
Workaround for a bug on Linux (Bug #685) with infinite reloading of .Rprofile.
Lots of changes to .Rprofile, most code (temporarily?) moved to svStart.R (a new file).
sv.file.path - allows now to get Komodo specific directories (with koDirs XPCOM).
sv.cmdout.message - now shows message on status bar
sv.version - now updates automatically. Change in type of argument that sv.checkVersion accepts (string rather than a number), please update that in all macros!









Modified: komodo/SciViews-K/content/RHelpWindow.xul
===================================================================
--- komodo/SciViews-K/content/RHelpWindow.xul	2009-11-06 15:51:49 UTC (rev 221)
+++ komodo/SciViews-K/content/RHelpWindow.xul	2009-11-09 10:53:39 UTC (rev 222)
@@ -231,20 +231,21 @@
 	var selText = sv.tools.strings.trim(window._content.getSelection()
 				.toString());
 
-	if (selText) {
-		var el = document.getElementById("cmd_rsearch_for");
-		el.setAttribute("label", sv.translate("Search R for \"%S\"",
-										  selText.substr(0, 10) + (selText.length > 10? "..." : "")));
+	var el = document.getElementById("cmd_rsearch_for");
+	var elLabel;
 
-		document.getElementById("cmd_rsearch_for").hidden = false;
-		document.getElementById("cmd_run_r_code").hidden = false;
+	var nothingSelected = !selText;
+
+	if (nothingSelected) {
+		elLabel = sv.translate("No selection");
 	} else {
-		document.getElementById("cmd_rsearch_for").hidden = true;
-		document.getElementById("cmd_run_r_code").hidden = true;
+		elLabel = sv.translate("Search R for \"%S\"",
+			selText.substr(0, 10) + (selText.length > 10? "..." : ""));
 	}
+	el.setAttribute("label", elLabel);
+	el.setAttribute("disabled", nothingSelected);
+	document.getElementById("cmd_run_r_code").setAttribute("disabled", nothingSelected);
 
-
-
 }
 
 function runSelAsRCode() {
@@ -446,7 +447,7 @@
     <key id="key_find_next" keycode="VK_F3" command="cmd_find_next" modifiers="" />
     <key id="key_go_back" keycode="VK_BACK" command="cmd_go_back" modifiers="" />
     <key id="key_go_home" keycode="VK_HOME" command="cmd_go_home" modifiers="alt" />
-    <key id="key_run_r_code" keycode="R" command="cmd_run_r_code" modifiers="accel" />
+    <key id="key_run_r_code" key="R" command="cmd_run_r_code" modifiers="accel" />
 </keyset>
 
 <commandset id="commandset_main">

Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js	2009-11-06 15:51:49 UTC (rev 221)
+++ komodo/SciViews-K/content/js/commands.js	2009-11-09 10:53:39 UTC (rev 222)
@@ -97,8 +97,7 @@
 			["extensions", "sciviewsk at sciviews.org", "templates"]);
 		var command, runIn = "no-console";
 
-		ko.statusBar.AddMessage(sv.translate("Starting R... please wait"),
-			"StartR", 10000, true);
+		sv.cmdout.message(sv.translate("Starting R... please wait"), 10000, true);
 		switch (preferredRApp) {
 			case "r-gui":
 				env.push("Rid=Rgui");
@@ -451,7 +450,7 @@
 		// Make these commands active only when current document language is R
 		var cmdsIfIsRView = ["RunAll", "SourceAll", "RunBlock", "RunFunction",
 			"RunLine", "RunPara", "SourceBlock", "SourceFunction", "SourcePara",
-			"RunLineOrSelection"];
+			"RunLineOrSelection", "SourceLineOrSelection"];
 
 		// ... and if some text is selected
 		var cmdsIfIsRViewAndSelection = ["RunSelection", "SourceSelection"];
@@ -483,6 +482,7 @@
 			}, 100);
 		};
 
+		//TODO: check if R is working before any command is sent, rather than continously
 		_keepCheckingR();
 
 		// This is no longer needed:

Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js	2009-11-06 15:51:49 UTC (rev 221)
+++ komodo/SciViews-K/content/js/r.js	2009-11-09 10:53:39 UTC (rev 222)
@@ -129,7 +129,7 @@
 		if (wasRRunning != isRRunning) {
 			if (isRRunning) {
 				// Remove message in the statusbar
-				ko.statusBar.AddMessage("", "StartR");
+				sv.cmdout.message("");
 				// update character set used by R
 				sv.socket.updateCharset(true);
 				window.setTimeout(function() {
@@ -173,7 +173,8 @@
 	// If R is not running, start it now
 	if (!sv.r.running) {
 		// Indicate R should be started
-		ko.statusBar.AddMessage(sv.translate("R must be started for this command (R -> Start R)"), "Rstart", 5000, true, true);
+		sv.cmdout.message(sv.translate("R must be started for this command (R -> Start R)"),
+						  5000, true);
 		// Indicate that we want to execute this command when R is started
 		//sv.r.pendingCmd = cmd;
 		// and start R now
@@ -227,7 +228,7 @@
 	// If R is not running, do nothing
 	if (!sv.r.running) {
 		// Indicate R should be started
-		ko.statusBar.AddMessage("R must be started for this command (R -> Start R)", "Rstart", 5000, true, true);
+		sv.cmdout.message("R must be started for this command (R -> Start R)", 5000, true);
 		// Indicate that we want to execute this command when R is started
 		// We don't use this any more if R is not started automatically
 		//... but we keep it for now for a future implementation using okCancel
@@ -521,7 +522,7 @@
 //TODO: make private
 sv.r.calltip_show = function (tip) {
 	if (tip != "") {
-		//ko.statusBar.AddMessage(tip, "R", 2000, true);
+		//sv.cmdout.message(tip, 2000, true);
 		var ke = ko.views.manager.currentView.scimoz;
 		ke.callTipCancel();
 		ke.callTipShow(ke.anchor, tip.replace(/[\r\n]+/g, "\n"));
@@ -614,8 +615,7 @@
 		topic = sv.getTextRange("word");
 
 	if (topic == "")
-		ko.statusBar.AddMessage(sv.translate("Selection is empty..."), "R",
-			1000, false);
+		sv.cmdout.message(sv.translate("Selection is empty..."), 1000);
 
 	if (!topic && !pkg) {
 		return false;
@@ -627,8 +627,8 @@
 		// Old version for R < 2.10: cmd = 'cat(unclass(help(' + cmd + ' htmlhelp = TRUE)))';
 		// TODO: error handling when package does not exists
 		res = sv.r.evalCallback(cmd, sv.command.openHelp);
-		ko.statusBar.AddMessage(sv.translate("R help asked for \"%S\"", topic),
-			"R", 5000, true);
+		sv.cmdout.message(sv.translate("R help asked for \"%S\"", topic),
+						  5000, true);
 	}
 	return res;
 }
@@ -640,12 +640,11 @@
 	if (typeof(topic) == "undefined" | topic == "")
 		topic = sv.getTextRange("word");
 	if (topic == "") {
-		ko.statusBar.AddMessage(sv.translate("Selection is empty..."), "R",
-			1000, false);
+		sv.cmdout.message(sv.translate("Selection is empty..."), 1000, false);
 	} else {
 		res = sv.r.eval("example(" + topic + ")");
-		ko.statusBar.AddMessage(sv.translate("R example run for \"%S\"", topic),
-			"R", 5000, true);
+		sv.cmdout.message(sv.translate("R example run for \"%S\"", topic),
+			5000, true);
 	}
 	return(res);
 }
@@ -665,8 +664,8 @@
 		// Get list of matching items and evaluate it with sv.r.search_select()
 		res = sv.r.evalCallback('cat(apropos("' + topic + '"), sep = "' +
 			sv.r.sep + '")', sv.r.search_select);
-		ko.statusBar.AddMessage(sv.translate("Searching_R_help_for", topic),
-			"R", 5000, true);
+		sv.cmdout.message(sv.translate("Searching_R_help_for", topic),
+			5000, true);
 	}
 	return(res);
 }
@@ -688,7 +687,7 @@
 // The callback for sv.r.search
 //TODO: make private
 sv.r.search_select = function (topics) {
-	ko.statusBar.AddMessage("", "R");
+	sv.cmdout.message("");
 	var res = false;
 	if (sv.tools.strings.removeLastCRLF(topics) == "") {
 		sv.cmdout.message(sv.translate("R help for %S not found.", topics));
@@ -730,8 +729,7 @@
 	}
 
 	if (!topic) {
-		ko.statusBar.AddMessage(sv.translate("Selection is empty..."), "R",
-			1000, false);
+		sv.cmdout.message(sv.translate("Selection is empty..."), 1000, false);
 		return;
 	}
 
@@ -764,14 +762,14 @@
 	res = sv.r.evalCallback('.tmp <- data();' +
 		'cat(paste(.tmp$results[, "Item"], .tmp$results[, "Title"],' +
 		' sep = "\t  -  "), sep = "\n"); rm(.tmp)', sv.r.data_select);
-	ko.statusBar.AddMessage("Listing available R datasets... please wait",
-		"R", 20000, true);
+	sv.cmdout.message(sv.translate("Listing available R datasets... please wait"),
+		20000, true);
 	return(res);
 }
 
 // The callback for sv.r.data
 sv.r.data_select = function (data) {
-	ko.statusBar.AddMessage("", "R");
+	sv.cmdout.message("");
 	var res = false;
 	if (sv.tools.strings.removeLastCRLF(data) == "") {
 		sv.alert("Problem retrieving the list of R datasets!");
@@ -919,14 +917,14 @@
 	  '")) paste(x, "\t     ",  sub("[\t\n\r].*$", "", ' +
 	  'comment(get(x))), sep = ""), silent = TRUE))), sep = ",,,")',
 	  sv.r.obj_select);
-	ko.statusBar.AddMessage("Listing available '" + objClass +
-		"'... please wait", "R", 20000, true);
+	sv.cmdout.message("Listing available '" + objClass +
+		"'... please wait", 20000, true);
 	return(res);
 }
 
 // The callback for sv.r.obj
 sv.r.obj_select = function (data) {
-	ko.statusBar.AddMessage("", "R");
+	sv.cmdout.message("");
 	var res = false;
 	if (sv.tools.strings.removeLastCRLF(data) == "") {
 		sv.alert("Select R objects", "Problem retrieving the list of objects!");
@@ -982,8 +980,7 @@
 	// Get currently active 'lm' object
 	var lm = sv.prefs.getString("r.active.lm", "<none>")
 	if (lm == "<lm>") lm = "<none>";
-	ko.statusBar.AddMessage("R session: " + ses + ", data: " + df +
-		", linear model: " + lm, "Rstatus", 0, false);
+	sv.cmdout.message(sv.translate("R session: %S  data: %S linear model: %S", ses, df, lm));
 }
 
 // Select one data frame
@@ -1005,7 +1002,7 @@
 
 // Callback for sv.r.obj_select_dataframe to refresh the associated MRUs
 sv.r.obj_refresh_dataframe = function (data) {
-	ko.statusBar.AddMessage("", "R");
+	sv.cmdout.message("");
 	// If we got nothing, then the object does not exists any more... clear MRUs
 	if (data == "<<<data>>>") {
 		//var oldobj = sv.prefs.getString("r.active.data.frame", "");
@@ -1081,7 +1078,7 @@
 
 // Callback for sv.r.obj_select to refresh the MRUs associated with lm objects
 sv.r.obj_refresh_lm = function (data) {
-	ko.statusBar.AddMessage("", "R");
+	sv.cmdout.message("");
 	// If we got nothing, then the object does not exists any more... clear MRUs
 	if (data == "<<<data>>>") {
 		//var oldobj = sv.prefs.getString("r.active.lm", "");
@@ -1263,8 +1260,8 @@
 	// TODO: run first in R; make dirs in R; then change in Komodo!
 	sv.r.evalCallback(cmd, function(data) {
 		// Indicate everything is fine
-		ko.statusBar.AddMessage("R session directory set to '" + dir + "'",
-			"R", 20000, true);
+		sv.cmdout.message(sv.translate("R session directory set to '%S'", dir),
+			20000, true);
         // Break possible partial multiline command in R from previous session
         // and indicate that we are in a new session now in the R console
         // TODO: report if we load something or not
@@ -1435,7 +1432,7 @@
 	// Quit R
 	sv.r.eval('q("' + response.toLowerCase() + '")');
 	// Clear the R-relative statusbar message
-	ko.statusBar.AddMessage("", "Rstatus");
+	sv.cmdout.message("");
 	// Clear the objects browser
 	sv.r.objects.clearPackageList();
 }
@@ -1475,8 +1472,8 @@
 					sv.translate("Select CRAN mirror to use:"), names, "one");
 
 				repos = urls[names.indexOf(items[0])].replace(/\/$/, "");
-				ko.statusBar.AddMessage(sv.translate("Current CRAN mirror is set to %S",
-					repos), "R", 5000, false);
+				sv.cmdout.message(sv.translate("Current CRAN mirror is set to %S",
+					repos), 5000, false);
 
 				sv.r.eval('with(TempEnv(), { repos <- getOption("repos");' +
 						  'repos["CRAN"] <- "' + repos + '"; ' +
@@ -1488,9 +1485,8 @@
 			}
 			return(res);
 		});
-	ko.statusBar.AddMessage(
-		sv.translate("Retrieving CRAN mirrors list... please wait."), "R",
-		20000, true);
+	sv.cmdout.message(sv.translate("Retrieving CRAN mirrors list... please wait."),
+					  20000, true);
 	return(res);
 }
 
@@ -1499,8 +1495,8 @@
 sv.r.pkg.available = function () {
 	var res = sv.r.eval('.pkgAvailable <- available.packages()\n' +
 		'as.character(.pkgAvailable[, "Package"])');
-	ko.statusBar.AddMessage("Looking for available R packages... please wait",
-		"R", 5000, true);
+	sv.cmdout.message(sv.translate("Looking for available R packages... please wait"),
+		5000, true);
 	return(res);
 }
 
@@ -1508,16 +1504,16 @@
 sv.r.pkg.installed = function () {
 	var res = sv.r.eval('.pkgInstalled <- installed.packages()\n' +
 		'as.character(.pkgInstalled[, "Package"])');
-	ko.statusBar.AddMessage("Looking for installed R packages... please wait",
-		"R", 5000, true);
+	sv.cmdout.message(sv.translate("Looking for installed R packages... please wait"),
+		5000, true);
 	return(res);
 }
 
 // List new packages in the repositories
 sv.r.pkg.new = function () {
 	var res = sv.r.eval('(.pkgNew <- new.packages())');
-	ko.statusBar.AddMessage("Looking for new R packages... please wait",
-		"R", 5000, true);
+	sv.cmdout.message(sv.translate("Looking for new R packages... please wait"),
+		5000, true);
 	return(res);
 }
 
@@ -1525,24 +1521,23 @@
 sv.r.pkg.old = function () {
 	var res = sv.r.eval('.pkgOld <- old.packages()\n' +
 		'noquote(.pkgOld[, c("Installed", "ReposVer")])');
-	ko.statusBar.AddMessage("Looking for old R packages... please wait",
-		"R", 5000, true);
+	sv.cmdout.message(sv.translate("Looking for old R packages... please wait"),
+		5000, true);
 	return(res);
 }
 
 // Update installed packages
 sv.r.pkg.update = function () {
 	var res = sv.r.eval('update.packages(ask = "graphics")');
-	ko.statusBar.AddMessage("Updating R packages... please wait",
-		"R", 5000, true);
+	sv.cmdout.message(sv.translate("Updating R packages... please wait"), 5000, true);
 	return(res);
 }
 
 // Some statistics about R packages
 sv.r.pkg.status = function () {
 	var res = sv.r.eval('(.pkgStatus <- packageStatus())');
-	ko.statusBar.AddMessage("Compiling R packages status... please wait",
-		"R", 5000, true);
+	sv.cmdout.message(sv.translate("Compiling R packages status... please wait"),
+		5000, true);
 	return(res);
 }
 
@@ -1555,14 +1550,14 @@
 // Load one R package
 sv.r.pkg.load = function () {
 	var res = false;
-	ko.statusBar.AddMessage(sv.translate("ListingPackages"),
-		"R", 20000, true);
+	sv.cmdout.message(sv.translate("ListingPackages"),
+		20000, true);
 
 	// Get list of installed R packages that are not loaded yet
 	res = sv.r.evalCallback('.tmp <- .packages(all.available = TRUE);' +
 		'cat(.tmp[!.tmp %in% .packages()], sep = "' + sv.r.sep + '"); rm(.tmp)',
 		function (pkgs) {
-			ko.statusBar.AddMessage("", "R");
+			sv.cmdout.message("");
 			var res = false;
 			if (pkgs.trim() == "") {
 				sv.alert("All installed R packages seem to be already loaded!");
@@ -1594,15 +1589,15 @@
 	res = sv.r.evalCallback('.tmp <- .packages(); cat(.tmp[!.tmp %in%' +
 		' c(if (exists(".required")) .required else NULL, "base")],' +
 		' sep = "' + sv.r.sep + '"); rm(.tmp)', sv.r.pkg.unload_select);
-	ko.statusBar.AddMessage("Listing loaded R packages... please wait",
-		"R", 20000, true);
+	sv.cmdout.message(sv.translate("Listing loaded R packages... please wait"),
+		20000, true);
 	return(res);
 }
 
 // The callback for sv.r.pkg.unload
 //TODO: make private
 sv.r.pkg.unload_select = function (pkgs) {
-	ko.statusBar.AddMessage("", "R");
+	sv.cmdout.message("");
 	var res = false;
 	if (sv.tools.strings.removeLastCRLF(pkgs) == "") {
 		sv.alert("None of the loaded packages are safe to unload!");
@@ -1628,17 +1623,17 @@
 		' "svMisc", "svIDE", "svGUI", "svSocket", "svIO", "svViews",' +
 		' "svWidgets", "svDialogs")], sep = "' + sv.r.sep + '"); rm(.tmp)',
 		sv.r.pkg.remove_select);
-	ko.statusBar.AddMessage("Listing removable R packages... please wait",
-		"R", 20000, true);
+	sv.cmdout.message(sv.translate("Listing removable R packages... please wait"),
+		20000, true);
 	return(res);
 }
 
 // The callback for sv.r.pkg.remove
 sv.r.pkg.remove_select = function (pkgs) {
-	ko.statusBar.AddMessage("", "R");
+	sv.cmdout.message("");
 	var res = false;
 	if (sv.tools.strings.removeLastCRLF(pkgs) == "") {
-		sv.alert("None of the installed R packages are safe to remove!");
+		sv.alert(sv.translate("None of the installed R packages are safe to remove!"));
 	} else {	// Something is returned
 		var items = pkgs.split(sv.r.sep);
 		// Select the item you want in the list

Modified: komodo/SciViews-K/content/js/sciviews.js
===================================================================
--- komodo/SciViews-K/content/js/sciviews.js	2009-11-06 15:51:49 UTC (rev 221)
+++ komodo/SciViews-K/content/js/sciviews.js	2009-11-09 10:53:39 UTC (rev 222)
@@ -3,8 +3,7 @@
 // Copyright (c) 2008-2009, Ph. Grosjean (phgrosjean at sciviews.org)
 // License: MPL 1.1/GPL 2.0/LGPL 2.1
 ////////////////////////////////////////////////////////////////////////////////
-// sv.version; // Get current SciViews-K version (major.minor)
-// sv.release; // The release (bug fixes). Full version is "version.release"
+// sv.version; // Get current SciViews-K version (major.minor.release)
 // sv.showVersion; // Do we display version in an alert() box or just set it?
 // sv.checkVersion(version); // Check the SciViews-K extension version is fine
 //
@@ -46,45 +45,68 @@
 // Not used any more?
 // sv.checkToolbox(); // Check that the correct SciViews-K toolbox is installed
 
-// Commented out, not used.
-// 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)
+////////////////////////////////////////////////////////////////////////////////
 
-// replaced by sv.getTextRange("word")
-// sv.getText(); // Get current selection, or word under the cursor
 
-////////////////////////////////////////////////////////////////////////////////
 
-if (typeof(sv) == 'undefined') {
-	var sv = {
-		// TODO: set this automatically according to the plugin version
-		version: 0.9,
-		release: 7,
-		showVersion: true,
-		checkVersion: function (version) {
-			if (this.version < version) {
-				var title = "SciViews-K"
-				var prompt = "Outdated SciViews-K extension..."
-				var text = "One or more macros require the SciViews-K plugin "
-				text += version + ".x"
-				text += " but the currently installed version is "
-				text += this.version + "." + this.release
-				text += ". You should update it."
-				text += " Would you like to open the extension manager"
-				text += " and check for available updates now?"
-				var res = ko.dialogs.yesNo(prompt, "Yes", text, title);
-				if (res == "Yes") ko.launch.openAddonsMgr();
-				return(false);
-			} else return(true);
+if (typeof(sv) == 'undefined') sv = {};
+
+// Create the 'sv.tools' namespace
+if (typeof(sv.tools) == 'undefined') sv.tools = {};
+
+// IMPORTANT: now sv.version is a "X.X.X" string, and sv.checkVersion accepts only such format
+// please update all macros using sv.checkVersion 
+sv.version = Components.classes["@mozilla.org/extensions/manager;1"]
+				.getService(Components.interfaces.nsIExtensionManager)
+				.getItemForID("sciviewsk at sciviews.org").version;
+sv.showVersion = true;
+
+sv._compareVersion = function (a, b) {
+    if (!a)	return -1;
+    if (!b)	return 1;
+
+	// try is necessary only till I find where is that damn macro causing an error
+	// at startup (-;
+	try {
+		a = a.split(/[.\-]/);
+		for (i in a) a[i] = parseInt(a[i]);
+		b = b.split(/[.\-]/);
+		for (i in b) b[i] = parseInt(b[i]);
+
+		for (k in a) {
+			if (k < b.length) {
+				if (a[k] > b[k])
+					return 1;
+				else if (a[k] < b[k])
+					return -1;
+			} else {
+				return 1;
+			}
 		}
-	};
+	   return (b.length > a.length)? -1 : 0;
+	} catch(e) {
+		return 1;
+	}
 }
 
-// Create the 'sv.tools' namespace
-if (typeof(sv.tools) == 'undefined') sv.tools = new Object();
+sv.checkVersion = function (version) {
+	if (sv._compareVersion(sv.version, version) < 0) {
+		var text = sv.translate(
+"One or more macros require the SciViews-K plugin %S, " +
+"but currently installed version is %S. You should update it." +
+"Would you like to open the extension manager and check for updates now?",
+version, this.version);
 
+		var sYes = sv.translate("Yes");
+		var res = ko.dialogs.yesNo(sv.translate("Outdated SciViews-K extension"),
+			sYes, text, "SciViews-K");
+		if (res == sYes) 	ko.launch.openAddonsMgr();
+		return(false);
+	} else
+		return(true);
+}
 
+
 //// Other functions directly defined in the 'sv' namespace ////////////////////
 // Our own alert box
 sv.alert = function (header, text) {
@@ -95,41 +117,10 @@
 //sv.alert("Message");
 
 // Gets current selection, or word under the cursor in the active buffer
+//DEPRECATED, use sv.getTextRange
 sv.getText = function (includeChars) sv.getTextRange("word", false, false, null, includeChars);
 
-// NOT USED ANYMORE
-//// Get current line of text in the active buffer
-//sv.getLine = function () {
-//	var kv = ko.views.manager.currentView;
-//	if (!kv) return("");
-//	kv.setFocus();
-//	var ke = kv.scimoz;
-//	// retain these so we can reset the selection after the replacement
-//	var curAnchor = ke.anchor;
-//	var curPos = ke.currentPos;
-//	// Get the text in the current line
-//	ke.home();
-//	ke.lineEndExtend();
-//	var currentLine = ke.selText;
-//	// Reset the selection
-//	ke.setSel(curAnchor, curPos);
-//	// Return the content of the current line
-//	return(currentLine);
-//}
-
-// NOT USED ANYMORE
 // Select a part of text in the current buffer and return it
-//sv.getPart = function (what, resel, clipboard) {
-//	var range;
-//	var text = sv.getTextRange(what, false, !resel, range);
-//	if (clipboard) {
-//		// Copy to clipboard instead of returning the text
-//		ke.copyRange(range.value.start, range.value.end);
-//	}
-//	return(text);
-//}
-
-// Select a part of text in the current buffer and return it
 // differs from sv.getPart that it does not touch the selection
 sv.getTextRange = function (what, gotoend, select, range, includeChars) {
 
@@ -323,7 +314,6 @@
         // This is used by calltip and completion. Returns all text backwards from current
 		// position to the beginning of the current folding level
         pStart = scimoz.positionFromLine(scimoz.getFoldParent(curLine));
-
 	case "all":
 	default:
 	   // Take everything
@@ -561,7 +551,6 @@
 	}
 }
 
-
 //// Control the command output tab ////////////////////////////////////////////
 if (typeof(sv.cmdout) == 'undefined') sv.cmdout = {};
 
@@ -623,26 +612,36 @@
         sv.log.exception(e, "Problems clearing the Command Output pane", true);
     }
 }
+// Display message on the status bar (default) or command output bar
+sv.cmdout.message = function (msg, timeout, highlight, outputBar) {
+	if (outputBar) {
+		document.getElementById('output_tabpanels').selectedIndex = 0;
+		var runoutputDesc = document.getElementById('runoutput-desc');
+		if (msg == null) msg = "";
 
-// Display message on the command output bar
-sv.cmdout.message = function (msg, timeout) {
-	document.getElementById('output_tabpanels').selectedIndex = 0;
-	var runoutputDesc = document.getElementById('runoutput-desc');
-	if (msg == null) msg = "";
-	runoutputDesc.style.color = "rgb(0, 0, 0)";
-	runoutputDesc.setAttribute("value", msg);
-	window.clearTimeout(runoutputDesc.timeout);
-	if (timeout > 0)
-		runoutputDesc.timeout = window.setTimeout("sv.cmdout.message();",
-            timeout);
+		runoutputDesc.parentNode.style.backgroundColor =
+			(highlight && msg) ? "highlight" : "";
+
+		runoutputDesc.style.color = "rgb(0, 0, 0)";
+		runoutputDesc.setAttribute("value", msg);
+		window.clearTimeout(runoutputDesc.timeout);
+		if (timeout > 0)
+			runoutputDesc.timeout = window.setTimeout("sv.cmdout.message('', 0, null, true);",
+				timeout);
+	} else {
+		ko.statusBar.AddMessage(msg, "SciViews-K info", timeout, highlight);
+	}
 }
 
 
 //// Logging management ////////////////////////////////////////////////////////
+if (typeof(sv.log) == 'undefined')
+	sv.log = ko.logging.getLogger("SciViews-K");
 
 
-if (typeof(sv.log) == 'undefined')
-	sv.log = {};
+//const LOG_NOTSET = 0;	//const LOG_DEBUG = 10;	//const LOG_INFO = 20;
+//const LOG_WARN = 30; 	//const LOG_ERROR = 40;	//const LOG_CRITICAL = 50;
+// ko.logging.LOG_*
 
 (function () {
 	var logger = ko.logging.getLogger("SciViews-K");
@@ -701,6 +700,7 @@
 
 
 
+
 //// Tests... default level do not print debug and infos!
 //sv.log.all(false);
 //alert(sv.log.isAll());
@@ -725,7 +725,6 @@
 //// Show Komodo log
 //sv.log.show();
 
-
 //// Not used any more? ////////////////////////////////////////////////////////
 // Note: this is bit dangerous in its present form, removes current SciViews-K toolbox
 // without notice, all modifications are lost.
@@ -784,4 +783,3 @@
 // Ensure we check the toolbox is installed once the extension is loaded
 //addEventListener("load", function() {setTimeout (sv.checkToolbox, 5000) }, false);
 //addEventListener("load", sv.checkToolbox, false);
-//@

Modified: komodo/SciViews-K/content/js/socket.js
===================================================================
--- komodo/SciViews-K/content/js/socket.js	2009-11-06 15:51:49 UTC (rev 221)
+++ komodo/SciViews-K/content/js/socket.js	2009-11-09 10:53:39 UTC (rev 222)
@@ -181,8 +181,7 @@
 
 		// if exception was returned:
 		if (res && res.name && res.name == "NS_ERROR_OFFLINE") {
-			ko.statusBar.AddMessage("Error: R is unreachable (see log)", "R",
-				5000, true);
+			sv.cmdout.message("Error: R is unreachable (see log)", 5000, true);
 		}
 		return(res);
 
@@ -325,9 +324,9 @@
 			// "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame ::
 			// chrome://sciviewsk/content/js/socket.js :: anonymous :: line 285
 		}
-		if (this.debug) sv.log.debug("Socket server started");
-		ko.statusBar.AddMessage("SciViews-K socket server started", "svSock",
-			2000, true);
+		if (this.debug)
+			sv.log.debug("Socket server started");
+		sv.cmdout.message("SciViews-K socket server started", 2000, true);
 	}
 
 	// Stop the SciViews-K socket server
@@ -342,11 +341,9 @@
 
 			_serverStarted = false;
 			if (this.debug) sv.log.debug("Socket server stopped");
-			ko.statusBar.AddMessage("SciViews-K socket server stopped",
-				"svSock", 2000, true);
+			sv.cmdout.message("SciViews-K socket server stopped", 2000, true);
 		} else {
-			ko.statusBar.AddMessage("SciViews-K socket server is not started",
-				"svSock", 2000, true);
+			sv.cmdout.message("SciViews-K socket server is not started", 2000, true);
 		}
 	}
 

Modified: komodo/SciViews-K/content/js/tools/file.js
===================================================================
--- komodo/SciViews-K/content/js/tools/file.js	2009-11-06 15:51:49 UTC (rev 221)
+++ komodo/SciViews-K/content/js/tools/file.js	2009-11-09 10:53:39 UTC (rev 222)
@@ -149,23 +149,30 @@
 		var file, baseFile;
 		if (baseDir) {
 			try {
-				file = Components.classes["@mozilla.org/file/directory_service;1"].
-					getService(Components.interfaces.nsIProperties).
-					get(baseDir, Components.interfaces.nsILocalFile);
-			} catch(e) {
-				// I don't want to log an exception here, since I try another
-				// method just below!
-				//sv.log.exception(e, "sv.tools.file.getfile: get " + baseDir);
-				file = Components.classes["@mozilla.org/file/local;1"].
-					createInstance(Components.interfaces.nsILocalFile);
 				try {
-					file.initWithPath(baseDir);
-				} catch (e) {
-					sv.log.exception(e,
-						"sv.tools.file.getfile: file.initWithPath(" + baseDir + ")");
-					return null;
+					file = Components.classes["@mozilla.org/file/directory_service;1"]
+						.getService(Components.interfaces.nsIProperties).
+						get(baseDir, Components.interfaces.nsILocalFile);
+				} catch(e) {
+					// if above fails, try Komodo directories too:
+					var dirs = Components.classes['@activestate.com/koDirs;1']
+						.getService(Components.interfaces.koIDirs);
+					baseDir = dirs[baseDir];
+
+				} finally { };
+
+				if (!file) {
+					file = Components.classes["@mozilla.org/file/local;1"].
+							createInstance(Components.interfaces.nsILocalFile);
+					try {
+							file.initWithPath(baseDir);
+					} catch (e) {
+						sv.log.exception(e,
+							"sv.tools.file.getfile: file.initWithPath(" + baseDir + ")");
+						return null;
+					}
 				}
-			}
+			} catch(e) {	}
 		}
 		if (pathComponents && pathComponents.length) {
 			for (i in pathComponents) {
@@ -195,16 +202,16 @@
 			if (!pathComponents)
 				pathComponents = [];
 			else if (typeof pathComponents == "string") {
-				var pc = [];
-				for (var i = 1; i < arguments.length; i++)
-					if (typeof arguments[i] != "undefined")
-						pc.push(arguments[i]);
+				var pc = Array.apply(null, arguments);
+				pc.shift(1);
 				pathComponents = pc;
 			}
 
-			var pathSep = Components.classes['@activestate.com/koOs;1'].
-				getService(Components.interfaces.koIOs).sep;
+			var os = Components.classes['@activestate.com/koOs;1'].
+				getService(Components.interfaces.koIOs);
 
+			var pathSep = os.sep;
+
 			baseDir = baseDir.replace(/[\\/]+/g, pathSep);
 			if (baseDir[0] == "~") {
 				pathComponents.unshift(baseDir.replace(/^~[\\/]*/, ""));

Modified: komodo/SciViews-K/templates/.Rprofile
===================================================================
--- komodo/SciViews-K/templates/.Rprofile	2009-11-06 15:51:49 UTC (rev 221)
+++ komodo/SciViews-K/templates/.Rprofile	2009-11-09 10:53:39 UTC (rev 222)
@@ -1,562 +1,5 @@
-### SciViews install begin ###
-# SciViews-R installation and startup for running R with Komodo/SciViews-K
-# Version 0.9.6, 2009-11-03 Ph. Grosjean (phgrosjean at sciviews.org)
-
-#TODO: Include all this as a function in svMisc??
-#TODO: [KB] Fix problem with installing sv* packages when not running R as root.
-#      R tries to install them forever, and finally crashes my Ubuntu (Bug #685)
-
-# Make sure we don't process this twice in case of duplicate items in .Rprofile
-svStart <- function(){
-# [KB] Wrapped this in a function, so we can be sure it does not leave any garbage or
-#      overwrites user's objects.
-
-if (!exists(".SciViewsReady", envir = .GlobalEnv)) {
-
-	assign(".SciViewsReady", FALSE, .GlobalEnv)
-	minVersion <- c(R = "2.10.0", svMisc = "0.9-56", svSocket = "0.9-48", svGUI = "0.9-46")
-
-	# First of all, check R version... redefine compareVersion() because it is
-	# not defined in very old R versions... and thus we don't get an explicit
-	# error message in that particular case
-	checkVersion <- function (a, b) {
-		a <- as.integer(strsplit(a, "[\\.-]")[[1]])
-		b <- as.integer(strsplit(b, "[\\.-]")[[1]])
-		for (k in 1:length(a)) {
-			if (k <= length(b)) {
-				if (a[k] > b[k]) return(1)
-				else if (a[k] < b[k]) return(-1)
-			} else return(1)
-		}
-		if (length(b) > length(a)) return(-1) else return(0)
-	}
-	rVersion <- paste(R.Version()$major, R.Version()$minor, sep = ".")
-	res <- checkVersion(rVersion, minVersion["R"])
-	if (res < 0) {
-		res <- FALSE
-		cat("R is too old for this version of SciViews (R >=",
-			minVersion["R"], "is needed), please, upgrade it\n")
-	} else res <- TRUE
-
-	# Load main R packages (tools added to the list because now required by svMisc)
-	res <- all(sapply(c("methods", "datasets", "utils", "grDevices", "graphics", "stats", "tools"),
-				  function(x) require(x, quietly = TRUE, character.only = TRUE)))
-
-
-	# Get environment variables
-	if (res) {
-		args <- commandArgs()
-		# If started --quiet, display a simplified message
-		# but not if started -q, so that the user can still make it fully quiet!
-		par <- args[grep("^--quiet$", args)]
-		if (length(par) > 0) cat(R.version.string, "\n", sep = "")
-
-		# Collect SciViews socket client/server config from command line or vars
-		par <- args[grep("^--ko.serve=", args)]
-		if (length(par) == 0) par <- as.integer(Sys.getenv("koServe")) else
-			par <- as.integer(sub("^--ko.serve=", "", par))
-		if (is.na(par)) par <- 8888
-		options(ko.serve = par)		# Port used by the R socket server
-		par <- args[grep("^--ko.host=", args)]
-		if (length(par) == 0) par <- as.character(Sys.getenv("koHost")) else
-			par <- sub("^--ko.host=", "", par)
-		if (par == "") par <- "localhost"
-		options(ko.host = par)		# Machine where Komodo is running
-		par <- args[grep("^--ko.port=", args)]
-		if (length(par) == 0) par <- as.integer(Sys.getenv("koPort")) else
-			par <- as.integer(sub("^--ko.port=", "", par))
-		if (is.na(par)) par <- 7052
-		options(ko.port = par)		# Port used by the Komodo socket server
-		par <- args[grep("^--ko.id=", args)]
-		if (length(par) == 0) par <- as.character(Sys.getenv("koId")) else
-			par <- sub("^--ko.id=", "", par)
-		if (par == "") par <- "SciViewsK"
-		options(ko.id = par)		# The id used by Komodo
-		par <- args[grep("^--ko.activate=", args)]
-		if (length(par) == 0) par <- as.character(Sys.getenv("koActivate")) else
-			par <- sub("^--ko.activate=", "", par)
-		if (par == "") par <- "FALSE"
-		par <- (par[1] == "TRUE")
-		options(ko.activate = par)	# Do we reactivate Komodo?
-		par <- args[grep("^--R.id=", args)]
-		if (length(par) == 0) par <- as.character(Sys.getenv("Rid")) else
-			par <- sub("^--R.id=", "", par)
-		if (par == "") par <- "R"
- 		options(R.id = par)			# The id used for this R kernel in Komodo
-		par <- args[grep("^--R.initdir=", args)]
-		if (length(par) == 0) par <- as.character(Sys.getenv("Rinitdir")) else
-			par <- sub("^--R.initdir=", "", par)
-		# If the initial directory is "", or it does not exist or it is not a dir
-		# we use the default home directory instead!
-		if (par == "" || !file.exists(par) || !file.info(par)$isdir) par <- "~"
-		options(R.initdir = par)	# The initial directory to use for R
-		# Note: the initial directory is used to load/save workspace and history
-		rm(par)
-	}
-
-	# Load tcltk package
-	if (res) {
-		if (capabilities("tcltk")) {
-			# Make sure tcltk can start: on Mac OS X < 10.5 only,
-			# that is, darwin < 9, we need to check that X11 is installed
-			# (optional component!) and started!
-			# But this is not needed any more for R >= 2.8.0. Before we
-			# activate this test, we must find a way to start Tk later,
-			# when tktoplevel() is first invoked!
-			#if (checkVersion(rVersion, "2.8.0") < 0) {
-			if (regexpr("^darwin[5-8]", R.Version()$os) > -1) {
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/sciviews -r 222


More information about the Sciviews-commits mailing list