[Sciviews-commits] r454 - in komodo/SciViews-K: content content/js defaults

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Mar 3 16:09:15 CET 2012


Author: phgrosjean
Date: 2012-03-03 16:09:15 +0100 (Sat, 03 Mar 2012)
New Revision: 454

Modified:
   komodo/SciViews-K/content/RHelpWindow.xul
   komodo/SciViews-K/content/js/ask.js
   komodo/SciViews-K/content/js/commands.js
   komodo/SciViews-K/content/js/misc.js
   komodo/SciViews-K/content/js/pref-R.js
   komodo/SciViews-K/content/js/prefs.js
   komodo/SciViews-K/content/js/r.js
   komodo/SciViews-K/content/js/rconsoleOld.js
   komodo/SciViews-K/content/js/rinterpolationquery.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/pref-R.xul
   komodo/SciViews-K/content/sessions.xul
   komodo/SciViews-K/defaults/svStart.R
Log:
Incorporation of changes from SciViews-K-dev into SciViews-K: prefs.js (part VI)

Modified: komodo/SciViews-K/content/RHelpWindow.xul
===================================================================
--- komodo/SciViews-K/content/RHelpWindow.xul	2012-02-28 06:27:38 UTC (rev 453)
+++ komodo/SciViews-K/content/RHelpWindow.xul	2012-03-03 15:09:15 UTC (rev 454)
@@ -74,7 +74,7 @@
 				rHelpBrowser.goHome();
 				return;
 			 case "@CRAN@":
-				uri = sv.prefs.getString("r.cran.mirror");
+				uri = sv.prefs.getPref("r.cran.mirror");
 				if (!uri || uri.indexOf("ftp:/") === 0)
 					uri = "http://cran.r-project.org/";
 			}
@@ -290,8 +290,8 @@
 			// Use only one type of connection for both client and server!
 			//if (sv.r.server == "http") {
 			// TODO: this is reworked in SciViews-K-dev => look what's there!!!
