[Sciviews-commits] r331 - in komodo/SciViews-K/content: . js js/tools

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 5 13:20:43 CEST 2010


Author: prezez
Date: 2010-10-05 13:20:43 +0200 (Tue, 05 Oct 2010)
New Revision: 331

Modified:
   komodo/SciViews-K/content/js/commands.js
   komodo/SciViews-K/content/js/socket.js
   komodo/SciViews-K/content/js/tools/file.js
   komodo/SciViews-K/content/sessions.xul
Log:
sv.commands _setControllers: fixed a bug that caused blocking of some commands in Komodo.
sv.socket.rUpdate: restored charset updating
sv.tools.file.pathFromURI: new function
sessions.xul: Fixed: workspace was saved as history file. Session directory was not changed in R. 

Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js	2010-10-04 21:35:03 UTC (rev 330)
+++ komodo/SciViews-K/content/js/commands.js	2010-10-05 11:20:43 UTC (rev 331)
@@ -329,9 +329,12 @@
     function _setControllers () {
         //Based on: chrome://komodo/content/library/controller.js
         // backwards compatibility APIs
-        xtk.include("controller");
-        var Controller = xtk.Controller;
+		if(typeof Controller != "function") {
+			xtk.include("controller");
+			var Controller = xtk.Controller;
+		}
 
+
         const XRRunning = 1, XRStopped = 2, XisRDoc = 4, XHasSelection = 8;
         var handlers = {
                 'cmd_svOpenPkgManager': [ "sv.command.openPkgManager();", XRRunning ],
@@ -351,9 +354,6 @@
                 'cmd_svRSourceBlock': [ 'sv.r.source("block");',XisRDoc | XRRunning ],
                 'cmd_svRSourceFunction': [ 'sv.r.source("function");',XisRDoc | XRRunning ],
                 'cmd_svRSourcePara': [ 'sv.r.source("para");',XisRDoc | XRRunning ],
-                // PhG: this should really be sv.r.run(), which is supposed to be "more
-				// intelligent" and can be used to run code step by step because it
-				// moves the cursor to the next line each time...
 				'cmd_svRRunLineOrSelection': [ 'sv.r.run();', XisRDoc | XRRunning ],
                 'cmd_svRSourceLineOrSelection': [ 'sv.r.source("line/sel");', XisRDoc | XRRunning ],
                 'cmd_svRRunSelection': [ 'sv.r.send("sel");',XisRDoc | XRRunning | XHasSelection ],
@@ -364,7 +364,6 @@
         // Temporary
         function _isRRunning () {
             return true;
-
         }
 
         function _isRCurLanguage () {
@@ -392,15 +391,13 @@
         function svController() {}
 
         svController.prototype = new Controller();
-
         svController.prototype.constructor = svController;
-
         svController.prototype.destructor = function() { }
 
         svController.prototype.isCommandEnabled = function(command) {
-            if(!command in handlers) return(false);
-
+            if(!(command in handlers)) return(false);
 			return(true);
+		}
 
 			// TODO: Clean up the mess here.
             //var test = handlers[command][1];
@@ -429,7 +426,7 @@
 			//	&& (((test & XHasSelection) != XHasSelection) || _hasSelection()));
 
 			//return true;
-        }
+        //}
 
         svController.prototype.supportsCommand = svController.prototype.isCommandEnabled;
 
@@ -551,14 +548,7 @@
         //sv.log.debug("Keybindings has been applied.");
 	}
 
-	// Workaround for an apparent bug in Komodo 6.0.0-rc1, causing that some
-	// commands become inactive when _setControllers are run immediately
-	// "on load" (e.g. Save)
-	function _delayedSetControllers () {
-		window.setTimeout(_setControllers, 100);
-	}
+addEventListener("load", _setControllers, false);
+addEventListener("load", _setKeybindings, false);
 
-    addEventListener("load", _delayedSetControllers, false);
-    addEventListener("load", _setKeybindings, false);
-
 }).apply(sv.command);

Modified: komodo/SciViews-K/content/js/socket.js
===================================================================
--- komodo/SciViews-K/content/js/socket.js	2010-10-04 21:35:03 UTC (rev 330)
+++ komodo/SciViews-K/content/js/socket.js	2010-10-05 11:20:43 UTC (rev 331)
@@ -31,6 +31,8 @@
 // * A method to check svSocketMinVersion, and include this in rUpdate()
 // * Correct the crash problem when Komodo exits on Windows (connections not closed?)
 // * The interface must be made 100% compatible with the HTTP server
+// * Severe! On Windows the socket server is not reachable from R after Komodo is restarted
+//   while R is running already. Executing sv.socket.serverStart() does not help at all.
 
 // Define the 'sv.socket' namespace
 if (typeof(sv.socket) == 'undefined') sv.socket = {};
@@ -58,16 +60,27 @@
 		try { _converter.charset = charset; } catch (e) { }
 	return(_converter.charset);
 });
