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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu May 21 19:55:53 CEST 2009


Author: prezez
Date: 2009-05-21 19:55:53 +0200 (Thu, 21 May 2009)
New Revision: 133

Added:
   komodo/SciViews-K/sciviewsk-0.7.4-beta-ko.xpi
Modified:
   komodo/SciViews-K/content/RBrowserOverlay.xul
   komodo/SciViews-K/content/js/robjects.js
   komodo/SciViews-K/content/js/sciviews.js
Log:
Object browser: 
added: smarter inserting of object names (modified with Ctrl/Shift).
fixed: Sorting direction no longer changes on list update
better mouse/key event handling, other small changes

changed: "sv.cmdout.append" now scrolls to end of page, rather than beginning of new text (new default behavior).
(new working xpi: build no 0.7.4)


Modified: komodo/SciViews-K/content/RBrowserOverlay.xul
===================================================================
--- komodo/SciViews-K/content/RBrowserOverlay.xul	2009-05-20 14:00:03 UTC (rev 132)
+++ komodo/SciViews-K/content/RBrowserOverlay.xul	2009-05-21 17:55:53 UTC (rev 133)
@@ -207,7 +207,6 @@
 						accesskey="a"
 						class="menuitem-iconic r-data-attach"
 						oncommand="sv.r.loadWorkspace(null, true);" />
-
 			  <menuitem id="r_objects_pkg_install"
 						label="Install..."
 						accesskey="i"
@@ -277,11 +276,11 @@
 		  flex="1"
           >
           <listbox flex="1" id="sciviews_robjects_searchpath_listbox"
-	    ondragdrop="nsDragAndDrop.drop(event,window.rObjectsTree.packageListObserver);"
-	    ondragover="nsDragAndDrop.dragOver(event,rObjectsTree.packageListObserver);"
-	    onkeypress="rObjectsTree.packageListKeyEvent(event);"
-	    oncommand="rObjectsTree.packageSelectedEvent(event);"
-	    />
+			ondragdrop="nsDragAndDrop.drop(event, window.rObjectsTree.packageListObserver);"
+			ondragover="nsDragAndDrop.dragOver(event, rObjectsTree.packageListObserver);"
+			onkeypress="rObjectsTree.packageListKeyEvent(event);"
+			oncommand="rObjectsTree.packageSelectedEvent(event);"
+			/>
         </vbox>
         <splitter
           id="sciviews_robjects_splitter"
@@ -298,7 +297,8 @@
               persist="sortDirection sortResource"
               sortDirection="ascending" sortResource="r-name"
 			  enableColumnDrag="true"
-			  onkeyup = "rObjectsTree.onEvent(event);"
+			  onselect="rObjectsTree.onEvent(event);"
+			  onkeypress="rObjectsTree.onEvent(event);"
               >
             <treecols>
               <treecol

Modified: komodo/SciViews-K/content/js/robjects.js
===================================================================
--- komodo/SciViews-K/content/js/robjects.js	2009-05-20 14:00:03 UTC (rev 132)
+++ komodo/SciViews-K/content/js/robjects.js	2009-05-21 17:55:53 UTC (rev 133)
@@ -589,24 +589,26 @@
 
 
 this.sort =  function(column) {
-	var columnName;
-	var tree = document.getElementById("sciviews_robjects_objects_tree");
-	var sortDirection = tree.getAttribute("sortDirection");
-	var order = sortDirection == "ascending" ? 1 : (sortDirection == "descending" ? -1 : 0);
-	if (++order > 1) order = -1;
+	var columnName, currentElement, tree, sortDirection, realOrder, order, sortDirs;
+	tree = document.getElementById("sciviews_robjects_objects_tree");
+	sortDirection = tree.getAttribute("sortDirection");
 
+	sortDirs = ["descending", "natural", "ascending", "descending"];
+	realOrder = sortDirs.indexOf(sortDirection) - 1;
+
 	try {
-		var currentElement = this.visibleData[this.selection.currentIndex].origItem;
+		currentElement = this.visibleData[this.selection.currentIndex].origItem;
 	} catch (e) {
-		var currentElement = null;
+		currentElement = null;
 	}
 
 	//if the column is passed and it's already sorted by that column, reverse sort
 	if (column) {
 		columnName = column.id;
-		if (tree.getAttribute("sortResource") == columnName) {
-			order *= -1;
-		}
+		if (tree.getAttribute("sortResource") == columnName)
+			realOrder = ((realOrder + 2) % 3) - 1;
+		else
+			realOrder = 1;
 	} else {
 		columnName = tree.getAttribute("sortResource");
 	}
@@ -618,13 +620,12 @@
 	if (typeof(sCol) == "undefined")
 		sCol = 0;
 
-	if (typeof(order) == "undefined")
-		order = 1;
-
 	// sort using original element order:
-	if (order == 0) {
+	if (realOrder == 0) {
 		sCol = 4;
 		order = 1;
+	} else {
+		order = realOrder;
 	}
 
 	function _sortCompare(a, b) {
@@ -654,20 +655,10 @@
 		}
 	}
 
-	switch(sortDirection){
-		case "descending":
-			sortDirection = "";
-			break;
-		case "ascending":
-			sortDirection = "descending";
-			break;
-		default:
-			sortDirection = "ascending"
-	}
+	sortDirection = sortDirs[realOrder + 1];
+
 	//setting these will make the sort option persist
 	tree.setAttribute("sortDirection", sortDirection);
-	//tree.setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
-
 	tree.setAttribute("sortResource", columnName);
 
 	var cols = tree.getElementsByTagName("treecol");
@@ -675,7 +666,6 @@
 		cols[i].removeAttribute("sortDirection");
 	}
 
