Addresses #85, Button(s) to expand/collapse all notes in a view

Better idea: Add expand/collapse keypress listener in treeview setTree() so that it works automatically in all trees

More of the functionality in the overlay could probably be moved into the treeviews like this
This commit is contained in:
Dan Stillman 2007-02-18 11:59:31 +00:00
parent 5d638df73a
commit bdcad86da5
5 changed files with 75 additions and 72 deletions

View file

@ -3,7 +3,6 @@ var ZoteroAdvancedSearch = new function() {
this.search = search;
this.clear = clear;
this.save = save;
this.handleKeyPress = handleKeyPress;
this.onDblClick = onDblClick;
this.onUnload = onUnload;
@ -87,22 +86,6 @@ var ZoteroAdvancedSearch = new function() {
}
function handleKeyPress(event) {
var key = String.fromCharCode(event.which);
if (key == '+' && !(event.ctrlKey || event.altKey || event.metaKey)) {
this.itemsView.expandAllRows();
return;
}
else if (key == '-' && !(event.shiftKey || event.ctrlKey ||
event.altKey || event.metaKey)) {
this.itemsView.collapseAllRows();
return;
}
}
// Adapted from: http://www.xulplanet.com/references/elemref/ref_tree.html#cmnote-9
function onDblClick(event, tree)
{

View file

@ -37,7 +37,6 @@
</hbox>
<tree id="zotero-items-tree" flex="1" hidecolumnpicker="true" seltype="multiple"
onkeypress="ZoteroAdvancedSearch.handleKeyPress(event)"
ondblclick="ZoteroAdvancedSearch.onDblClick(event, this)"
ondraggesture="if (event.target.localName == 'treechildren') { nsDragAndDrop.startDrag(event, ZoteroAdvancedSearch.itemsView); }">
<treecols>

View file

@ -340,16 +340,6 @@ var ZoteroPane = new function()
event.preventDefault();
return;
}
if (key == '+' && !(event.ctrlKey || event.altKey || event.metaKey)) {
ZoteroPane.collectionsView.expandAllRows();
return;
}
else if (key == '-' && !(event.shiftKey || event.ctrlKey ||
event.altKey || event.metaKey)) {
ZoteroPane.collectionsView.collapseAllRows();
return;
}
}
else if (from == 'zotero-items-tree') {
if (event.keyCode == event.DOM_VK_BACK_SPACE ||
@ -358,16 +348,6 @@ var ZoteroPane = new function()
event.preventDefault();
return;
}
if (key == '+' && !(event.ctrlKey || event.altKey || event.metaKey)) {
ZoteroPane.itemsView.expandAllRows();
return;
}
else if (key == '-' && !(event.shiftKey || event.ctrlKey ||
event.altKey || event.metaKey)) {
ZoteroPane.itemsView.collapseAllRows();
return;
}
}
}

View file

@ -49,6 +49,25 @@ Zotero.CollectionTreeView.prototype.setTree = function(treebox)
if(this._treebox)
return;
this._treebox = treebox;
// Add a keypress listener for expand/collapse
var expandAllRows = this.expandAllRows;
var collapseAllRows = this.collapseAllRows;
var tree = this._treebox.treeBody.parentNode;
tree.addEventListener('keypress', function(event) {
var key = String.fromCharCode(event.which);
if (key == '+' && !(event.ctrlKey || event.altKey || event.metaKey)) {
expandAllRows(treebox);
return;
}
else if (key == '-' && !(event.shiftKey || event.ctrlKey ||
event.altKey || event.metaKey)) {
collapseAllRows(treebox);
return;
}
}, false);
//select Library
this.selection.select(0);
}
@ -361,25 +380,27 @@ Zotero.CollectionTreeView.prototype.toggleOpenState = function(row)
}
Zotero.CollectionTreeView.prototype.expandAllRows = function() {
this._treebox.beginUpdateBatch();
for (var i=0; i<this.rowCount; i++) {
if (this.isContainer(i) && !this.isContainerOpen(i)) {
this.toggleOpenState(i);
Zotero.CollectionTreeView.prototype.expandAllRows = function(treebox) {
var view = treebox.view;
treebox.beginUpdateBatch();
for (var i=0; i<view.rowCount; i++) {
if (view.isContainer(i) && !view.isContainerOpen(i)) {
view.toggleOpenState(i);
}
}
this._treebox.endUpdateBatch();
treebox.endUpdateBatch();
}
Zotero.CollectionTreeView.prototype.collapseAllRows = function() {
this._treebox.beginUpdateBatch();
for (var i=0; i<this.rowCount; i++) {
if (this.isContainer(i) && this.isContainerOpen(i)) {
this.toggleOpenState(i);
Zotero.CollectionTreeView.prototype.collapseAllRows = function(treebox) {
var view = treebox.view;
treebox.beginUpdateBatch();
for (var i=0; i<view.rowCount; i++) {
if (view.isContainer(i) && view.isContainerOpen(i)) {
view.toggleOpenState(i);
}
}
this._treebox.endUpdateBatch();
treebox.endUpdateBatch();
}

View file

@ -66,6 +66,24 @@ Zotero.ItemTreeView.prototype.setTree = function(treebox)
return;
this._treebox = treebox;
// Add a keypress listener for expand/collapse
var expandAllRows = this.expandAllRows;
var collapseAllRows = this.collapseAllRows;
var tree = this._treebox.treeBody.parentNode;
tree.addEventListener('keypress', function(event) {
var key = String.fromCharCode(event.which);
if (key == '+' && !(event.ctrlKey || event.altKey || event.metaKey)) {
expandAllRows(treebox);
return;
}
else if (key == '-' && !(event.shiftKey || event.ctrlKey ||
event.altKey || event.metaKey)) {
collapseAllRows(treebox);
return;
}
}, false);
this.sort();
//Zotero.debug('Running callbacks in itemTreeView.setTree()', 4);
@ -476,28 +494,6 @@ Zotero.ItemTreeView.prototype.toggleOpenState = function(row)
}
Zotero.ItemTreeView.prototype.expandAllRows = function() {
this._treebox.beginUpdateBatch();
for (var i=0; i<this.rowCount; i++) {
if (this.isContainer(i) && !this.isContainerOpen(i)) {
this.toggleOpenState(i);
}
}
this._treebox.endUpdateBatch();
}
Zotero.ItemTreeView.prototype.collapseAllRows = function() {
this._treebox.beginUpdateBatch();
for (var i=0; i<this.rowCount; i++) {
if (this.isContainer(i) && this.isContainerOpen(i)) {
this.toggleOpenState(i);
}
}
this._treebox.endUpdateBatch();
}
Zotero.ItemTreeView.prototype.isSorted = function()
{
// We sort by the first column if none selected, so return true
@ -928,6 +924,30 @@ Zotero.ItemTreeView.prototype.rememberFirstRow = function(firstRow) {
}
Zotero.ItemTreeView.prototype.expandAllRows = function(treebox) {
var view = treebox.view;
treebox.beginUpdateBatch();
for (var i=0; i<view.rowCount; i++) {
if (view.isContainer(i) && !view.isContainerOpen(i)) {
view.toggleOpenState(i);
}
}
treebox.endUpdateBatch();
}
Zotero.ItemTreeView.prototype.collapseAllRows = function(treebox) {
var view = treebox.view;
treebox.beginUpdateBatch();
for (var i=0; i<view.rowCount; i++) {
if (view.isContainer(i) && view.isContainerOpen(i)) {
view.toggleOpenState(i);
}
}
treebox.endUpdateBatch();
}
/*
* Returns an array of item ids of visible items in current sort order
*/