-this.charset = "UTF-8"; //svConverter.charset; // Already set at UTF-8 by default
+
+this.charset = "ASCII";
+//  KB: Makes no sense to set it to UTF-8 on non-unicode systems! Causes an error on
+//  a first call to rUpdate.
+//this.charset = "UTF-8"; //svConverter.charset; // Already set at UTF-8 by default
 									// in svRinterpreter.js
 
+//TODO: charcode is not updated when Komodo starts and R is already running. 
+// rUpdate should be run at Komodo startup, but how to figure out if R is running 
+// then???  
+// Perhaps save 'charcode' as a preference
+
 // The conversion functions
 function _fromUnicode (str, charset) {
-	if (charset !== undefined && _this.charset != charset) _this.charset = charset;
+	if (charset !== undefined && _this.charset != charset) 	_this.charset = charset;
 	try {
-		str = _converter.ConvertFromUnicode(str);
+		if (_converter.charset)
+			str = _converter.ConvertFromUnicode(str) + _converter.Finish();
 	} catch(e) {
-		sv.log.exception(e, "sv.socket is unable to convert from Unicode");
+		sv.log.exception(e, "sv.socket is unable to convert from Unicode to " +
+		 	_converter.charset + ". The string was " + str);
 	}
 	return(str);
 }
@@ -75,9 +88,11 @@
 function _toUnicode (str, charset) {
 	if (charset !== undefined && _this.charset != charset) _this.charset = charset;
 	try {
-		str = _converter.ConvertToUnicode(str);
+		if (_this.charset)
+			str = _converter.ConvertToUnicode(str);
 	} catch(e) {
-		sv.log.exception(e, "sv.socket is unable to convert from Unicode");
+		sv.log.exception(e, "sv.socket is unable to convert to Unicode from " +
+			_converter.charset + ". The string was " + str);
 	}
 	return(str);
 }
@@ -286,16 +301,19 @@
 // TODO: add the current working directory and report WD changes from R automagically
 this.rUpdate = function () {
 	// Make sure that dec and sep are correctly set in R
-	this.rCommand('<<<H>>>options(OutDec = "' +
+	this.rCommand('<<<h>>>options(OutDec = "' +
 		sv.prefs.getString("r.csv.dec", ".") +
 		'"); options(OutSep = "' +
 		sv.prefs.getString("r.csv.sep", ",") +
-		'"); invisible(guiRefresh(force = TRUE)); ' +
-		'cat("<<<charset=", localeToCharset()[1], ">>>", sep = "")',
+		'"); ' +
+		// ??? The following does not work.
+		//'cat("<<<charset=", localeToCharset()[1], ">>>", sep = "")',
+		'cat("", localeToCharset()[1], sep = "")',
 		false, function (s) {
-			_this.charset = s;
+			_this.charset = sv.tools.strings.trim(s);
 			if (_this.debug) sv.log.debug("R charset: " + s);
 	});
+	//invisible(guiRefresh(force = TRUE));
 }
 
 
@@ -506,6 +524,3 @@
 // Launch the SciViews socket server on Komodo startup
 addEventListener("load", function()
 	window.setTimeout("sv.socket.serverStart();", 500), false);
-
-//FIXME: on Windows the socket server is not reachable from R after Komodo is restarted
-//while R is running. Executing sv.socket.serverStart() does not help at all.

Modified: komodo/SciViews-K/content/js/tools/file.js
===================================================================
--- komodo/SciViews-K/content/js/tools/file.js	2010-10-04 21:35:03 UTC (rev 330)
+++ komodo/SciViews-K/content/js/tools/file.js	2010-10-05 11:20:43 UTC (rev 331)
@@ -18,7 +18,8 @@
 // sv.tools.file.getfile(baseDir, [pathComponents]);
 								// Create nsILocalFile object from array and/or
 								// special dir name
-// sv.tools.file.readURI(uri);	// Read data from an URI
+// sv.tools.file.readURI(uri);		// Read data from an URI
+// sv.tools.file.pathFromURI(uri);	// Converts an URI to local path
 // sv.tools.file.list(dirname, pattern, noext); // List all files matching
 								// pattern in dirname (with/without extension)
 // sv.tools.file.whereIs(appName);
@@ -202,11 +203,11 @@
 		for(var i in path) res = res.concat(path[i]);
 		//path = os.path.normpath(res.join(sep));
 		var dir0;
-		
+
 		path = res.join(sep);
 		if(os.name == "nt") path = path.replace(/\/+/g, sep);
 		dir0 = path.split(sep, 1)[0];
-		
+
 		path = sv.tools.file.specDir(dir0) + path.substring(dir0.length);
 		path = os.path.abspath(os.path.normpath(path));
 		return(path);
@@ -233,6 +234,13 @@
 		return (res);
 	}
 
