diff --git a/chrome/content/zotero/integration/addCitationDialog.js b/chrome/content/zotero/integration/addCitationDialog.js index 6af23b2bb..c7ab2e2d6 100644 --- a/chrome/content/zotero/integration/addCitationDialog.js +++ b/chrome/content/zotero/integration/addCitationDialog.js @@ -123,7 +123,14 @@ var Zotero_Citation_Dialog = new function () { // single citation toggleMultipleSources(false); _suppressNextTreeSelect = true; - itemsView.selectItem(io.citation.citationItems[0].id); // treeview from xpcom/itemTreeView.js + + // switch to library if item doesn't exist in current selection + if(!collectionsView.getSelectedCollection().hasItem(io.citation.citationItems[0].id)) { + var item = Zotero.Items.get(io.citation.citationItems[0].id); + collectionsView.selectLibrary(item.libraryID); + } + itemsView.selectItem(io.citation.citationItems[0].id); + for(var box in _preserveData) { var property = _preserveData[box][0]; if(io.citation.citationItems[0][box]) { diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index f2094846c..6a72d1812 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -1672,14 +1672,8 @@ var ZoteroPane = new function() function getSelectedCollection(asID) { - if (this.collectionsView - && this.collectionsView.selection - && this.collectionsView.selection.count > 0 - && this.collectionsView.selection.currentIndex != -1) { - var collection = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex); - if (collection && collection.isCollection()) { - return asID ? collection.ref.id : collection.ref; - } + if (this.collectionsView) { + return this.collectionsView.getSelectedCollection(asID); } return false; } diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 38567a09d..1ca88dda6 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -946,6 +946,19 @@ Zotero.CollectionTreeView.prototype.rememberSelection = function(selection) break; } } + + +Zotero.CollectionTreeView.prototype.getSelectedCollection = function(asID) { + if (this.selection + && this.selection.count > 0 + && this.selection.currentIndex != -1) { + var collection = this._getItemAtRow(this.selection.currentIndex); + if (collection && collection.isCollection()) { + return asID ? collection.ref.id : collection.ref; + } + } + return false; +}