[Sciviews-commits] r361 - komodo/SciViews-K-dev/content

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Mar 7 23:46:03 CET 2011


Author: prezez
Date: 2011-03-07 23:46:03 +0100 (Mon, 07 Mar 2011)
New Revision: 361

Modified:
   komodo/SciViews-K-dev/content/sessions.xul
Log:
Session manager: list of directories includes current and last Places's root

Modified: komodo/SciViews-K-dev/content/sessions.xul
===================================================================
--- komodo/SciViews-K-dev/content/sessions.xul	2011-03-07 14:15:13 UTC (rev 360)
+++ komodo/SciViews-K-dev/content/sessions.xul	2011-03-07 22:46:03 UTC (rev 361)
@@ -56,7 +56,7 @@
 ondialogextra1="OK();"
 title="R Session manager"
 persist="screenX screenY"
-		>
+>
 <script type="text/javascript">
 <![CDATA[
 
@@ -82,48 +82,54 @@
 	mainWin = p;
 	var sf = sv.tools.file;
 
+
+	var lastPlaces = [ko.places.manager.lastHomePlace, ko.places.manager.currentPlace]
+		.map(sv.tools.file.pathFromURI);
+
+	function hasPrefSetting(name, el) {
+		if (!el.hasAttribute("prefsettings")) return false;
+		var prefSettings = el.getAttribute("prefsettings").split(" ");
+		return prefSettings.indexOf(name) != -1;
+	}
+
+
 	var prefEls = document.getElementsByAttribute("pref", "true");
-	var prefName, prefVal, prefSettings, prefHomeSubst, prefExistingOnly,
+	var prefName, prefVal, prefHomeSubst, prefExistingOnly,
 	el, value, values, listContentPref;
 	for (var i = 0; i < prefEls.length; i++) {
 		el = prefEls[i];
 		prefName = el.id;
 		prefVal = sv.pref.getPref(prefName);
-		//prefSettings = el.getAttribute("prefsettings");
-		if (el.hasAttribute("prefsettings")) {
-			prefSettings = el.getAttribute("prefsettings").split(" ");
-		} else {
-			prefSettings = '';
-		}
-		prefHomeSubst = prefSettings.indexOf("home-subst") != -1;
-		prefExistingOnly = prefSettings.indexOf("existing-only") != -1;
+		prefHomeSubst = hasPrefSetting("home-subst", el);
+		prefExistingOnly = hasPrefSetting("existing-only", el);
 
 		if (prefHomeSubst)
 			prefVal = sf.path(prefVal);
 
 		if (el.tagName == "menulist") {
-
 			listContentPref = el.hasAttribute("contentpref")?
-			el.getAttribute("contentpref") : prefName + ".mru";
+			el.getAttribute("contentpref") : prefName + '.mru';
 
-			values = sv.pref.getPref(listContentPref);
+			values = sv.pref.getPref(listContentPref, '').split(os.pathsep);
+			if(hasPrefSetting('add-recent', el)) {
+				values = Array.concat(lastPlaces, values);
+			}
+
 			if (values) {
-				//TODO: allow for other separators
-				values = values.split(os.pathsep);
-
-				var k = values.indexOf(
-				prefHomeSubst? homeSubst(prefVal) : prefVal);
+				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);
+				values = Array.concat(prefVal, values).filter(function(x) x != '');
+				values = values.map(function(x) sf.path(x));
+				if (prefExistingOnly) {
+					values = values.filter(function(x) sf.exists(x) == sf.TYPE_DIRECTORY);
+				}
+				values = sv.tools.array.unique(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);
-				}
+				values.forEach(function(value) el.insertItemAt(value, value, value, null));
+
 			}
 		} else if (el.tagName == "checkbox") {
 			el.checked = (prefVal == "true");
@@ -193,13 +199,18 @@
 }
 
 // Add a directory item into list
-function setDir(id) {
+function setDir(id, relId) {
 	var el = document.getElementById(id);
 	var dir = ko.filepicker.getFolder(el.value, "Choose directory for: " + id);
-
+	var baseDir;
+	if(relId) {
+		baseDir = document.getElementById(relId).value;
+		if(baseDir) {
+			dir = os.path.relpath(dir, os.normpath(baseDir));
+		}
+	}
 	if (!dir) return (false);
 
-
 	var mi;
 	for (var j = 0; j < el.itemCount; j++) {
 		if (el.getItemAtIndex(j).value == dir) {
@@ -356,7 +367,7 @@
 				<hbox align="center">
 					<menulist id="sciviews.session.dir" oncommand="selectSessionDir();"
 							  pref="true" prefattribute="value" flex="1"
-							  prefsettings="dir existing-only home-subst">
+							  prefsettings="dir existing-only home-subst add-recent">
 						<menupopup />
 					</menulist>
 					<button label="Browse..."



More information about the Sciviews-commits mailing list