-			if (sv.prefs.getString("sciviews.client.type", "socket") == "http") {
-				var port = sv.prefs.getString("sciviews.client.socket", "8888");
+			if (sv.prefs.getPref("sciviews.r.type", "socket") == "http") {
+				var port = sv.prefs.getPref("sciviews.r.port", 8888);
 				var path = "http://127.0.0.1:" + port + "/doc/html/index.html";
 				browser.homePage = sv.helpStartURI = path;
 				//alert(browser.homePage);

Modified: komodo/SciViews-K/content/js/ask.js
===================================================================
--- komodo/SciViews-K/content/js/ask.js	2012-02-28 06:27:38 UTC (rev 453)
+++ komodo/SciViews-K/content/js/ask.js	2012-03-03 15:09:15 UTC (rev 454)
@@ -31,9 +31,9 @@
 				var obj = cls[0];
 				for (i = 1; i < cls.length; i++) {
 					if (cls[i] != null & cls[i] != "") {
-						sv.prefs.setString("r.active." + cls[i], obj, true);
+						sv.prefs.setPref("r.active." + cls[i], obj, true);
 						if (cls[i] == "data.frame") {
-							sv.prefs.setString("r.active.data.frame.d", obj +
+							sv.prefs.setPref("r.active.data.frame.d", obj +
 								"$", true);
 							sv.r.obj_message();
 						} else if (cls[i] == "lm") sv.r.obj_message();
@@ -47,9 +47,9 @@
 		cls = classes.split("|");
 		for (i = 0; i < cls.length; i++) {
 			if (cls[i] != null & cls[i] != "") {
-				sv.prefs.setString("r.active." + cls[i], object, true);
+				sv.prefs.setPref("r.active." + cls[i], object, true);
 				if (cls[i] == "data.frame") {
-					sv.prefs.setString("r.active.data.frame.d", object + "$", true);
+					sv.prefs.setPref("r.active.data.frame.d", object + "$", true);
 					sv.r.obj_message();
 				} else if (cls[i] == "lm") sv.r.obj_message();
 			}
@@ -67,9 +67,9 @@
 	var obj = cls[0];
 	for (i = 1; i < cls.length; i++) {
 		if (cls[i] != null & cls[i] != "") {
-			sv.prefs.setString("r.active." + cls[i], obj, true);
+			sv.prefs.setPref("r.active." + cls[i], obj, true);
 			if (cls[i] == "data.frame") {
-				sv.prefs.setString("r.active.data.frame.d", obj + "$", true);
+				sv.prefs.setPref("r.active.data.frame.d", obj + "$", true);
 				sv.r.obj_message();
 			} else if (cls[i] == "lm") sv.r.obj_message();
 		}

Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js	2012-02-28 06:27:38 UTC (rev 453)
+++ komodo/SciViews-K/content/js/commands.js	2012-03-03 15:09:15 UTC (rev 454)
@@ -160,7 +160,7 @@
 
 		var cwd = sv.tools.file.path("ProfD", "extensions",
 			"sciviewsk at sciviews.org", "defaults");
-		var cmd = sv.prefs.getString("svRCommand");
+		var cmd = sv.prefs.getPref("svRCommand");
 
 		// Remove /defaults/00LOCK if remained after a fail-start
 		try {
@@ -170,7 +170,7 @@
 
 		// On Mac OS X, R.app is not a file, but a dir!
 		if (!cmd || (sv.tools.file.exists(sv.tools.strings.trim(
-			sv.prefs.getString("svRDefaultInterpreter"))) ==
+			sv.prefs.getPref("sciviews.r.interpreter"))) ==
 			sv.tools.file.TYPE_NONE)) {
 			if (ko.dialogs.okCancel(sv.translate("R interpreter is not" +
 				"(correctly) configured in Preferences. Do you want to do it now?"),
@@ -182,7 +182,7 @@
 
 		// Default R program depends on the platform
 		var isWin = navigator.platform.indexOf("Win") === 0;
-		var id = sv.prefs.getString("svRApplication",
+		var id = sv.prefs.getPref("sciviews.r.batchinterp",
 			isWin? "r-gui" : "r-terminal");
 
 		// Width of R output defined to fit R output panel (min = 66, max = 200)
@@ -192,21 +192,21 @@
 		if (width < 66) width = 66;
 		if (width > 200) width = 200;
 
-		var clientType = sv.prefs.getString("sciviews.client.type", "http");
+		var rType = sv.prefs.getPref("sciviews.r.type", "http");
 		var env = [
-			"koId=" + sv.prefs.getString("sciviews.client.id", "SciViewsK"),
+			"koId=" + sv.prefs.getPref("sciviews.ko.id", "SciViewsK"),
 			"koHost=localhost",
 			"koActivate=FALSE",
-			"Rinitdir=" + sv.prefs.getString("sciviews.session.dir", "~"),
-			"koType=" + clientType,
-			"koServe=" + sv.prefs.getString("sciviews.client.socket", "8888"),
-			"koPort=" + sv.prefs.getString("sciviews.server.socket", "7052"),
-			"koKotype=" + sv.prefs.getString("sciviews.server.type", "file"),
+			"Rinitdir=" + sv.prefs.getPref("sciviews.session.dir", "~"),
+			"koType=" + rType,
+			"koServe=" + sv.prefs.getPref("sciviews.r.port", 8888),
+			"koPort=" + sv.prefs.getPref("sciviews.ko.port", 7052),
+			"koKotype=" + sv.prefs.getPref("sciviews.ko.type", "file"),
 			"koDebug=" + String(sv.socket.debug).toUpperCase(),
 			"koAppFile=" + sv.tools.file.path("binDir", "komodo" +
 				(isWin? ".exe" : "")),
-			"OutDec=" + sv.prefs.getString("r.csv.dec", "."),
-			"OutSep=" + sv.prefs.getString("r.csv.sep", ","),
+			"OutDec=" + sv.prefs.getPref("r.csv.dec", "."),
+			"OutSep=" + sv.prefs.getPref("r.csv.sep", ","),
 			"width=" + width
 		];
 		var runIn = "no-console";
@@ -234,8 +234,8 @@
 		// Register observer of application termination
 		this.rObserver = new AppTerminateObserver(cmd);
 
-		// Ensure the client type is correct for everyone
-		sv.socket.setSocketType(clientType);
+		// Ensure the R type is correct for everyone
+		sv.socket.setSocketType(rType);
 
 		// ... make sure to start with a clear R Output window
 		sv.cmdout.clear(false);
@@ -348,7 +348,7 @@
 			uri = ""; // Home page will be shown
 		}
 
-		var rhelpTabbed = sv.prefs.getString("rhelp.tabbed", false) == "true";
+		var rhelpTabbed = sv.prefs.getPref("rhelp.tabbed", false) == "true";
 		var rHelpXulUri = "chrome://sciviewsk/content/RHelpWindow.xul";
 
 		// Open R-help in a right tab

Modified: komodo/SciViews-K/content/js/misc.js
===================================================================
--- komodo/SciViews-K/content/js/misc.js	2012-02-28 06:27:38 UTC (rev 453)
+++ komodo/SciViews-K/content/js/misc.js	2012-03-03 15:09:15 UTC (rev 454)
@@ -29,7 +29,7 @@
             "Dataset name:", "Dataset", "Select a dataset", "datafile");
     }
     if (data != null & data != "") {
-        var dataDir = sv.prefs.getString("sciviews.data.localdir", "~");
+        var dataDir = sv.prefs.getPref("sciviews.data.localdir", "~");
         var file = Components.classes["@mozilla.org/file/local;1"]
             .createInstance(Components.interfaces.nsILocalFile);
         file.initWithPath(dataDir);
@@ -67,7 +67,7 @@
 			**   00001   Execute by others.
 			*/
 			outputStream.init(file, 0x04 | 0x08 | 0x20, 438, 0);
-			var sep = sv.prefs.getString("r.csv.sep", "\t");
+			var sep = sv.prefs.getPref("r.csv.sep", "\t");
             var content = '"var1"' + sep + '"var2"\n';
 			var result = outputStream.write(content, content.length);
 			outputStream.close();
@@ -97,7 +97,7 @@
             "Script name:", "Script", "Select a script", "scriptfile");
     }
     if (script != null & script != "") {
-        var scriptsDir = sv.prefs.getString("sciviews.scripts.localdir",
+        var scriptsDir = sv.prefs.getPref("sciviews.scripts.localdir",
             "~/Scripts");
         var file = Components.classes["@mozilla.org/file/local;1"]
             .createInstance(Components.interfaces.nsILocalFile);
@@ -119,7 +119,7 @@
             "Report name:", "Report", "Select a report", "reportfile");
     }
     if (rep != null & rep != "") {
-        var reportsDir = sv.prefs.getString("sciviews.reports.localdir",
+        var reportsDir = sv.prefs.getPref("sciviews.reports.localdir",
             "~/Reports");
         var file = Components.classes["@mozilla.org/file/local;1"]
             .createInstance(Components.interfaces.nsILocalFile);
@@ -430,7 +430,7 @@
 			.getService(Components.interfaces.koITime);
 		var secsNow = timeSvc.time();
 		var timeTupleNow = timeSvc.localtime(secsNow, new Object());
-		if (!format) format = sv.prefs.getString("defaultDateFormat");
+		if (!format) format = sv.prefs.getPref("defaultDateFormat");
 		var timeStr = timeSvc.strftime(format, timeTupleNow.length, timeTupleNow);
 		ke.replaceSel(timeStr);
     } catch(e) {

Modified: komodo/SciViews-K/content/js/pref-R.js
===================================================================
--- komodo/SciViews-K/content/js/pref-R.js	2012-02-28 06:27:38 UTC (rev 453)
+++ komodo/SciViews-K/content/js/pref-R.js	2012-03-03 15:09:15 UTC (rev 454)
@@ -131,11 +131,11 @@
 
 // Populate the list of available R interpreters
 function _populateRInterps () {
-    var prefExecutable = sv.prefs.getString('svRDefaultInterpreter');
+    var prefExecutable = sv.prefs.getPref('sciviews.r.interpreter');
     var rs = new Array();
     var os = Components.classes['@activestate.com/koOs;1']
 		.getService(Components.interfaces.koIOs);
-    var menu = document.getElementById("svRDefaultInterpreter");
+    var menu = document.getElementById("sciviews.r.interpreter");
 
     switch (os.name) { //'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos'.
      case "nt":
@@ -162,7 +162,7 @@
 
     rs = sv.tools.array.unique(rs);
 	if (rs.indexOf(prefExecutable) == -1) {
-		prefset.setStringPref('svRDefaultInterpreter', '');
+		prefset.setStringPref('sciviews.r.interpreter', '');
 		rs.unshift('');
 	}
     menu.removeAllItems();
@@ -182,8 +182,8 @@
 	while (p.opener && (p = p.opener) && !sv) if (p.sv) sv = p.sv;
 	var prefExecutable;
 	var prefset = parent.hPrefWindow.prefset;
-	var prefName = 'svRDefaultInterpreter';
-    var menu = document.getElementById("svRApplication");
+	var prefName = 'sciviews.r.interpreter';
+    var menu = document.getElementById("sciviews.r.batchinterp");
     menu.removeAllItems();
     var platform = navigator.platform.substr(0,3);
     var tmp = {}, required, res;
@@ -232,8 +232,8 @@
 	var os = Components.classes['@activestate.com/koOs;1']
 		.getService(Components.interfaces.koIOs);
 
-	var menuApplication = document.getElementById("svRApplication");
-    var menuInterpreters = document.getElementById("svRDefaultInterpreter");
+	var menuApplication = document.getElementById("sciviews.r.batchinterp");
+    var menuInterpreters = document.getElementById("sciviews.r.interpreter");
 
 	// Just in case
 	if (sv.tools.file.exists(menuInterpreters.value) ==
@@ -254,8 +254,8 @@
 }
 
 function PrefR_svRApplicationOnSelect (event) {
-	var menuApplication = document.getElementById("svRApplication");
-    var menuInterpreters = document.getElementById("svRDefaultInterpreter");
+	var menuApplication = document.getElementById("sciviews.r.batchinterp");
+    var menuInterpreters = document.getElementById("sciviews.r.interpreter");
     if (!(menuApplication.value in apps)) return;
 	var app = apps[menuApplication.value].app;
 	//var sel = menuApplication.selectedItem;
@@ -279,10 +279,10 @@
 }
 
 function PrefR_updateCommandLine (update) {
-    var appId = document.getElementById("svRApplication").value;
-    var appPath = document.getElementById("svRDefaultInterpreter").value;
+    var appId = document.getElementById("sciviews.r.batchinterp").value;
+    var appPath = document.getElementById("sciviews.r.interpreter").value;
     if (!appId || !appPath) return("");
-	var cmdArgs = document.getElementById("svRArgs").value;
+	var cmdArgs = document.getElementById("sciviews.r.args").value;
 	var args1 = "";
 
 	if (document.getElementById("sciviews.pkgs.sciviews").checked)
@@ -314,7 +314,7 @@
 }
 
 function PrefR_setExecutable (path) {
-    var menu = document.getElementById("svRDefaultInterpreter");
+    var menu = document.getElementById("sciviews.r.interpreter");
 
     if (!path || !sv.tools.file.exists(path)) {
 		var os = Components.classes['@activestate.com/koOs;1']
@@ -359,7 +359,7 @@
 			var platform = navigator.platform.toLowerCase().substr(0,3);
 			if (platform == "win")
 				localPaths.push(svFile.path(
-					sv.prefs.getString("svRDefaultInterpreter"), "../../doc"));
+					sv.prefs.getPref("sciviews.r.interpreter"), "../../doc"));
 			else { // Linux or Mac OS X
 				localPaths.push("/usr/share/R/doc"); // Linux
 				localPaths.push("/usr/local/share/R/doc"); // Linux
@@ -409,7 +409,7 @@
 	// Put arrData into MenuList
 	var menuList = document.getElementById("CRANMirror");
 	var value =
-		menuList.value? menuList.value : sv.prefs.getString("r.cran.mirror");
+		menuList.value? menuList.value : sv.prefs.getPref("r.cran.mirror");
 	menuList.removeAllItems();
 	for (i in arrData) {
 		if (arrData[i][0])
@@ -429,10 +429,10 @@
 	prefset = parent.hPrefWindow.prefset;
 	
 	// Set R interpreter
-	prefset.setStringPref("svRDefaultInterpreter",
-		document.getElementById("svRDefaultInterpreter").value);
-	prefset.setStringPref("svRApplication",
-		document.getElementById('svRApplication')
+	prefset.setStringPref("sciviews.r.interpreter",
+		document.getElementById("sciviews.r.interpreter").value);
+	prefset.setStringPref("sciviews.r.batchinterp",
+		document.getElementById('sciviews.r.batchinterp')
 		.selectedItem.getAttribute("value"));
 	prefset.setStringPref("svRCommand", PrefR_updateCommandLine(false));
 	
@@ -456,41 +456,41 @@
 		}
 	}
 	
-	// Set the client type
-	var clientType = document.getElementById('sciviews.client.type').value;
-	prefset.setStringPref("sciviews.client.type", clientType);
+	// Set the R type
+	var rType = document.getElementById('sciviews.r.type').value;
+	prefset.setStringPref("sciviews.r.type", rType);
 	// Check if selected item is different from current sv.clientType
 	// and if R is running
-	if (clientType != sv.clientType && sv.r.test()) {
+	if (rType != sv.clientType && sv.r.test()) {
 		// R is running, do not change right now
 		sv.alert("R server type changed",
 			"The R server type you selected will be" +
 			" used after restarting R!");
 	} else {
 		// Change current server type too
-		sv.socket.setSocketType(clientType);
+		sv.socket.setSocketType(rType);
 	}
 	
 	_menuListGetValues();
 	
 	// Restart socket server if running and port or channel changed
-	var serverType = document.getElementById('sciviews.server.type').value;
-	var serverPort = document.getElementById('sciviews.server.socket').value;
-	if (serverPort != prefset.getStringPref("sciviews.server.socket") ||
-		serverType != sv.serverType) {
+	var koType = document.getElementById('sciviews.ko.type').value;
+	var koPort = document.getElementById('sciviews.ko.port').value;
+	if (koPort != prefset.getStringPref("sciviews.ko.port") ||
+		koType != sv.serverType) {
 		// Stop server with old config, if it is started
 		var isStarted = sv.socket.serverIsStarted;
 		if (isStarted) sv.socket.serverStop();
-		prefset.setStringPref("sciviews.server.socket", serverPort);
-		prefset.setStringPref("sciviews.server.type", serverType);
-		sv.serverType = serverType;
+		prefset.setStringPref("sciviews.ko.port", koPort);
+		prefset.setStringPref("sciviews.ko.type", koType);
+		sv.serverType = koType;
 		// Start server with new config, if previous one was started
 		if (isStarted) sv.socket.serverStart();
 		// Change config in R, if it is running and connected
 		if (sv.r.running) {
-			sv.r.evalHidden('options(ko.kotype = "' + serverType + '", ' +
-				'ko.port = "' + serverPort + '")', true);
+			sv.r.evalHidden('options(ko.kotype = "' + koType + '", ' +
+				'ko.port = "' + koPort + '")', true);
 		}
 	}
 	return(true);
-}
\ No newline at end of file
+}

Modified: komodo/SciViews-K/content/js/prefs.js
===================================================================
--- komodo/SciViews-K/content/js/prefs.js	2012-02-28 06:27:38 UTC (rev 453)
+++ komodo/SciViews-K/content/js/prefs.js	2012-03-03 15:09:15 UTC (rev 454)
@@ -5,10 +5,13 @@
 // License: MPL 1.1/GPL 2.0/LGPL 2.1
 ////////////////////////////////////////////////////////////////////////////////
 // sv.prefs.defaults;             // Default preference values
+// sv.prefs.getPref(prefName, defaultValue);
+//                                // Get a preference, use 'def' is not found
+// sv.prefs.setPref(prefName, value, overwrite, asInt);
+//                                // Set a preference
+// sv.prefs.setPref(prefName);    // Delete a preference
+// sv.prefs.askPref(pref, defvalue); // Ask for the value of a preference
 // sv.prefs.checkAll();           // Check all preferences
-// sv.prefs.getString(pref, def); // Get a preference, use 'def' is not found
-// sv.prefs.setString(pref, value, overwrite); // Set a preference string
-// sv.prefs.askString(pref, defvalue); // Ask for the value of a preference
 // sv.prefs.mru(mru, reset, items, sep); //Simplify update of MRU lists
 //                                         history a text entries in dialog box
 // sv.prefs.tip(arg, tip);        // Default tooltips for interpolation queries
@@ -16,108 +19,179 @@
 // Definition of various preferences for SciViews-K
 ////////////////////////////////////////////////////////////////////////////////
 
-if (typeof(sv.prefs) == "undefined") sv.prefs = {};
+if (sv.prefs === undefined) sv.prefs = {};
 
 (function () {
 	
 	var prefset = Components.classes["@activestate.com/koPrefService;1"]
-	.getService(Components.interfaces.koIPrefService).prefs;
+		.getService(Components.interfaces.koIPrefService).prefs;
+	this.prefset = prefset;
+	var _this = this;
 
-this.prefset = prefset;
+	// sv.prefs.defaults[preferenceName] = preferenceValue
+	this.defaults = {
+		"sciviews.ko.id": "SciViewsK",
+		"sciviews.ko.type": "socket",
+		"sciviews.ko.port": 7052,
+		"sciviews.r.type": "http",
+		"sciviews.r.port": 8888,
+		"sciviews.r.host": "127.0.0.1",
+		"sciviews.r.interpreter": "",
+		//"sciviews.r.args": "--quiet",
+		//"sciviews.r.auto-start": false,
+		"sciviews.r.batchinterp": "",
+	    "r.csv.dec": ".",
+		"r.csv.sep": ",",
+		"r.application": "",
+		"r.cran.mirror": "http://cran.r-project.org/"
+		//"r.help.command": "javascript:sv.r.help(\"%w\")",
+		//"r.help.open.in": [tab, window],
+		//"r.help.remote": "http://finzi.psych.upenn.edu/R/"
+	}
 
-// sv.prefs.defaults[preferenceName] = preferenceValue
-sv.prefs.defaults = {
-	"sciviews.server.socket": "7052",
-	"sciviews.server.type": "socket",
-	"sciviews.client.type": "http",
-	"sciviews.client.socket": "8888",
-	"sciviews.client.id": "SciViewsK",
-	"sciviews.server.host": "127.0.0.1",
-	"svRDefaultInterpreter": "",
-	"svRApplication": "",
-    "r.csv.dec": ".",
-	"r.csv.sep": ",",
-	"r.application": "",
-	"r.cran.mirror": "http://cran.r-project.org/"
-	//*Future preferences:*
-	//"svRArgs": "--quiet",
-	//"RHelpCommand": "javascript:sv.r.help(\"%w\")",
-	//"sciviews.rhelp.open_in": [tab, window]
-	//"sciviews.r.auto-start": false
-}
+	// Get a preference, or default value
+	this.getPref = function (prefName, defaultValue) {
+		var ret, typeName, type;
+		if (prefset.hasPref(prefName)) {
+			type = ['long', 'double', 'boolean', 'string']
+				.indexOf(prefset.getPrefType(prefName));
+			if (type == -1) return(undefined);
+			typeName = ['Long', 'Double', 'Boolean', 'String'][type];
+			ret = prefset['get' + typeName + 'Pref'](prefName);
+		} else ret = defaultValue;
+		return(ret);
+	}
+	
+	// Set a preference
+	this.setPref = function (prefName, value, overwrite, asInt) {
+		var typeName, type;
+		if (prefset.hasPref(prefName)) {
+			if (overwrite === false) return("");
+			type = prefset.getPrefType(prefName);
+		} else {
+			type = typeof(value);
+			if (type == 'number') type = asInt? "long" : "double";
+		}
+		type = ['double', 'long', 'boolean', 'string'].indexOf(type);
+		if (type == -1 || type == null) return(undefined);
+		typeName = ['Double', 'Long', 'Boolean', 'String'][type];
+		prefset['set' + typeName + 'Pref'](prefName, value);
+		return(typeName);
+	}
+	
+	// Delete a preference
+	this.deletePref = function (prefName) {
+		prefset.deletePref(prefName);
+		return(prefset.hasPref(prefName));
+	}
+	
+	// Display a dialog box to change a preference string
+	this.askPref = function (pref, defvalue) {
+		// If defvalue is defined, use it, otherwise, use current pref value
+		var prefExists = prefset.hasPref(pref);
+		if (defvalue == null) {
+			defvalue = prefExists ? this.getPref(pref) : "";
+		}
+		var prefType = prefExists ? prefset.getPrefType(pref) : 'undefined';
+		var validator = {
+			'double': function (win, x)
+				(/^[+-]?\d+\.\d*([eE][+-]?\d+)?$/).test(x),
+			'long': function (win,x)
+				x == parseInt(x),
+			'boolean': function (win, x)
+				["true", "false", "0", "1"].indexOf(x.toLowerCase()) != -1,
+			'string': function (win, x)
+				true,
+			'undefined': function (win, x)
+				true
+		}
+		// Display a dialog box to change the preference value
+		var newVal = ko.dialogs.prompt("Change preference value" +
+			(prefType == 'undefined' ? "" : " (" + prefType + ")") +
+			" for:", pref, 	defvalue, "SciViews-K preference", "svPref" + pref,
+			validator[prefType]);
+	
+		if (prefType == 'undefined') {
+			for (prefType in validator)
+				if (validator[prefType](null, newVal)) break;
+		}
+		switch(prefType) {
+		 case 'boolean':
+			newVal = !!eval(newVal.toLowerCase());
+			break;
+		 case 'long':
+			newVal = parseInt(newVal);
+			break;
+		 case 'double':
+			newVal = parseFloat(newVal);
+			break;
+		}
+		if (newVal != null) this.setPref(pref, newVal);
+	}
+	
+	// Set default preferences
+	this.checkAll = function sv_checkAllPref (revert) {
+		for (var i in _this.defaults) {
+			var el;
+			var p = _this.defaults[i];
+			switch(typeof(p)) {
+			 case "number":
+				el = (parseInt(p) == p)? "Long" : "Double";
+				break;
+			 case "boolean":
+				el = "Boolean";
+				break;
+			 case "string":
+			 default:
+				el = "String";
+				p = p.toString();
+			}
+			if (revert // take all
+				|| !prefset.hasPref(i) // if missing at all
+				|| (prefset["has" + el + "Pref"](i) // has right type, but empty
+				&& !prefset["get" + el + "Pref"](i))) {
+				_this.deletePref(i); // To avoid _checkPrefType error
+				prefset["set" + el + "Pref"](i, p);
+			};
+		}
+	}
 
-// Get a string preference, or default value
-sv.prefs.getString = function (pref, def) {
-	var prefsSvc = Components.classes["@activestate.com/koPrefService;1"]
-		.getService(Components.interfaces.koIPrefService);
-	var prefs = prefsSvc.prefs;
-	if (prefs.hasStringPref(pref)) {
-		return(prefs.getStringPref(pref));
-	} else return(def);
-}
+	// Simplify update of MRU lists
+	this.mru = function (mru, reset, items, sep) {
+		var mruList = "dialog-interpolationquery-" + mru + "Mru";
+		// Do we reset the MRU list?
+		if (reset === undefined) reset = false;
+		if (reset == true) ko.mru.reset(mruList);
+	
+		// Do we need to split items (when sep is defined)?
+		if (sep !== undefined) items = items.split(sep);
+	
+		// Add each item in items in inverse order
+		for (var i = items.length - 1; i >= 0; i--) {
+			if (items[i] != "")
+				ko.mru.add(mruList, items[i], true);
+		}
+	}
+	
+	// Simplify storage of default tooltips for arguments in interpolation queries
+	this.tip = function (arg, tip) {
+		_this.set("dialog-tip-" + arg, tip, true);
+	}
 
-// Set a string preference
-sv.prefs.setString = function (pref, value, overwrite) {
-	var prefsSvc = Components.classes["@activestate.com/koPrefService;1"]
-		.getService(Components.interfaces.koIPrefService);
-	var prefs = prefsSvc.prefs;
-	if (overwrite == false & prefs.hasStringPref(pref)) return;
-	prefs.setStringPref(pref, value);
-}
+}).apply(sv.prefs);
 
-// Display a dialog box to change a preference string
-sv.prefs.askString = function (pref, defvalue) {
-	var prefsSvc = Components.classes["@activestate.com/koPrefService;1"]
-		.getService(Components.interfaces.koIPrefService);
-	var prefs = prefsSvc.prefs;
-	// If defvalue is defined, use it, otherwise, use current pref value
-	if (defvalue == null & prefs.hasStringPref(pref))
-		defvalue = prefs.getStringPref(pref);
-	if (defvalue == null) defvalue == "";
-	// Display a dialog box to change the preference value
-	newvalue = ko.dialogs.prompt("Change preference value for:", pref,
-		defvalue, "SciViews-K preference", "svPref" + pref)
-	if (newvalue != null) prefs.setStringPref(pref, newvalue);
-}
 
-// Set default preferences
-sv.prefs.checkAll = function sv_checkAllPref (revert) {
-	var prefset = Components.classes['@activestate.com/koPrefService;1']
-		.getService(Components.interfaces.koIPrefService).prefs;
-	for (var i in sv.prefs.defaults) {
-		var el;
-		var p = sv.prefs.defaults[i];
-		switch(typeof(p)) {
-		 case "number":
-			el = (parseInt(p) == p)? "Long" : "Double";
-			break;
-		 case "boolean":
-			el = "Boolean";
-			break;
-		 case "string":
-		 default:
-			el = "String";
-			p = p.toString();
-		}
-		if (revert // take all
-			|| !prefset.hasPref(i) // if missing at all
-			|| (prefset["has" + el + "Pref"](i) // has right type, but empty
-			&& !prefset["get" + el + "Pref"](i))) {
-			prefset.deletePref(i); // To avoid _checkPrefType error
-			prefset["set" + el + "Pref"](i, p);
-		};
-	}
-}
 // Preferences (default values, or values reset on each start)
 sv.prefs.checkAll(false);
+
 // Try getting a reasonable default R interpreter, if none is defined
-var svRDefaultInterpreter = sv.prefs.getString("svRDefaultInterpreter", "");
+var svRDefaultInterpreter = sv.prefs.getPref("sciviews.r.interpreter", "");
 // Is this R interpreter still there?
 if (svRDefaultInterpreter != "" &&
 	sv.tools.file.exists(svRDefaultInterpreter) == sv.tools.file.TYPE_NONE) {
 	// We don't warn the user that current R is not found here because Komodo
 	// is still loading. Will be rechecked on time in sv.command.startR()
-	sv.prefs.setString("svRDefaultInterpreter", "", true);
+	sv.prefs.setPref("sciviews.r.interpreter", "", true);
 	svRDefaultInterpreter = "";
 }
 // If no default R interpreter defined, try to get reasonable default one
@@ -126,9 +200,9 @@
 	if (navigator.platform.indexOf("Win") === 0) {
 		svRDefaultInterpreter = sv.tools.file.whereIs("Rgui");
 		if (svRDefaultInterpreter) {
-			sv.prefs.setString("svRDefaultInterpreter", svRDefaultInterpreter,
+			sv.prefs.setPref("sciviews.r.interpreter", svRDefaultInterpreter,
 				true);
-			sv.prefs.setString("svRApplication", "r-gui", true);		
+			sv.prefs.setPref("sciviews.r.batchinterp", "r-gui", true);		
 		}
 	} else { // Linux or Mac OS X
 		svRDefaultInterpreter = sv.tools.file.whereIs("R");
@@ -136,74 +210,54 @@
 			// Check if GnomeTerm Konsole or xfce4term are there, use them
 			if (sv.tools.file.exists("gnome-terminal") !=
 				sv.tools.file.TYPE_NONE) {
-				sv.prefs.setString("svRApplication", "r-gnome-term", true);
+				sv.prefs.setPref("sciviews.r.batchinterp", "r-gnome-term",
+					true);
 			} else if (sv.tools.file.exists("konsole") !=
 				sv.tools.file.TYPE_NONE) {
-				sv.prefs.setString("svRApplication", "r-kde-term", true);
+				sv.prefs.setPref("sciviews.r.batchinterp", "r-kde-term",
+					true);
 			} else if (sv.tools.file.exists("xfce4-terminal") !=
 				sv.tools.file.TYPE_NONE) {
-				sv.prefs.setString("svRApplication", "r-xfce4-term", true);
+				sv.prefs.setPref("sciviews.r.batchinterp", "r-xfce4-term",
+					true);
 			} else { // Use default terminal
-				sv.prefs.setString("svRApplication", "r-terminal", true);
+				sv.prefs.setPref("sciviews.r.batchinterp", "r-terminal",
+					true);
 			}
-			sv.prefs.setString("svRDefaultInterpreter", svRDefaultInterpreter,
+			sv.prefs.setPref("sciviews.r.interpreter", svRDefaultInterpreter,
 				true);
 		}
 	}
 }
 
-// Simplify update of MRU lists
-sv.prefs.mru = function (mru, reset, items, sep) {
-	var mruList = "dialog-interpolationquery-" + mru + "Mru";
-	// Do we reset the MRU list?
-	if (reset === undefined) reset = false;
-	if (reset == true) ko.mru.reset(mruList);
-
-	// Do we need to split items (when sep is defined)?
-	if (sep !== undefined) items = items.split(sep);
-
-	// Add each item in items in inverse order
-	for (var i = items.length - 1; i >= 0; i--) {
-		if (items[i] != "")
-			ko.mru.add(mruList, items[i], true);
-	}
-}
-
-// Simplify storage of default tooltips for arguments in interpolation queries
-sv.prefs.tip = function (arg, tip) {
-	sv.prefs.setString("dialog-tip-" + arg, tip, true);
-}
-
-}).apply(sv.prefs);
-
 // This is required by sv.helpContext() for attaching help to snippets
 // Create empty preference sets to be used with snippet help system hack
 // [[%pref:R-help:value]] which displays nothing when the snippet is used
 // but can be used to retrieve value to display a particular snippet help page
 // Help page triggered by a given URL
-sv.prefs.setString("URL-help", "", true);
+sv.prefs.setPref("URL-help", "", true);
 // R HTML help pages triggered with '?topic'
-sv.prefs.setString("R-help", "", true);
+sv.prefs.setPref("R-help", "", true);
 // Help page on the R Wiki
-sv.prefs.setString("RWiki-help", "", true);
+sv.prefs.setPref("RWiki-help", "", true);
 
 // Default working directory for R and default subdirs the first time SciViews-K
 // is used... the rest of session dirs is set in r.js with sv.r.setSession()
-sv.prefs.setString("sciviews.session.dir", "~", false);
+sv.prefs.setPref("sciviews.session.dir", "~", false);
 
 // Where do we want to display R help? In internal browser or not?
-sv.prefs.setString("sciviews.r.help", "internal", false);
+sv.prefs.setPref("sciviews.r.help", "internal", false);
 
 // This is the base path for the R Wiki context help feature sv.helpContext()
-sv.prefs.setString("sciviews.rwiki.help.base",
+sv.prefs.setPref("sciviews.rwiki.help.base",
 	"http:/wiki.r-project.org/rwiki/doku.php?id=", false);
 
 // Set default dataset to 'df'
 // Should be reset to a more useful value during first use of R
-sv.prefs.setString("r.active.data.frame", "<df>", true);
-sv.prefs.setString("r.active.data.frame.d", "<df>$", true);
-sv.prefs.setString("r.active.lm", "<lm>", true);
-sv.prefs.setString("r.active.pcomp", "<pcomp>", true);
+sv.prefs.setPref("r.active.data.frame", "<df>", true);
+sv.prefs.setPref("r.active.data.frame.d", "<df>$", true);
+sv.prefs.setPref("r.active.lm", "<lm>", true);
+sv.prefs.setPref("r.active.pcomp", "<pcomp>", true);
 sv.prefs.mru("var", true, "");
 sv.prefs.mru("var2", true, "");
 sv.prefs.mru("x", true, "");
@@ -223,7 +277,7 @@
 // header argument, like in read.table()
 sv.prefs.mru("header", true, 'TRUE|FALSE', "|");
 
-// Various examples of pkgdata (indeed, data frames in datatasets 2.9.1) /////
+// Various examples of pkgdata (indeed, data frames in datatasets 2.9.1) ///////
 sv.prefs.mru("pkgdata", false,
 	'airquality|anscombe|attenu|attitude|beaver1|beaver2|BOD|cars|' +
 	'ChickWeight|chickwts|CO2|DNase|esoph|faithful|Formaldehyde|freeny|' +

Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js	2012-02-28 06:27:38 UTC (rev 453)
+++ komodo/SciViews-K/content/js/r.js	2012-03-03 15:09:15 UTC (rev 454)
@@ -111,7 +111,7 @@
 	
 	// Save the path in r.application prefs
 	if (R == null) R = "";
-	sv.prefs.setString("r.application", R, true);
+	sv.prefs.setPref("r.application", R, true);
 	return(R);
 }
 
@@ -178,9 +178,9 @@
 	// Blank R output
 	sv.cmdout.message("R has quit!", 0, false);
 	// Reset statusbar
-	sv.prefs.setString("sciviews.session.dir", "~", true);
-	sv.prefs.setString("r.active.data.frame", "<none>", true);
-	sv.prefs.setString("r.active.lm", "<none>", true);
+	sv.prefs.setPref("sciviews.session.dir", "~", true);
+	sv.prefs.setPref("r.active.data.frame", "<none>", true);
+	sv.prefs.setPref("r.active.lm", "<none>", true);
 	ko.statusBar.AddMessage("", "SciViews-K");
 	sv.cmdout.clear(false);
 	// Reset the objects explorer
@@ -998,7 +998,7 @@
 					//alert("Update of MRU lists not implemented yet for " +
 					//	"other objects than 'data.frame'");
 					// Temporary code: at least set pref value
-					sv.prefs.setString("r.active." + objclass, objname, true);
+					sv.prefs.setPref("r.active." + objclass, objname, true);
 				}
 			}
 		}
@@ -1010,13 +1010,13 @@
 // active in the Komodo statusbar
 sv.r.obj_message = function () {
 	// Get the directory of current session
-	var ses = sv.prefs.getString("sciviews.session.dir", "~");
+	var ses = sv.prefs.getPref("sciviews.session.dir", "~");
 	ses = sv.tools.strings.filename(ses);
 	// Get currently active data frame
-	var df = sv.prefs.getString("r.active.data.frame", "<none>");
+	var df = sv.prefs.getPref("r.active.data.frame", "<none>");
 	if (df == "<df>") df = "<none>";
 	// Get currently active 'lm' object
-	var lm = sv.prefs.getString("r.active.lm", "<none>")
+	var lm = sv.prefs.getPref("r.active.lm", "<none>")
 	if (lm == "<lm>") lm = "<none>";
 	ko.statusBar.AddMessage(sv.translate(
 		"R session: %S  data: %S linear model: %S", ses, df, lm), "SciViews-K");
@@ -1044,9 +1044,9 @@
 	ko.statusBar.AddMessage("", "SciViews-K");
 	// 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", "");
-		sv.prefs.setString("r.active.data.frame", "<df>", true); // Default
-		sv.prefs.setString("r.active.data.frame.d", "<df>$", true);
[TRUNCATED]

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


More information about the Sciviews-commits mailing list