From 5e774efc42fae1bef2f432c5cfcf24802442606c Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 29 Jan 2009 01:14:46 +0000 Subject: [PATCH] Addresses #513, Deleted Items folder Adds handling for parent/child items in trash -- non-deleted context items will appear in gray, and "Restore to Library" and the delete keystrokes won't be available if any of those are selected Like other search views, Select All will select only the deleted items --- chrome/content/zotero/overlay.js | 48 +++++++++-- .../zotero/xpcom/collectionTreeView.js | 3 +- chrome/content/zotero/xpcom/data/item.js | 85 ++++++++++++++----- chrome/content/zotero/xpcom/data/items.js | 6 +- chrome/content/zotero/xpcom/itemTreeView.js | 27 +++--- 5 files changed, 126 insertions(+), 43 deletions(-) diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 5b226b8fe..0348f10fb 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -819,6 +819,7 @@ var ZoteroPane = new function() } } + function itemSelected() { if (!Zotero.stateCheck()) { @@ -829,7 +830,8 @@ var ZoteroPane = new function() // Display restore button if items selected in Trash if (this.itemsView && this.itemsView.selection.count) { document.getElementById('zotero-item-restore-button').hidden - = !this.itemsView._itemGroup.isTrash(); + = !this.itemsView._itemGroup.isTrash() + || _nonDeletedItemsSelected(this.itemsView); } var tabs = document.getElementById('zotero-view-tabs'); @@ -913,7 +915,27 @@ var ZoteroPane = new function() label.value = Zotero.getString('pane.item.selected.zero'); } } - + } + + + /** + * Check if any selected items in the passed (trash) treeview are not deleted + * + * @param {nsITreeView} + * @return {Boolean} + */ + function _nonDeletedItemsSelected(itemsView) { + var start = {}; + var end = {}; + for (var i=0, len=itemsView.selection.getRangeCount(); i 0) { val = c; @@ -668,7 +668,9 @@ Zotero.ItemTreeView.prototype.isContainerEmpty = function(row) if(this._sourcesOnly) { return true; } else { - return (this._getItemAtRow(row).numNotes() == 0 && this._getItemAtRow(row).numAttachments() == 0); + var includeTrashed = this._itemGroup.isTrash(); + return (this._getItemAtRow(row).numNotes(includeTrashed) == 0 + && this._getItemAtRow(row).numAttachments(includeTrashed) == 0); } } @@ -727,8 +729,9 @@ Zotero.ItemTreeView.prototype.toggleOpenState = function(row, skipItemMapRefresh else { var item = this._getItemAtRow(row).ref; //Get children - var attachments = item.getAttachments(); - var notes = item.getNotes(); + var includeTrashed = this._itemGroup.isTrash(); + var attachments = item.getAttachments(includeTrashed); + var notes = item.getNotes(includeTrashed); var newRows; if(attachments && notes) @@ -891,6 +894,8 @@ Zotero.ItemTreeView.prototype.sort = function(itemID) return field; } + var includeTrashed = this._itemGroup.isTrash(); + function rowSort(a,b) { var cmp, fieldA, fieldB; @@ -915,7 +920,7 @@ Zotero.ItemTreeView.prototype.sort = function(itemID) break; case 'numChildren': - cmp = b.numChildren() - a.numChildren(); + cmp = b.numChildren(includeTrashed) - a.numChildren(includeTrashed); if (cmp) { return cmp; } @@ -2273,26 +2278,26 @@ Zotero.ItemTreeView.TreeRow.prototype.getField = function(field, unformatted) return this.ref.getField(field, unformatted, true); } -Zotero.ItemTreeView.TreeRow.prototype.numChildren = function() +Zotero.ItemTreeView.TreeRow.prototype.numChildren = function(includeTrashed) { if(this.ref.isRegularItem()) - return this.ref.numChildren(); + return this.ref.numChildren(includeTrashed); else return 0; } -Zotero.ItemTreeView.TreeRow.prototype.numNotes = function() +Zotero.ItemTreeView.TreeRow.prototype.numNotes = function(includeTrashed) { if(this.ref.isRegularItem()) - return this.ref.numNotes(); + return this.ref.numNotes(includeTrashed); else return 0; } -Zotero.ItemTreeView.TreeRow.prototype.numAttachments = function() +Zotero.ItemTreeView.TreeRow.prototype.numAttachments = function(includeTrashed) { if(this.ref.isRegularItem()) - return this.ref.numAttachments(); + return this.ref.numAttachments(includeTrashed); else return 0; } \ No newline at end of file