From be166665e71c132a670c8195aab7128bffb5bd1d Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 9 Mar 2011 23:00:09 +0000 Subject: [PATCH] Fix cross-library item reselection in Edit Citation --- .../zotero/integration/addCitationDialog.js | 17 ++++++++++++----- chrome/content/zotero/selectItemsDialog.js | 1 - .../content/zotero/xpcom/collectionTreeView.js | 6 +++--- chrome/content/zotero/xpcom/itemTreeView.js | 6 ++++-- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/chrome/content/zotero/integration/addCitationDialog.js b/chrome/content/zotero/integration/addCitationDialog.js index a61840811..d241355bd 100644 --- a/chrome/content/zotero/integration/addCitationDialog.js +++ b/chrome/content/zotero/integration/addCitationDialog.js @@ -124,13 +124,20 @@ var Zotero_Citation_Dialog = new function () { toggleMultipleSources(false); _suppressNextTreeSelect = true; - // switch to library if item doesn't exist in current selection - var collection = collectionsView.getSelectedCollection(); - if(collection && !collection.hasItem(io.citation.citationItems[0].id)) { - var item = Zotero.Items.get(io.citation.citationItems[0].id); + // If we're in a different library, switch libraries + var id = io.citation.citationItems[0].id; + var itemGroup = collectionsView._getItemAtRow(collectionsView.selection.currentIndex); + var item = Zotero.Items.get(id); + if(item.libraryID != itemGroup.ref.libraryID) { collectionsView.selectLibrary(item.libraryID); } - itemsView.wrappedJSObject.selectItem(io.citation.citationItems[0].id); + var selected = itemsView.selectItem(id); + if(!selected) { + // If item wasn't found in current view, select library root + // and try again (in case we were in a collection of correct library) + collectionsView.selectLibrary(item.libraryID); + itemsView.selectItem(id); + } for(var box in _preserveData) { var property = _preserveData[box][0]; diff --git a/chrome/content/zotero/selectItemsDialog.js b/chrome/content/zotero/selectItemsDialog.js index febbdfdd8..d75c54ae9 100644 --- a/chrome/content/zotero/selectItemsDialog.js +++ b/chrome/content/zotero/selectItemsDialog.js @@ -47,7 +47,6 @@ function doLoad() // Don't show Commons when citing collectionsView.showCommons = false; document.getElementById('zotero-collections-tree').view = collectionsView; - if(io.select) itemsView.selectItem(io.select); } function doUnload() diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index cad467380..a71ce8587 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -736,13 +736,13 @@ Zotero.CollectionTreeView.prototype.selectLibrary = function (libraryID) { // Already selected var itemGroup = this._getItemAtRow(this.selection.currentIndex); - if (itemGroup.ref.libraryID == libraryID) { + if (itemGroup.isLibrary(true) && itemGroup.ref.libraryID == libraryID) { return true; } // Find library - for (var i=0, rows=this.rowCount; i