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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 9 02:53:25 CET 2011


Author: prezez
Date: 2011-03-09 02:53:25 +0100 (Wed, 09 Mar 2011)
New Revision: 362

Modified:
   komodo/SciViews-K/content/RObjectsOverlay.xul
   komodo/SciViews-K/content/js/robjects.js
   komodo/SciViews-K/content/js/tools/array.js
   komodo/SciViews-K/content/overlayMain.xul
   komodo/SciViews-K/content/sessions.xul
Log:
R object browser: simplified enabling items in the context menu (with "testDisableIf" attribute), new command: save selected items as .RData
sv.tools.array - added: .duplicates, some functions rewritten with new Array methods (js v1.6)
Session manager: list of directories includes current and last Places's root

Modified: komodo/SciViews-K/content/RObjectsOverlay.xul
===================================================================
--- komodo/SciViews-K/content/RObjectsOverlay.xul	2011-03-07 22:46:03 UTC (rev 361)
+++ komodo/SciViews-K/content/RObjectsOverlay.xul	2011-03-09 01:53:25 UTC (rev 362)
@@ -54,47 +54,97 @@
 
 
 	<popupset id="extensionPopupSet">
-		<menupopup id="rObjectsContext"
-		onpopupshowing="sv.r.objects.contextOnShow();">
-			<menuitem class="primary_menu_item" id="menu_robjects_cmd_insertfullname"
-			command="robjects_cmd_insertfullname" acceltext="Ins"/>
-			<menuitem id="menu_robjects_cmd_insertname"
-			command="robjects_cmd_insertname" acceltext="Ctrl+Ins"/>
-			<menuitem id="menu_robjects_cmd_insertquoted"
-			command="robjects_cmd_insertquoted" acceltext="Shift+Ins"/>
+		<menupopup id="rObjectsContext" onpopupshowing="sv.r.objects.contextOnShow(event);">
+			<menuitem id="menu_robjects_insertfullname"
+				class="primary_menu_item"
+				oncommand="sv.r.objects.insertName(true)"
+				accesskey="F"
+				label="&sciviews.robjects.insFullName;"
+				acceltext="Ins" />
+			<menuitem id="menu_cmd_robjects_insertquoted"
+				label="&sciviews.robjects.insertQuoted;"
+				oncommand="sv.r.objects.insertName(false, true);"
+				accesskey="&sciviews.robjects.insertQuoted.acc;"
+				acceltext="Shift+Ins" />
+			<menuitem id="menu_robjects_insertname"
+				label="&sciviews.robjects.insName;"
+				oncommand="sv.r.objects.insertName(false)"
+				accesskey="I"
+				acceltext="Ctrl+Ins" />
 
 			<menuseparator keep="false" intoplevel="true"/>
 
-			<menuitem id="menu_robjects_cmd_removeobj"
-			command="robjects_cmd_removeobj" acceltext="Del"
+			<menuitem id="cmd_robjects_removeobj"
+				label="&sciviews.robjects.rmObj;"
+				oncommand="sv.r.objects.removeSelected(event.shiftKey)"
+				accesskey="R"
+				acceltext="Del"
+				testDisableIf="t:noDelete"
 			key="key_cmd_delete" />
-			<menuitem id="menu_robjects_cmd_deletenow"
-			command="robjects_cmd_deletenow" class="menuitem-iconic list-item-remove-icon"
-			acceltext="Shift+Del"/>
+			<menuitem id="menu_cmd_robjects_deletenow"
+				label="&sciviews.robjects.deleteNow;"
+				oncommand="sv.r.objects.removeSelected(true);"
+				class="menuitem-iconic list-item-remove-icon"
+				acceltext="Shift+Del"
+				testDisableIf="t:noDelete"
+				accesskey="&sciviews.robjects.deleteNow.acc;" />
 
 			<menuseparator keep="false" intoplevel="true"/>