+	// Read data from an URI
+	this.pathFromURI = function (uri) {
+		var fileSvc = Components.classes["@activestate.com/koFileService;1"]
+			.getService(Components.interfaces.koIFileService);
+		return (fileSvc.getFileFromURI(uri).path);
+	}
+
 	// List all files matching a given pattern in directory,
 	// python interface - ~2x faster than with nsILocalFile
 	this.list = function (dirname, pattern, noext) {

Modified: komodo/SciViews-K/content/sessions.xul
===================================================================
--- komodo/SciViews-K/content/sessions.xul	2010-10-04 21:35:03 UTC (rev 330)
+++ komodo/SciViews-K/content/sessions.xul	2010-10-05 11:20:43 UTC (rev 331)
@@ -66,7 +66,8 @@
 
 // Create references to main window objects:
 var mainWin, sv, ko;
-var os = Components.classes['@activestate.com/koOs;1'].getService(Components.interfaces.koIOs);
+var os = Components.classes['@activestate.com/koOs;1']
+	.getService(Components.interfaces.koIOs);
 
 
 // Populate session directory list, insert preference values into corresponding textboxes
@@ -135,6 +136,7 @@
 // Save values as preferences:
 function OK() {
 	var el = document.getElementById("sciviews.session.dir");
+	var newDir = el.value;
 	var mi, values = [];
 	for (var j = 0; j < el.itemCount; j++) {
 		values.push(homeSubst(el.getItemAtIndex(j).value));
@@ -142,28 +144,31 @@
 	sv.prefs.setString("sciviews.session.dir.mru", values.join(os.pathsep));
 
 	var prefEls = document.getElementsByAttribute("pref", "true");
-	var prefIds = [], prefName, prefVal, el;
+	var prefName, prefVal, el;
+	var prefAll = {};
 	for (var i = 0; i < prefEls.length; i++) {
 		el = prefEls[i];
 		prefVal = el.value;
 		if (el.getAttribute("prefsettings").indexOf("home-subst") != -1)
 		prefVal = homeSubst(prefVal);
-		sv.prefs.setString(el.id, prefVal);
+		prefAll[el.id] = prefVal;
 	}
 
-	function _getVal(id) document.getElementById(id).value;
+	sv.r.setSession(prefAll["sciviews.session.dir"],
+		prefAll["sciviews.session.data"],
+		prefAll["sciviews.session.scripts"],
+		prefAll["sciviews.session.reports"]);
 
-	sv.r.setSession (_getVal("sciviews.session.dir"),
-	_getVal("sciviews.session.data"),
-	_getVal("sciviews.session.scripts"),
-	_getVal("sciviews.session.reports"));
 
+	for (i in prefAll) sv.prefs.setString(i, prefAll[i]);
+
 	var setPlacesRoot =
 		document.getElementById("sciviews.session.placesroot").checked;
 
-	if (setPlacesRoot) {
-		ko.places.manager.openDirectory(_getVal("sciviews.session.dir"));
-	}
+	if (setPlacesRoot &&
+		(sv.tools.file.pathFromURI(ko.places.manager.currentPlace) != newDir))
+			ko.places.manager.openDirectory(newDir);
+
 	sv.prefs.setString("sciviews.session.placesroot", setPlacesRoot);
 
 	return (true);
@@ -256,8 +261,10 @@
 		}
 	}
 
-	printInfo("This directory contains " + (hasConfig? "a config file" : "no config file") +
-	" (\".svConfig\") and " + (hasWorkspace? "saved workspace": "no workspace") + ".");
+	printInfo("This directory contains " +
+		(hasConfig? "a config file" : "no config file") +
+		" (\".svConfig\") and " +
+		(hasWorkspace? "saved workspace": "no workspace") + ".");
 
 	document.getElementById("delete-config-button").disabled = !hasConfig;
 	document.getElementById("delete-workspace-button").disabled = !hasWorkspace;
@@ -274,7 +281,8 @@
 	var cfg = [];
 	var cfgEls = document.getElementsByAttribute("config", "*");
 	for (var i= 0; i < cfgEls.length; i++) {
-		cfg.push(cfgEls[i].getAttribute("config") + " = " + sv.tools.strings.trim(cfgEls[i].value));
+		cfg.push(cfgEls[i].getAttribute("config") + " = " +
+				 sv.tools.strings.trim(cfgEls[i].value));
 	}
 	var cfgFile = sv.tools.file.path(dir, ".svData");
 	sv.tools.file.write(cfgFile, cfg.join("\n"), "utf-8");
@@ -288,11 +296,11 @@
 	var files;
 	switch (which) {
 		case "config":
-		files = [".svData"];
-		break;
+			files = [".svData"];
+			break;
 		case "workspace":
-		files = [".RData", ".Rhistory"];
-		break;
+			files = [".RData", ".Rhistory"];
+			break;
 		default:
 	}
 
@@ -332,7 +340,7 @@
 			sv.translate("Do you want to overwrite current history file in \"%S\"", dir),
 				"Cancel", null, sv.translate("Save current history")
 			) == "OK") {
-			sv.r.evalHidden('savehistory("' + addslashes(rDataFile) + '")');
+			sv.r.evalHidden('savehistory("' + addslashes(rHistoryFile) + '")');
 		}
 	}
 }



More information about the Sciviews-commits mailing list