From bdcad86da51a6d79ff670eca2f0295bff75446f6 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 18 Feb 2007 11:59:31 +0000 Subject: [PATCH] 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 --- chrome/content/zotero/advancedSearch.js | 17 ----- chrome/content/zotero/advancedSearch.xul | 1 - chrome/content/zotero/overlay.js | 20 ------ .../zotero/xpcom/collectionTreeView.js | 45 +++++++++---- chrome/content/zotero/xpcom/itemTreeView.js | 64 ++++++++++++------- 5 files changed, 75 insertions(+), 72 deletions(-) diff --git a/chrome/content/zotero/advancedSearch.js b/chrome/content/zotero/advancedSearch.js index 1cb094ace8..58e6ccb692 100644 --- a/chrome/content/zotero/advancedSearch.js +++ b/chrome/content/zotero/advancedSearch.js @@ -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) { diff --git a/chrome/content/zotero/advancedSearch.xul b/chrome/content/zotero/advancedSearch.xul index cb38b091d0..8371a3c18d 100644 --- a/chrome/content/zotero/advancedSearch.xul +++ b/chrome/content/zotero/advancedSearch.xul @@ -37,7 +37,6 @@ diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index d438186a87..5d00bb7c44 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -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; - } } } diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 8cdab3f0c0..d8ebcc7425 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -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