From 063ba1de5e6776c3c47f1f8210a84c0d09c41f01 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 13 Jan 2012 18:11:00 -0500 Subject: [PATCH] Undelete linked item automatically when redragging item to a library Unlike with Restore to Library, the linked item is first removed from any collections, so it only ends up in the library root and, if applicable, the target collection. --- chrome/content/zotero/xpcom/collectionTreeView.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index d817ae66c..c2bea0ead 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -1242,7 +1242,7 @@ Zotero.CollectionTreeView.prototype.canDrop = function(row, orient, dragData) } var linkedItem = item.getLinkedItem(itemGroup.ref.libraryID); - if (linkedItem) { + if (linkedItem && !linkedItem.deleted) { // For drag to root, skip if linked item exists if (itemGroup.isLibrary(true)) { continue; @@ -1373,6 +1373,18 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient) // Check if there's already a copy of this item in the library var linkedItem = item.getLinkedItem(targetLibraryID); if (linkedItem) { + // If linked item is in the trash, undelete it + if (linkedItem.deleted) { + // Remove from any existing collections, or else when it gets + // undeleted it would reappear in those collections + var collectionIDs = linkedItem.getCollections(); + for each(var collectionID in collectionIDs) { + var col = Zotero.Collections.get(collectionID); + col.removeItem(linkedItem.id); + } + linkedItem.deleted = false; + linkedItem.save(); + } return linkedItem.id; /*