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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Dec 27 20:26:37 CET 2009


Author: prezez
Date: 2009-12-27 20:26:36 +0100 (Sun, 27 Dec 2009)
New Revision: 238

Modified:
   komodo/SciViews-K/content/js/misc.js
   komodo/SciViews-K/content/js/pref-R.js
   komodo/SciViews-K/content/js/socket.js
   komodo/SciViews-K/content/pref-R.xul
   komodo/SciViews-K/content/sessions.xul
Log:
Preferences page: added options for "r.csv.sep" and "r.csv.dec".
sv.socket.prompt is now set properly by sv.socket.rClient.
session manager: added possibility to save workspace in selected directory.

Modified: komodo/SciViews-K/content/js/misc.js
===================================================================
--- komodo/SciViews-K/content/js/misc.js	2009-12-22 10:11:32 UTC (rev 237)
+++ komodo/SciViews-K/content/js/misc.js	2009-12-27 19:26:36 UTC (rev 238)
@@ -222,12 +222,13 @@
 	function _colorPicker_system (color) {
 		var sysUtils = Components.classes['@activestate.com/koSysUtils;1'].
 			getService(Components.interfaces.koISysUtils);
-		if (!color)
-			color = "#000000";
+		if (!color)		color = "#000000";
 		// sysUtils.pickColor seems to be broken, does not return any value
 		// which is strange, because it is only wrapper for .pickColorWithPositioning,
 		// Moreover, positioning does not seem to work anyway.
 		var newcolor = sysUtils.pickColorWithPositioning(color, -1, -1);
+		//Note pickColor was fixed in Komodo 5.2.3
+
 		if (newcolor) {
 		   var scimoz = ko.views.manager.currentView.scimoz;
 		   scimoz.replaceSel(newcolor);
@@ -406,7 +407,7 @@
             scimoz.setSel(curAnchor, curPos);
         }
     } catch (e) {
-        sv.log.exception(e, "sv.misc.showConfig() error");
+        sv.log.exception(e, "sv.misc.swapQuotes() error");
     } finally {
         ko.views.manager.currentView.scimoz.endUndoAction();
     }
@@ -436,7 +437,8 @@
         var ke = ko.views.manager.currentView.scimoz;
 
 		// Adapted from setDateFormatExample() in "chrome://komodo/content/pref/pref-intl.js"
-		var timeSvc = Components.classes["@activestate.com/koTime;1"]. getService(Components.interfaces.koITime);
+		var timeSvc = Components.classes["@activestate.com/koTime;1"]
+			.getService(Components.interfaces.koITime);
 		var secsNow = timeSvc.time();
 		var timeTupleNow = timeSvc.localtime(secsNow, new Object());
 		if (!format)
@@ -447,5 +449,3 @@
         sv.log.exception(e, "sv.misc.timeStamp() error");
     }
 }
-
-

Modified: komodo/SciViews-K/content/js/pref-R.js
===================================================================
--- komodo/SciViews-K/content/js/pref-R.js	2009-12-22 10:11:32 UTC (rev 237)
+++ komodo/SciViews-K/content/js/pref-R.js	2009-12-27 19:26:36 UTC (rev 238)
@@ -11,9 +11,7 @@
 // TODO: use 'R' simply as default R (terminal on Win/Mac, or ? on Linux)
 
 /* TODO: prefs to include:
- * session directory ??? (dir, datadir, scriptdir, reportdir)
  * address for remote R (sv.socket.host)? (if not localhost - disable source* commands)
- * default CRAN mirror updated also by sv.r.pkg.chooseCRANMirror
  * R help: show in tab (sidebar - another TODO) or in separate window
  * R Site search url (%S replaced by topic)
  */
@@ -24,6 +22,57 @@
 
 var sv;
 