+			<menuitem id="cmd_robjects_summary"
+				label="&sciviews.robjects.summary;"
+				oncommand="sv.r.objects.do('summary')"
+				testDisableIf="t:isFunction t:isEnvironment"
+				accesskey="S" />
+			<menuitem id="cmd_robjects_print"
+				label="&sciviews.robjects.print;"
+				oncommand="sv.r.objects.do('print')"
+				testDisableIf="t:isPackage"
+				accesskey="P" />
+			<menuitem id="cmd_robjects_plot"
+				label="&sciviews.robjects.plot;"
+				oncommand="sv.r.objects.do('plot')"
+				testDisableIf="t:isFunction t:isEnvironment"
+				accesskey="O"/>
+			<menuitem id="cmd_robjects_str"
+				label="&sciviews.robjects.str;"
+				oncommand="sv.r.objects.do('str')"
+				testDisableIf="t:isPackage"
+				accesskey="T"/>
 
-			<menuitem id="menu_robjects_cmd_selectall"
-			command="robjects_cmd_selectall" acceltext="Ctrl+A"/>
-			<menuitem id="menu_robjects_cmd_selectsiblings"
-			command="robjects_cmd_selectsiblings" acceltext="Ctrl+Shift+A"/>
+			<menuseparator keep="false" intoplevel="true"/>
+			<menuitem id="menu_cmd_robjects_selectall"
+				label="&sciviews.robjects.selectAll;"
+				oncommand="sv.r.objects.selection.selectAll();"
+				accesskey="&sciviews.robjects.selectAll.acc;"
+				acceltext="Ctrl+A" />
+			<menuitem id="menu_cmd_robjects_selectsiblings"
+				label="&sciviews.robjects.selectSiblings;"
+				oncommand="sv.r.objects.selectAllSiblings(sv.r.objects.selection.currentIndex);"
+				accesskey="&sciviews.robjects.selectSiblings.acc;"
+				acceltext="Ctrl+Shift+A" />
 
-			<!--<menuitem id="menu_robjects_cmd_attach" command="robjects_cmd_attach"/>
-			<menuitem id="menu_robjects_cmd_detach" command="robjects_cmd_detach"/>-->
 			<menuseparator keep="false" intoplevel="true"/>
-			<menuitem id="menu_robjects_cmd_print" command="robjects_cmd_print"/>
-			<menuitem id="menu_robjects_cmd_plot" command="robjects_cmd_plot"/>
-			<menuitem id="menu_robjects_cmd_summary" command="robjects_cmd_summary"/>
-			<menuitem id="menu_robjects_cmd_str" command="robjects_cmd_str"/>
-			<!--<menuitem id="menu_robjects_cmd_args" command="robjects_cmd_args"/>-->
-			<menuitem id="menu_robjects_cmd_names" command="robjects_cmd_names"/>
+			<menuitem id="menu_cmd_robjects_write_table"
+				class="menuitem-iconic save-buffer-icon"
+				label="&sciviews.robjects.write_table;"
+				oncommand="sv.r.objects.do('write.table')"
+				testDisableIf="t:cannotSaveToFile"
+				accesskey="T"/>
 
-			<menuitem id="menu_robjects_cmd_write_table"
+			<menuitem id="menu_cmd_robjects_save"
 			class="menuitem-iconic save-buffer-icon"
-			command="robjects_cmd_write_table"/>
+				label="&sciviews.robjects.save;"
+				oncommand="sv.r.objects.do('save')"
+				testDisableIf="t:cannotSave"
+				accesskey="S" />
 
 			<menuseparator keep="false" intoplevel="true"/>
-			<menuitem id="menu_robjects_cmd_help" command="robjects_cmd_help"/>
+			<menuitem id="menu_cmd_robjects_help"
+				label="&sciviews.robjects.help;"
+				oncommand="sv.r.objects.do('help')"
+				class="menuitem-iconic help-icon"
+				testDisableIf="t:multipleSelection t:noHelp"
+				accesskey="H" />
 			</menupopup>
 		</popupset>
 
@@ -107,48 +157,7 @@
 		checked="true" state="open"/>
 		</broadcasterset>
 