-	//document.getElementById(columnName).setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
 	document.getElementById(columnName).setAttribute("sortDirection", sortDirection);
 
 	// sort packages always by name:
@@ -930,6 +920,7 @@
 // Drag'n'drop support
 this.listObserver = {
 	onDragStart: function (event, transferData, action) {
+		_this.onEvent(event);
 		var namesArr = _this.getSelectedNames(event.ctrlKey);
 		transferData.data = new TransferData();
 		transferData.data.addDataForFlavour("text/unicode", namesArr.join(', '));
@@ -1045,7 +1036,6 @@
 	if (selectedPackages.length == 0)
 		selectedPackages.push('.GlobalEnv');
 
-	// for use with modified objList
 	var cmd = 'invisible(sapply(c("' + selectedPackages.join('","')	+ '"), function(x) '
 		+ 'print(objList(envir = x, all.info = FALSE, compare = FALSE), sep = "' + sep + '", raw.output = TRUE, header = TRUE)))';
 
@@ -1160,9 +1150,9 @@
 	return true;
 }
 
-this.getSelectedNames = function(fullNames, dblQuoteSubObjects) {
-	if (typeof dblQuoteSubObjects == 'undefined')
-		dblQuoteSubObjects = false;
+this.getSelectedNames = function(fullNames, extended) {
+	if (typeof extended == 'undefined')
+		extended = false;
 	var rows = this.getSelectedRows();
 	var namesArr = new Array();
 	var cellText, item;
@@ -1172,47 +1162,42 @@
 		item = selectedItemsOrd[i];
 		cellText = item[name];
 
-		// optimize this later...
 		if (cellText) {
-			if (name == "name" || item.type == 'object') {
-				if (dblQuoteSubObjects && item.type == "sub-object") {
-					cellText = "\"" + cellText + "\"";
-				} else if (cellText.search(/^[a-z\.][\w\._]*$/i) == -1)
-					cellText = "`" + cellText + "`";
-				if (item.type == "args" && name == "name")
-					cellText += "="; // attach '=' to function args, but not to full names
+			if ((!fullNames || item.type == "object")
+				&& cellText.search(/^[a-z\.][\w\._]*$/i) == -1) {
+				cellText = "`" + cellText + "`";
 			}
+			if (!fullNames && extended) {
+				if (item.type == "sub-object")
+					cellText = '"' + cellText + '"';
+				else if (item.group == "function")
+					cellText += "()";
+				else if (item.type == "args")
+					cellText += "="; // attach '=' to function args
+			}
 		}
-
-		/*if (cellText && (name == "name" || item.type == 'object')) {
-			if (cellText.search(/^[a-z\.][\w\._]*$/i) == -1)
-				cellText = "`" + cellText + "`";
-		}*/
-
 		namesArr.push(cellText);
-
-
-		//if (cellText != "") {
-		//	if (item.type == 'object' &&
-		//		cellText.search(/^[a-z\.][\w\._]*$/i) == -1)
-		//		cellText = "`" + cellText + "`";
-		//	else if (item.type == "args" && name == "name")
-		//		cellText += "="; // attach '=' to function args, but not to full names
-		//	namesArr.push(cellText);
-		//}
-
 	}
 	return (namesArr);
 }
 
-this.insertName = function(fullNames) {
+this.insertName = function(fullNames, extended) {
 	var view = ko.views.manager.currentView;
 	if (!view)
 		return;
-	var namesArr = _this.getSelectedNames(fullNames);
-	view.setFocus();
+	var text = _this.getSelectedNames(fullNames, extended).join(', ');
+	//view.setFocus();
 	var scimoz = view.scimoz;
-	scimoz.insertText(scimoz.currentPos, namesArr.join(', '));
+	var length = scimoz.length;
+
+	if (scimoz.getWCharAt(scimoz.selectionStart - 1).search(/^[\w\.\u0100-\uFFFF"'`,\.;:=]$/) != -1)
+		text = " " + text;
+	if (scimoz.getWCharAt(scimoz.selectionEnd).search(/^[\w\.\u0100-\uFFFF"'`]$/) != -1)
+		text += " ";
+
+	scimoz.insertText(scimoz.currentPos, text);
+	scimoz.currentPos += scimoz.length - length;
+	scimoz.charRight();
 }
 
 
@@ -1324,119 +1309,97 @@
 }
 
 
-
-
 this.selectedItemsOrd = [];
-/*
-this.getClickedRow(event) {
-	var row = {}, column = {}, part = {};
 
-	var boxobject = _this.treeBox;
-	boxobject.QueryInterface(Components.interfaces.nsITreeBoxObject);
-	boxobject.getCellAt(event.clientX, event.clientY, row, column, part);
-
-	//if (typeof column.value != "string") column.value = column.value.id;
-	return row.value;
-	//document.getElementById("row").value = row.value;
-	//document.getElementById("column").value = column.value;
-	//document.getElementById("part").value = part.value;
-}
-*/
-
-//rObjectsTree
-
 this.onEvent = function(event) {
-	var selectedRows = _this.getSelectedRows();
-	var selectedItems = [];
-	for (var i = 0; i < selectedRows.length; i++)
-		selectedItems.push(_this.visibleData[selectedRows[i]].origItem);
-	var curRowIdx = selectedRows.indexOf(_this.selection.currentIndex);
+	switch (event.type) {
+		case "select":
+			var selectedRows = _this.getSelectedRows();
+			var selectedItems = [];
+			for (var i = 0; i < selectedRows.length; i++)
+				selectedItems.push(_this.visibleData[selectedRows[i]].origItem);
+			var curRowIdx = selectedRows.indexOf(_this.selection.currentIndex);
 
-	// this maintains array of selected items in order they were added to selection
-	var prevItems = _this.selectedItemsOrd;
-	var newItems = [];
-	for (var i = 0; i < prevItems.length; i++) {
-		var j = selectedItems.indexOf(prevItems[i]);
-		if (j != -1) // present in Prev, but not in Cur
-			newItems.push(prevItems[i])
-	}
-	for (var i = 0; i < selectedItems.length; i++) {
-		if (prevItems.indexOf(selectedItems[i]) == -1) { // present in Cur, but not in Prev
-			newItems.push(selectedItems[i]);
-		}
-	}
-	_this.selectedItemsOrd = newItems;
-
-	//sv.debugMsg(event.type)
-	//sv.debugMsg("keyCode: " + event.keyCode + "; charCode: " + event.charCode +
-					 //"; which: " + event.which + "; .ctrlKey: " + event.ctrlKey);
-
-	if (event.type == "keyup" || event.type == "keypress") {
-		var keyCode = event.keyCode;
-		if (typeof(keyCode) == "undefined")
-			keyCode = 0;
-
-		switch (keyCode) {
-			//case 38: // up
-			//case 40: // down
-			//	if (event.shiftKey) {
-			//		sv.debugMsg("Select: " + _this.visibleData[_this.selection.currentIndex].origItem.name);
-			//	}
-			//	return;
-			case 46: // Delete key
-				_this.removeSelected(event.shiftKey);
-				event.originalTarget.focus();
-				return;
-			case 45: //insert
-				sv.debugMsg("Insert");
-				break;
-			case 65: // Ctrt + A
-				if (event.ctrlKey){
-					_this.selection.selectAll();
+			// this maintains array of selected items in order they were added to selection
+			var prevItems = _this.selectedItemsOrd;
+			var newItems = [];
+			for (var i = 0; i < prevItems.length; i++) {
+				var j = selectedItems.indexOf(prevItems[i]);
+				if (j != -1) // present in Prev, but not in Cur
+					newItems.push(prevItems[i])
+			}
+			for (var i = 0; i < selectedItems.length; i++) {
+				if (prevItems.indexOf(selectedItems[i]) == -1) { // present in Cur, but not in Prev
+					newItems.push(selectedItems[i]);
 				}
-			case 0:
-				return;
-			case 93:
-				//windows context menu key
-				var contextMenu =  document.getElementById("rObjectsContext");
-				//event.initMouseEvent()
+			}
+			_this.selectedItemsOrd = newItems;
+			return;
+		case "keyup":
+		case "keypress":
+			var key = event.keyCode? event.keyCode : event.charCode;
+			switch (key) {
+				//case 38: // up
+				//case 40: // down
+				//	if (event.shiftKey) {
+				//		sv.debugMsg("Select: " + _this.visibleData[_this.selection.currentIndex].origItem.name);
+				//	}
+				//	return;
+				case 46: // Delete key
+					_this.removeSelected(event.shiftKey);
+					event.originalTarget.focus();
+					return;
+				case 45: //insert
+				case 32: //space
+					sv.debugMsg("Insert");
+					break;
+				case 65: // Ctrt + A
+					if (event.ctrlKey){
+						_this.selection.selectAll();
+					}
+				case 0:
+					return;
+				case 93:
+					//windows context menu key
+					var contextMenu = document.getElementById("rObjectsContext");
+					_this.treeBox.ensureRowIsVisible(_this.selection.currentIndex);
+					var y = ((2 + _this.selection.currentIndex - _this.treeBox.getFirstVisibleRow())
+						* _this.treeBox.rowHeight)	+ _this.treeBox.y;
+					var x = _this.treeBox.x;
+					contextMenu.openPopup(null, "after_pointer", x, y, true);
 
-				_this.treeBox.ensureRowIsVisible(_this.selection.currentIndex);
-
-				var y = ((2 + _this.selection.currentIndex - _this.treeBox.getFirstVisibleRow())
-					* _this.treeBox.rowHeight)	+ _this.treeBox.y;
-				var x = _this.treeBox.x;
-
-				contextMenu.openPopup(null, "after_pointer", x, y, true);
-
-			// TODO: Escape key stops retrieval of r objects
-			default:
-				//sv.debugMsg(String.fromCharCode(event.charCode));
-				//sv.debugMsg("keyCode: " + keyCode);
+				// TODO: Escape key stops retrieval of r objects
+				default:
+					return;
+			}
+			break;
+		case "dblclick":
+			if (event.button != 0)	return;
+			if (_this.selection && (_this.selection.currentIndex == -1
+				|| _this.isContainer(_this.selection.currentIndex)))
 				return;
-		}
-
-	} else if (event.type == "dblclick") {
-		if (event.button != 0)
+			break;
+		case "click":
+		case "draggesture":
 			return;
-
-		if (_this.selection && (_this.selection.currentIndex == -1
-			|| _this.isContainer(_this.selection.currentIndex)))
-			return;
-	} else if (event.type == "click") {
-		return;
+		default:
 	}
-
+	sv.debugMsg("event.type = " + event.type);
 	// default action: insert selected names:
-	_this.insertName(event.ctrlKey);
+	_this.insertName(event.ctrlKey, event.shiftKey);
+
+	// this does not have any effect:
+	//document.getElementById("sciviews_robjects_objects_tree").focus();
 	event.originalTarget.focus();
 }
+//fsplitbodymass.mosdyday
 
+
 // drag & drop handling for search paths list
 this.packageListObserver = {
 	onDrop : function (event, transferData, session) {
 		var data = transferData;
-		alert(transferData.flavour.contentType);
+		sv.debugMsg("dropped object was " + transferData.flavour.contentType);
 		var path;
 		if (transferData.flavour.contentType == "application/x-moz-file") {
 			path = transferData.data.path;
@@ -1455,8 +1418,8 @@
 	},
 
 	onDragOver : function(event, flavour, session) {
-		sv.cmdout.append(flavour.contentType);
-		session.canDrop = flavour.contentType == 'text/unicode'	|| flavour.contentType == 'application/x-moz-file';
+		session.canDrop = flavour.contentType == 'text/unicode'
+						   || flavour.contentType == 'application/x-moz-file';
 	},
 
 	getSupportedFlavours : function () {
@@ -1499,24 +1462,3 @@
 
 } ).apply(rObjectsTree);
 
-//ondragover="nsDragAndDrop.dragOver(event,rObjectsTree.packageListObserver);"
-//ondragenter="nsDragAndDrop.dragEnter(event,rObjectsTree.packageListObserver);"
-
-
-/*
-how to get the clicked cell in treeBox:
-
-  var row = {}, column = {}, part = {};
-  var tree = document.getElementById("thetree");
-
-  var boxobject = tree.boxObject;
-  boxobject.QueryInterface(Components.interfaces.nsITreeBoxObject);
-  boxobject.getCellAt(event.clientX, event.clientY, row, column, part);
-
-  if (typeof column.value != "string") column.value = column.value.id;
-
-  document.getElementById("row").value = row.value;
-  document.getElementById("column").value = column.value;
-  document.getElementById("part").value = part.value;
-
-*/

Modified: komodo/SciViews-K/content/js/sciviews.js
===================================================================
--- komodo/SciViews-K/content/js/sciviews.js	2009-05-20 14:00:03 UTC (rev 132)
+++ komodo/SciViews-K/content/js/sciviews.js	2009-05-21 17:55:53 UTC (rev 133)
@@ -30,7 +30,7 @@
 // sv.prefs.askString(pref, defvalue): // Ask for the value of a preference
 //
 // OpenKore Command Output management ('sv.cmdout' namespace)
-// sv.cmdout.append(str, newline); // Append text to the Command Output pane
+// sv.cmdout.append(str, newline, scrollToStart); // Append text to the Command Output pane
 // sv.cmdout.clear(); // Clear the Command Output pane
 // sv.cmdout.message(msg, timeout); // // Display message on the Command Output pane's bar
 
@@ -561,7 +561,7 @@
 if (typeof(sv.cmdout) == 'undefined') sv.cmdout = {};
 
 // Append text to the Command Output pane
-sv.cmdout.append = function(str, newline) {
+sv.cmdout.append = function(str, newline, scrollToStart) {
 	try {
 		var runout = ko.run.output;
 		// Make sure the command output window is visible
@@ -583,8 +583,13 @@
 			scimoz.readOnly = false;
 			scimoz.appendText(str_byte_length, str);
 		} finally { scimoz.readOnly = ro; }
-		// Bring the new text into view
-		scimoz.gotoPos(prevLength + 1);
+
+		if (scrollToStart) {
+			// Bring the new text into view
+			scimoz.gotoPos(prevLength + 1);
+		} else {
+			scimoz.gotoLine(scimoz.lineCount);
+		}
 	} catch(e) { alert("Problems printing [" + str + "]:" + e + "\n"); }
 };
 
@@ -614,18 +619,12 @@
 sv.cmdout.message = function(msg, timeout) {
 	document.getElementById('output_tabpanels').selectedIndex = 0;
 	var runoutputDesc = document.getElementById('runoutput-desc');
-	if (msg == null)
-		msg = "";
-
+	if (msg == null) msg = "";
 	runoutputDesc.style.color = "rgb(0, 0, 0)";
-
 	runoutputDesc.setAttribute("value", msg);
-
 	window.clearTimeout(runoutputDesc.timeout);
-
-	if (timeout > 0) {
-		runoutputDesc.timeout = window.setTimeout("sv.cmdout.message()", timeout);
-	}
+	if (timeout > 0)
+		runoutputDesc.timeout = window.setTimeout("sv.cmdout.message();", timeout);
 }
 
 sv.checkToolbox = function() {

Added: komodo/SciViews-K/sciviewsk-0.7.4-beta-ko.xpi
===================================================================
(Binary files differ)


Property changes on: komodo/SciViews-K/sciviewsk-0.7.4-beta-ko.xpi
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream



More information about the Sciviews-commits mailing list