+
+// for editable menulists: append new element if necessarry.
+function editMenulist(el) {
+	var curValue = sv.tools.strings.trim(el.value);
+	if (!curValue) return;
+	var values = [], val;
+	for (var j = 0; j < el.itemCount; j++) {
+		val = el.getItemAtIndex(j).value;
+		if (val == curValue) {
+			el.selectedIndex = j;
+			return;
+		}
+		values.push(val);
+	}
+	el.appendItem(curValue, curValue, null);
+}
+
+function menuListSetValues(attribute) {
+	if (!attribute) attribute = 'values';
+	var ml = document.getElementsByTagName('menulist');
+	var el, values;
+	for (var i = 0; i < ml.length; i++) {
+		el = ml[i];
+		if (el.hasAttribute(attribute)) {
+			values = el.getAttribute(attribute).split(/\s+/);
+			for (var k in values) {
+			   el.appendItem(values[k], values[k], null);
+			}
+		}
+	}
+}
+
+function menuListGetValues(attribute) {
+	if (!attribute) attribute = 'values';
+	var ml = document.getElementsByTagName('menulist');
+	var el, values;
+	for (var i = 0; i < ml.length; i++) {
+		el = ml[i];
+		if (el.hasAttribute(attribute)) {
+			values = [];
+			for (var k = 0; k < el.itemCount; k++) {
+				values.push(el.getItemAtIndex(k).value);
+			}
+			el.setAttribute(attribute, values.join(" "));
+		}
+	}
+}
+
+
+
+
 function PrefR_menulistSetValue(menuList, value, attr, vdefault) {
 	var n = menuList.itemCount;
 	var item;
@@ -57,6 +106,8 @@
 	if (!PrefR_UpdateCranMirrors(true))
 		PrefR_UpdateCranMirrors(false);
 
+	menuListSetValues();
+
 	parent.hPrefWindow.onpageload();
 }
 
@@ -75,6 +126,24 @@
 	prefset.setStringPref("svRApplicationId",
 					  document.getElementById('svRApplication')
 					  .selectedItem.id);
+
+	var outDec = document.getElementById('r.csv.dec').value;
+	var outSep = document.getElementById('r.csv.sep').value;
+
+	prefset.setStringPref("r.csv.dec.arg", '"' + outDec +'"');
+	prefset.setStringPref("r.csv.sep.arg", '"' + outSep +'"');
+
+	//alert(sv.tools.strings.addslashes(outDec));
+
+	if	(sv.r.running) {
+		sv.r.eval('options(OutDec = "' + outDec + '", ' +
+						'OutSep = "' + outSep + '")', true);
+	}
+
+
+
+	menuListGetValues();
+
 	return true;
 }
 
@@ -249,7 +318,7 @@
 }
 
 // From: http://www.bennadel.com/index.cfm?dax=blog:1504.view