-	<commandset id="allcommands">
-		<commandset id="r-objects-commands">
-			<command id="robjects_cmd_insertfullname" label="&sciviews.robjects.insFullName;"
-			oncommand="sv.r.objects.insertName(true);" accesskey="F"/>
-			<command id="robjects_cmd_insertname" label="&sciviews.robjects.insName;"
-			oncommand="sv.r.objects.insertName(false);" accesskey="I"/>
-			<command id="robjects_cmd_removeobj" label="&sciviews.robjects.rmObj;"
-			oncommand="sv.r.objects.removeSelected(event.shiftKey);" accesskey="R"/>
-				<!--<command id="robjects_cmd_attach" label="&sciviews.robjects.loadPkg;"
-				oncommand="sv.r.objects.do('library');" accesskey="L" disabled="true"/>-->
-			<command id="robjects_cmd_summary" label="&sciviews.robjects.summary;"
-			oncommand="sv.r.objects.do('summary');" accesskey="S"/>
-			<command id="robjects_cmd_print" label="&sciviews.robjects.print;"
-			oncommand="sv.r.objects.do('print');" accesskey="P"/>
-			<command id="robjects_cmd_plot" label="&sciviews.robjects.plot;"
-			oncommand="sv.r.objects.do('plot');" accesskey="O"/>
-			<command id="robjects_cmd_str" label="&sciviews.robjects.str;"
-			oncommand="sv.r.objects.do('str');" accesskey="T"/>
-			<command id="robjects_cmd_names" label="&sciviews.robjects.names;"
-			oncommand="sv.r.objects.do('names');" accesskey="N"/>
 
-			<command id="robjects_cmd_write_table" label="&sciviews.robjects.write_table;"
-			oncommand="sv.r.objects.do('write.table');" accesskey="T"/>
-
-
-			<command id="robjects_cmd_help" label="&sciviews.robjects.help;"
-			oncommand="sv.r.objects.do('help');" accesskey="H"/>
-
-			<command id="robjects_cmd_deletenow" label="&sciviews.robjects.deleteNow;"
-			oncommand="sv.r.objects.removeSelected(true);" accesskey="&sciviews.robjects.deleteNow.acc;"/>
-			<command id="robjects_cmd_insertquoted" label="&sciviews.robjects.insertQuoted;"
-			oncommand="sv.r.objects.insertName(false, true);" accesskey="&sciviews.robjects.insertQuoted.acc;"/>
-			<command id="robjects_cmd_selectall" label="&sciviews.robjects.selectAll;"
-			oncommand="sv.r.objects.selection.selectAll();" accesskey="&sciviews.robjects.selectAll.acc;"/>
-			<command id="robjects_cmd_selectsiblings" label="&sciviews.robjects.selectSiblings;"
-			oncommand="sv.r.objects.selectAllSiblings(sv.r.objects.selection.currentIndex);"
-			accesskey="&sciviews.robjects.selectSiblings.acc;"/>
-
-
-		</commandset>
-	</commandset>
-
 	<menupopup id="tabPicker_popup">
 		<menuitem id="show_robjects_tab"
 		insertafter="show_runoutput_tab,show_codebrowser_tab"

Modified: komodo/SciViews-K/content/js/robjects.js
===================================================================
--- komodo/SciViews-K/content/js/robjects.js	2011-03-07 22:46:03 UTC (rev 361)
+++ komodo/SciViews-K/content/js/robjects.js	2011-03-09 01:53:25 UTC (rev 362)
@@ -1164,10 +1164,10 @@
 		return;
 	}
 
