commit be166665e71c132a670c8195aab7128bffb5bd1d
parent d405f2675cb76a5be0acca59dfce7f29bcbea096
Author: Dan Stillman <dstillman@zotero.org>
Date: Wed, 9 Mar 2011 23:00:09 +0000
Fix cross-library item reselection in Edit Citation
Diffstat:
4 files changed, 19 insertions(+), 11 deletions(-)
diff --git 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
@@ -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
@@ -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<rows.length; i++) {
- var itemGroup = this._getItemAtRow(this.selection.currentIndex);
+ for (var i=0, rows=this.rowCount; i<rows; i++) {
+ var itemGroup = this._getItemAtRow(i);
if (itemGroup.ref && itemGroup.ref.libraryID == libraryID) {
this.selection.select(i);
return true;
diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js
@@ -1296,8 +1296,10 @@ Zotero.ItemTreeView.prototype.selectItem = function(id, expand, noRecurse)
// Clear the quicksearch and tag selection and try again (once)
if (!noRecurse) {
- this._ownerDocument.defaultView.ZoteroPane.clearQuicksearch();
- this._ownerDocument.defaultView.ZoteroPane.clearTagSelection();
+ if (this._ownerDocument.defaultView.ZoteroPane) {
+ this._ownerDocument.defaultView.ZoteroPane.clearQuicksearch();
+ this._ownerDocument.defaultView.ZoteroPane.clearTagSelection();
+ }
return this.selectItem(id, expand, true);
}