-function CSVToArray( strData, strDelimiter ){
+function CSVToArray(strData, strDelimiter){
 	strDelimiter = (strDelimiter || ",");
 	var objPattern = new RegExp((
 			// Delimiters.

Modified: komodo/SciViews-K/content/js/socket.js
===================================================================
--- komodo/SciViews-K/content/js/socket.js	2009-12-22 10:11:32 UTC (rev 237)
+++ komodo/SciViews-K/content/js/socket.js	2009-12-27 19:26:36 UTC (rev 238)
@@ -56,6 +56,7 @@
 
 	// The main socket client function to connect to R socket server
 	this.rClient = function (host, port, outputData, listener, echo, echofun) {
+
 		try {
 			var transportService = Components.
 				classes["@mozilla.org/network/socket-transport-service;1"]
@@ -82,12 +83,12 @@
 
 			var dataListener = {
 				data: "",
-				onStartRequest: function(request, context) { this.data = ""; },
+				onStartRequest: function(request, context) { _this.data = ""; },
 				onStopRequest: function(request, context, status) {
 					instream.close();
 					outstream.close();
-					this.data = sv.tools.strings.removeLastCRLF(this.data);
-					listener.finished(this.data);
+					_this.data = sv.tools.strings.removeLastCRLF(_this.data);
+					listener.finished(_this.data);
 				},
 				onDataAvailable: function(request, context,
 					inputStream, offset, count) {
@@ -104,11 +105,11 @@
 
 					// Determine if we have a prompt at the end
 					if (chunk.search(/\+\s+$/) > -1) {
-						this.prompt = ":+ ";
+						_this.prompt = ":+ ";
 						// remove endline from prompt if it is a continuation
 						chunk = chunk.rtrim() + " ";
 					} else if (chunk.search(/>\s+$/) > -1) {
-						this.prompt = ":> ";
+						_this.prompt = ":> ";
 					}
 
 					// Do we need to close the connection
@@ -120,7 +121,7 @@
 						// Eliminate the last carriage return after the prompt
 						chunk = chunk.replace(/(\r?\n\f|\s+$)/, "");
 					}
-					this.data += chunk;
+					_this.data += chunk;
 					// Do we "echo" these results somewhere?
 					if (echo) {
 						if (echofun == null) {
@@ -132,7 +133,7 @@
 			}
 
 			var pump = Components.
-			classes["@mozilla.org/network/input-stream-pump;1"].
+				classes["@mozilla.org/network/input-stream-pump;1"].
 				createInstance(Components.interfaces.nsIInputStreamPump);
 			pump.init(stream, -1, -1, 0, 0, false);
 			pump.asyncRead(dataListener, null);
@@ -176,7 +177,7 @@
 		var port = sv.prefs.getString("sciviews.client.socket", "8888");
 		var id = "<<<id=" +
 			sv.prefs.getString("sciviews.client.id", "SciViewsK") + ">>>";
-		var res = this.rClient(this.host, port, id + cmd + "\n",
+		var res = _this.rClient(_this.host, port, id + cmd + "\n",
 			listener, echo, echofun);
 
 		// BUG: (windows/linux?) if network connection is turned off while komodo is
@@ -188,7 +189,6 @@
 			sv.cmdout.message("Error: R is unreachable (see log)", 5000, true);
 		}
 		return(res);
-
 	}
 	//Test: sv.socket.rCommand("<<<q>>>cat('library = '); str(library)");
 

Modified: komodo/SciViews-K/content/pref-R.xul
===================================================================
--- komodo/SciViews-K/content/pref-R.xul	2009-12-22 10:11:32 UTC (rev 237)
+++ komodo/SciViews-K/content/pref-R.xul	2009-12-27 19:26:36 UTC (rev 238)
@@ -32,6 +32,8 @@
 
  ***** END LICENSE BLOCK ***** -->
 
+<!-- SciViews-K preference page -->
+
 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
 <?xml-stylesheet href="chrome://komodo/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://komodo/skin/global/global.css" type="text/css"?>
@@ -196,5 +198,36 @@
 		  </rows>
 		</grid>
 	</groupbox>
+	<groupbox orient="vertical">
+		<caption label="Data output"/>
+		<grid>
+		<columns>
+			<column flex="3"/> <column flex="3"/> <column flex="3"/>
+		</columns>
+			<rows>
+				<row align="center">
+					<label value="Decimal separator" control="r.csv.dec" />
+					<menulist pref="true" id="r.csv.dec"
+						values=", ." persist="values"
+						>
+						<menupopup />
+					</menulist>
+
+					<label value="CSV field separator" control="r.csv.sep" />
+					<menulist pref="true" id="r.csv.sep"
+							  editable="true"
+							  <!--oninput="this.value = this.value[0];"-->
+							  onkeyup="if (event.keyCode == 13) editMenulist(this);"
+							  onblur="editMenulist(this);"
+							  values=", ; \t" persist="values"
+							  >
+						<menupopup />
+					</menulist>
+				</row>
+			</rows>
+		</grid>
+	</groupbox>
+
+
 </vbox>
 </window>

Modified: komodo/SciViews-K/content/sessions.xul
===================================================================
--- komodo/SciViews-K/content/sessions.xul	2009-12-22 10:11:32 UTC (rev 237)
+++ komodo/SciViews-K/content/sessions.xul	2009-12-27 19:26:36 UTC (rev 238)
@@ -1,8 +1,41 @@
 <?xml version="1.0"?>
+<!-- ***** BEGIN LICENSE BLOCK *****
+ Version: MPL 1.1/GPL 2.0/LGPL 2.1
+
+ The contents of this file are subject to the Mozilla Public License
+ Version 1.1 (the "License"); you may not use this file except in
+ compliance with the License. You may obtain a copy of the License at
+ http://www.mozilla.org/MPL/
+
+ Software distributed under the License is distributed on an "AS IS"
+ basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ License for the specific language governing rights and limitations
+ under the License.
+
+ The Original Code is SciViews-K by Philippe Grosjean et al.
+
+ Contributor(s):
+   Kamil Barton
+ 
+ Alternatively, the contents of this file may be used under the terms of
+ either the GNU General Public License Version 2 or later (the "GPL"), or
+ the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ in which case the provisions of the GPL or the LGPL are applicable instead
+ of those above. If you wish to allow use of your version of this file only
+ under the terms of either the GPL or the LGPL, and not to allow others to
+ use your version of this file under the terms of the MPL, indicate your
+ decision by deleting the provisions above and replace them with the notice
+ and other provisions required by the GPL or the LGPL. If you do not delete
+ the provisions above, a recipient may use your version of this file under
+ the terms of any one of the MPL, the GPL or the LGPL.
+
+ ***** END LICENSE BLOCK ***** -->
+
+<!-- SciViews-K's R-session manager dialog box -->
+
 <!DOCTYPE dialog SYSTEM "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" [
-  <!ENTITY % dialogsDTD SYSTEM "chrome://komodo/locale/dialogs.dtd">
+<!ENTITY % dialogsDTD SYSTEM "chrome://komodo/locale/dialogs.dtd">
   %dialogsDTD;
-]>
 <!ENTITY % sciviewskDTD SYSTEM "chrome://sciviewsk/locale/sciviewsk.dtd">
 	%sciviewskDTD;
 ]>
@@ -27,7 +60,10 @@
 <script type="text/javascript">
 <![CDATA[
 
+//TODO: Move this code to /content/js/sessions.js
+//TODO
 
+
 // Create references to main window objects:
 var mainWin, sv, ko;
 var os = Components.classes['@activestate.com/koOs;1'].getService(Components.interfaces.koIOs);
@@ -42,46 +78,49 @@
 		if (sv && ko) break;
 	}
 	mainWin = p;
+	var sf = sv.tools.file;
 
-	prefName = "sciviews.session.dir";
-	var values = sv.prefs.getString(prefName + ".mru");
-	var prefVal = sv.prefs.getString(prefName);
-	if (values) {
-		values = values.split(os.pathsep);
-		var i = values.indexOf(prefVal);
-		if (i != -1) { // Move current value onto top of list:
-			values.splice(i, 1);
-			values = Array.concat(prefVal, values);
-		}
-		if (values.length > 10)
-			values.splice(10);
-
-		var el = document.getElementById(prefName);
-		var value;
-		for (var j = 0; j < values.length; j++) {
-			value = sv.tools.file.path(values[j]);
-			el.insertItemAt(j, value, value, null);
-		}
-	}
-
 	var prefEls = document.getElementsByAttribute("pref", "true");
-	var prefName, prefVal, el;
+	var prefName, prefVal, prefSettings, prefHomeSubst, prefExistingOnly,
+		el, value, values, listContentPref;
 	for (var i = 0; i < prefEls.length; i++) {
 		el = prefEls[i];
 		prefName = el.id;
 		prefVal = sv.prefs.getString(prefName);
+		prefSettings = el.getAttribute("prefsettings");
+		if (el.hasAttribute("prefsettings")) {
+			prefSettings = el.getAttribute("prefsettings").split(" ");
+		}
+		prefHomeSubst = prefSettings.indexOf("home-subst") != -1;
+		prefExistingOnly = prefSettings.indexOf("existing-only") != -1;
 
-		if (el.getAttribute("homesubst") == "true")
-			prefVal = sv.tools.file.path(prefVal);
+		if (prefHomeSubst)
+			prefVal = sf.path(prefVal);
 
 		if (el.tagName == "menulist") {
-			var mi, values = [];
-			for (var j = 0; j < el.itemCount; j++) {
-				values.push(el.getItemAtIndex(j).value);
+
+			listContentPref = el.hasAttribute("contentpref")?
+				el.getAttribute("contentpref") : prefName + ".mru";
+
+			values = sv.prefs.getString(listContentPref);
+			if (values) {
+				//TODO: allow for other separators
+				values = values.split(os.pathsep);
+
+				var k = values.indexOf(
+					prefHomeSubst? homeSubst(prefVal) : prefVal);
+				// Move current value onto top of list:
+				if (k != -1) values.splice(k, 1);
+				values = Array.concat(prefVal, values);
+
+				if (values.length > 10)		values.splice(10);
+
+				for (var j = 0; j < values.length; j++) {
+					value = sf.path(values[j]);
+					if (!prefExistingOnly || sf.exists(value))
+						el.insertItemAt(j, value, value, null);
+				}
 			}
-			if (values.indexOf(prefVal) == -1) {
-				el.insertItemAt(0, prefVal, prefVal, null);
-			}
 		}
 		el.value = prefVal;
 	}
@@ -103,17 +142,17 @@
 	for (var i = 0; i < prefEls.length; i++) {
 		el = prefEls[i];
 		prefVal = el.value;
-		if (el.getAttribute("homesubst") == "true")
+		if (el.getAttribute("prefsettings").indexOf("home-subst") != -1)
 			prefVal = homeSubst(prefVal);
 		sv.prefs.setString(el.id, prefVal);
 	}
 
-	sv.r.setSession (document.getElementById("sciviews.session.dir").value,
-					 document.getElementById("sciviews.session.data").value,
-					 document.getElementById("sciviews.session.scripts").value,
-					 document.getElementById("sciviews.session.reports").value);
+	function _getVal(id) document.getElementById(id).value;
+	sv.r.setSession (_getVal("sciviews.session.dir"),
+					 _getVal("sciviews.session.data"),
+					 _getVal("sciviews.session.scripts"),
+					 _getVal("sciviews.session.reports"));
 
-	//alert(values.join(os.pathsep));
 	return true;
 }
 
@@ -204,8 +243,8 @@
 		}
 	}
 
-	printInfo("In this directory: " + (hasConfig? "config file exists" : "no config file") +
-			  ", " + (hasWorkspace? "saved workspace exists": "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;
@@ -257,6 +296,35 @@
 	return false;
 }
 
+
+function saveWorkspace() {
+	//TODO: if R is not running copy .RData file to "dir"
+	if (!sv.r.running) return;
+
+	var sf = sv.tools.file;
+	var addslashes = sv.tools.strings.addslashes;
+	var dir = sf.path(document.getElementById("sciviews.session.dir").value);
+
+	var rDataFile = sf.path(dir, ".RData");
+	var rHistoryFile = sf.path(dir, ".Rhistory");
+	if (!sf.exists(rDataFile) || ko.dialogs.okCancel(
+			sv.translate("Do you really want to overwrite exising workspace file"
+						 + "in \"%S\" with current workspace?", dir),
+				"Cancel", null, sv.translate("Save current workspace")
+		) == "OK") {
+			sv.r.evalCallback('save.image("' + addslashes(rDataFile) + '")',
+				selectSessionDir);
+
+		if (!sf.exists(rHistoryFile) || ko.dialogs.okCancel(
+			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) + '")');
+		}
+
+	}
+}
+
 ]]>
 </script>
 <vbox>
@@ -267,8 +335,8 @@
 				<hbox align="center">
 					<menulist id="sciviews.session.dir" oncommand="selectSessionDir();"
 							  pref="true" prefattribute="value" flex="1"
-							  homesubst="true">
-						<menupopup id="sciviews_menu_select_r_application" />
+							  prefsettings="dir existing-only home-subst">
+						<menupopup />
 					</menulist>
 					<button label="Browse..."
 					oncommand="setDir('sciviews.session.dir');"/>
@@ -299,6 +367,9 @@
 						<button id="delete-workspace-button"
 								label="Delete R workspace"
 								oncommand="clearFiles('workspace');"/>
+						<button id="delete-workspace-button"
+								label="Save current workspace here"
+								oncommand="saveWorkspace();"/>
 					</hbox>
 				</vbox>
 			</vbox>



More information about the Sciviews-commits mailing list