-	this.contextOnShow = function () {
+this.contextOnShow = function (event) {
 		var currentIndex = _this.selection.currentIndex;
+	if (currentIndex == -1) return;
 
-		if (currentIndex != -1) {
 			var isEnvironment, isPackage, isInPackage, noDelete, isFunction;
 			var item, type, name;
 			item = _this.visibleData[currentIndex].origItem;
@@ -1183,68 +1183,98 @@
 				|| isInPackage;
 			isFunction = type == "function";
 
-			var canSaveToFile = ["data.frame", "matrix", "table"]
-				.indexOf(item.class) > -1;
+	var cannotSaveToFile = ["data.frame", "matrix", "table"].indexOf(item.class) == -1;
+	var cannotSave = _this.selectedItemsOrd.filter(function(x)
+		x.type == 'object' && x.group != 'function').length == 0;
 
-			var selItemCount = _this.selection.count;
+	var multipleSelection = _this.selection.count > 1;
 
 			// Help can be shown only for one object:
-			var hasHelp = (selItemCount == 1)
-				&& (isPackage || isInPackage);
+	var noHelp = !isPackage || !isInPackage;
 
-			//sv.cmdout.append(name
-			//	+ "; isPackage:" + isPackage
-			//	+ "; isEnvironment:" + isEnvironment
-			//	+ "; noDelete:" + noDelete
-			//	+ "; isInPackage:" + isEnvironment
-			//	+ "; isFunction:" + isFunction
-			//	+ "; hasHelp:" + hasHelp
-			//)
+	//var menuNode = document.getElementById("rObjectsContext");
+	var menuItems = event.target.childNodes;
+	var testDisableIf, disable = false;
 
-			document.getElementById("robjects_cmd_removeobj")
-				.setAttribute("disabled", noDelete);
-			document.getElementById("robjects_cmd_deletenow")
-				.setAttribute("disabled", noDelete);
-			//document.getElementById("robjects_cmd_attach")
-			//	.setAttribute("disabled", noDelete || !isPackage);
-			document.getElementById("robjects_cmd_summary")
-				.setAttribute("disabled", isFunction || isEnvironment);
-			document.getElementById("robjects_cmd_print")
-				.setAttribute("disabled", isPackage);
-			document.getElementById("robjects_cmd_plot")
-				.setAttribute("disabled", isFunction || isEnvironment);
-			document.getElementById("robjects_cmd_names")
-				.setAttribute("disabled", isFunction);
-			document.getElementById("robjects_cmd_str")
-				.setAttribute("disabled", isPackage);
-			document.getElementById("robjects_cmd_write_table")
-				.setAttribute("disabled", !canSaveToFile);
 
-			// Disable help option for non-package objects,
-			// because usually there is none
-			document.getElementById("robjects_cmd_help")
-				.setAttribute("disabled", !hasHelp);
+	for(var i = 0; i < menuItems.length; i++) {
+		if (!menuItems[i].hasAttribute('testDisableIf')) continue;
+		testDisableIf = menuItems[i].getAttribute('testDisableIf').split(/\s+/);
+		disable = false;
+
+		for(var j = 0; j < testDisableIf.length && !disable; j++) {
+			switch(testDisableIf[j]){
+				case 't:multipleSelection':
+					disable = multipleSelection;
+					break;
+				case 't:noHelp':
+					disable = noHelp;
+					break;
+				case 't:isFunction':
+					disable = isFunction;
+					break;
+				case 't:isEnvironment':
+					disable = isEnvironment;
+					break;
+				case 't:isPackage':
+					disable = isPackage;
+					break;
+				case 't:cannotSaveToFile':
+					disable = cannotSaveToFile;
+					break;
+				case 't:cannotSave':
+					disable = cannotSave;
+					break;
+				case 't:noDelete':
+					disable = noDelete;
+					break;
+				default: ;
+			}
 		}
+		//print( menuItems[i].id + ": " + testDisableIf + " = " + disable);
+		menuItems[i].setAttribute('disabled', disable);
+		}
 	}
 
 	this.do = function (action) {
-		var obj = [];
-		var rows = _this.getSelectedRows();
+		var obj = _this.selectedItemsOrd;
+		var command;
+	switch(action) {
+		case 'save':
+			// Select only objects:
+			obj = obj.filter(function(x) { if(x.type != "object") {
+				_this.selection.toggleSelect(x.index); return false }
+				else return true});
 
-		for (i in rows)
-			obj.push(_this.visibleData[rows[i]].origItem);
+			var dup = sv.tools.array.duplicates(obj.map(function(x) x.name));
+			if(dup.length &&
+			   ko.dialogs.okCancel("Objects with the same names from different" +
+				"environments selected. Following object will be taken from the " +
+				"foremost location in the search path: " + dup.join(', '),
+				"Cancel") == "Cancel") return;
 
-		var command;
+			var fileName = (obj.length == 1)? obj[0].name
+				.replace(/[\/\\:\*\?"<>\|]/g, '_') : '';
 
-		switch(action) {
+			var dir = sv.tools.file.pathFromURI(ko.places.manager.currentPlace);
+
+			fileName = sv.fileOpen(dir, fileName + '.RData', '',
+				["R data (*.RData)|*.RData"], false, true, oFilterIdx = {});
+
+			if (!fileName) return;
+			command = 'save(list=c(' + obj.map(function(x) '"' + x.name + '"')
+				.join(',')	+ '), file="' + fileName.addslashes() + '")';
+
+			sv.r.eval(command);
+		break;
 		 // Special handling for help
 		 case 'help':
 			for (i in obj) {
 				// Help only for packages and objects inside a package
-				if (obj[i].env.indexOf("package:") == 0) {
+			if (obj[i].fullName.indexOf("package:") == 0) {
+				sv.r.help("", obj[i].fullName.replace(/^package:/, ''));
+			} else if (obj[i].env.indexOf("package:") == 0) {
 					sv.r.help(obj[i].fullName, obj[i].env.replace(/^package:/, ''));
-				} else if (obj[i].fullName.indexOf("package:") == 0) {
-					sv.r.help("", obj[i].fullName.replace(/^package:/, ''));
 				} else {
 					sv.r.help(obj[i].fullName);
 				}
@@ -1289,11 +1319,15 @@
 
 	this.selectedItemsOrd = [];
 
-	this.onEvent = function (event) {
+this.onEvent = function on_Event(event) {
 		switch (event.type) {
 		 case "select":
 			var selectedRows = _this.getSelectedRows();
 			var selectedItems = [];
+
+			if (selectedRows.some(function(x) x >= _this.visibleData.length))
+				return false;
+
 			for (var i = 0; i < selectedRows.length; i++)
 				selectedItems.push(_this.visibleData[selectedRows[i]].origItem);
 			var curRowIdx = selectedRows.indexOf(_this.selection.currentIndex);
@@ -1314,23 +1348,16 @@
 				}
 			}
 			_this.selectedItemsOrd = newItems;
-			return;
+
+			return false;
 		 case "keyup":
 		 case "keypress":
 			var key = event.keyCode ? event.keyCode : event.charCode;
 			switch (key) {
-			 //case 38: // up
-			 //case 40: // down
-			//	if (event.shiftKey) {
-			//		sv.log.debug("Select: " +
-			//          _this.visibleData[_this.selection.currentIndex]
-			//          .origItem.name);
-			//	}
-			//	return;
 			 case 46: // Delete key
 				_this.removeSelected(event.shiftKey);
 				event.originalTarget.focus();
-				return;
+				return false;
 			 case 45: // Insert
 			 case 32: // Space
 				//sv.log.debug("Insert");
@@ -1345,7 +1372,7 @@
 					}
 				}
 			 case 0:
-				return;
+				return false;
 			 case 93:
 				// Windows context menu key
 				var contextMenu = document.getElementById("rObjectsContext");
@@ -1358,18 +1385,18 @@
 
 			 // TODO: Escape key stops retrieval of R objects
 			 default:
-				return;
+				return false;
 			}
 			break;
 		 case "dblclick":
-			if (event.button != 0) return;
+			if (event.button != 0) return false;
 			if (_this.selection && (_this.selection.currentIndex == -1
 				|| _this.isContainer(_this.selection.currentIndex)))
-				return;
+				return false;
 			break;
 		 case "click":
 		 case "draggesture":
-			return;
+			return false;
 		 default:
 		}
 
@@ -1379,6 +1406,7 @@
 		// This does not have any effect
 		//document.getElementById("sciviews_robjects_objects_tree").focus();
 		event.originalTarget.focus();
+	return false;
 	}
 
 	// Drag & drop handling for search paths list
@@ -1421,7 +1449,6 @@
 		},
 	//	onDragEnter: function (event, flavour, session) {
 	//		sv.log.debug(event.type + ":" + session);
-	////package:gpclibpackage:adehabitat
 	//		//sv.xxx = session;
 	//	},
 		//

Modified: komodo/SciViews-K/content/js/tools/array.js
===================================================================
--- komodo/SciViews-K/content/js/tools/array.js	2011-03-07 22:46:03 UTC (rev 361)
+++ komodo/SciViews-K/content/js/tools/array.js	2011-03-09 01:53:25 UTC (rev 362)
@@ -7,25 +7,28 @@
 // sv.tools.array.contains(a, s);   // Does array 'a' contain 's'
 // sv.tools.array.removeItem(a, s); // Return an array with 's' removed from 'a'
 //
-// Additional methods to Array objects /////////////////////////////////////////
-// Note: not used yet and generates an error in loading Komodo! => disabled!
-// Array.prototype.makeunique();	// New array with duplicate values removed
-// Array.prototype.getintersect(); 	// Compute the intersection of n arrays
-// Array.prototype.rassemble();		// Get the union of n arrays
+// Warning: adding to Array.prototype has REALLY strange side effects. No idea why.
 ////////////////////////////////////////////////////////////////////////////////
 
 // Define the 'sv.tools.array' namespace
+if (typeof(sv) == 'undefined') sv = {};
+if (typeof(sv.tools) == 'undefined') sv.tools = {};
 if (typeof(sv.tools.array) == 'undefined') sv.tools.array = {};
 
-// Remove 's' from the array 'a'
-sv.tools.array.remove = function (a, s) {
-	for (i = 0; i < a.length; i++)
-		if (s == a[i]) a.splice(i, 1);
-}
+sv.tools.array.contains = function array_contains (arr, s) (arr.indexOf(s) !== -1);
 
-// Does the array 'a' contain 's'?
-sv.tools.array.contains = function (a, s) {
-	return(a.indexOf(s) !== -1);
+sv.tools.array.unique = function array_unique(arr)
+	arr.reduce(function(a, j) {
+		if(a.indexOf(j)==-1) a.push(j);
+		return(a)}, []);
+
+sv.tools.array.remove = function array_remove(arr, item) arr.filter(function(x) x !== item);
+
+sv.tools.array.duplicates = function array_duplicates(arr) {
+	var dup = [];
+	arr.forEach(function(el, i, a) {
+		if(i > 0 && a.lastIndexOf(el, i - 1) != -1) dup.push(el) });
+	return dup;
 }
 
 // Return an array from which 's' item is eliminated from the array 'a'
@@ -36,21 +39,8 @@
 	return(b);
 }
 
-sv.tools.array.unique = function(a) {
-    var res = [];
-    var l = a.length;
-	for (var i in a) {
-		if (res.indexOf(a[i]) != -1) continue;
-		res.push(a[i]);
-	}
-	return(res);
-}
 
-
-
 //// Additional methods to Array objects ///////////////////////////////////////
-//// Return new array with duplicate values removed
-//
 //// Compute the intersection of n arrays
 //Array.prototype.getintersect = function () {
 //	if (!arguments.length)

Modified: komodo/SciViews-K/content/overlayMain.xul
===================================================================
--- komodo/SciViews-K/content/overlayMain.xul	2011-03-07 22:46:03 UTC (rev 361)
+++ komodo/SciViews-K/content/overlayMain.xul	2011-03-09 01:53:25 UTC (rev 362)
@@ -316,14 +316,15 @@
 
 <menupopup id="places-files-popup">
 	<menuseparator id="placesContextMenu_separatorR"
-		testEval_HideIf="ko.places.manager.getSelectedItems().filter(function(x) /\.[Rr]$/.test(x.name)).length == 0"
+		testEval_HideIf="ko.places.manager.getSelectedItems().some(function(x) /\.[Rr]$/.test(x.name))"
 	/>
-<menuitem oncommand="sv.command.sourcePlacesSelection()"
+<menuitem desc="General: Edit Properties"
+		  oncommand="sv.command.sourcePlacesSelection()"
 		  disableIf="folder"
 		  class="menuitem-iconic"
 		  id="placesContextMenu_Rsource"
 		  label="Source into R"
-		  testEval_HideIf="ko.places.manager.getSelectedItems().filter(function(x) /\.[Rr]$/.test(x.name)).length == 0"
+		  testEval_HideIf="ko.places.manager.getSelectedItems().some(function(x) /\.[Rr]$/.test(x.name))"
 />
 </menupopup>
 

Modified: komodo/SciViews-K/content/sessions.xul
===================================================================
--- komodo/SciViews-K/content/sessions.xul	2011-03-07 22:46:03 UTC (rev 361)
+++ komodo/SciViews-K/content/sessions.xul	2011-03-09 01:53:25 UTC (rev 362)
@@ -82,22 +82,28 @@
 	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.prefs.getString(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);
 
@@ -106,24 +112,28 @@
 			listContentPref = el.hasAttribute("contentpref")?
 			el.getAttribute("contentpref") : prefName + ".mru";
 
-			values = sv.prefs.getString(listContentPref);
+			values = sv.prefs.getString(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");



More information about the Sciviews-commits mailing list