Fix cross-library item reselection in Edit Citation

This commit is contained in:
Dan Stillman 2011-03-09 23:00:09 +00:00
parent d405f2675c
commit be166665e7
4 changed files with 19 additions and 11 deletions

View File

@ -124,13 +124,20 @@ var Zotero_Citation_Dialog = new function () {
toggleMultipleSources(false); toggleMultipleSources(false);
_suppressNextTreeSelect = true; _suppressNextTreeSelect = true;
// switch to library if item doesn't exist in current selection // If we're in a different library, switch libraries
var collection = collectionsView.getSelectedCollection(); var id = io.citation.citationItems[0].id;
if(collection && !collection.hasItem(io.citation.citationItems[0].id)) { var itemGroup = collectionsView._getItemAtRow(collectionsView.selection.currentIndex);
var item = Zotero.Items.get(io.citation.citationItems[0].id); var item = Zotero.Items.get(id);
if(item.libraryID != itemGroup.ref.libraryID) {
collectionsView.selectLibrary(item.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) { for(var box in _preserveData) {
var property = _preserveData[box][0]; var property = _preserveData[box][0];

View File

@ -47,7 +47,6 @@ function doLoad()
// Don't show Commons when citing // Don't show Commons when citing
collectionsView.showCommons = false; collectionsView.showCommons = false;
document.getElementById('zotero-collections-tree').view = collectionsView; document.getElementById('zotero-collections-tree').view = collectionsView;
if(io.select) itemsView.selectItem(io.select);
} }
function doUnload() function doUnload()

View File

@ -736,13 +736,13 @@ Zotero.CollectionTreeView.prototype.selectLibrary = function (libraryID) {
// Already selected // Already selected
var itemGroup = this._getItemAtRow(this.selection.currentIndex); var itemGroup = this._getItemAtRow(this.selection.currentIndex);
if (itemGroup.ref.libraryID == libraryID) { if (itemGroup.isLibrary(true) && itemGroup.ref.libraryID == libraryID) {
return true; return true;
} }
// Find library // Find library
for (var i=0, rows=this.rowCount; i<rows.length; i++) { for (var i=0, rows=this.rowCount; i<rows; i++) {
var itemGroup = this._getItemAtRow(this.selection.currentIndex); var itemGroup = this._getItemAtRow(i);
if (itemGroup.ref && itemGroup.ref.libraryID == libraryID) { if (itemGroup.ref && itemGroup.ref.libraryID == libraryID) {
this.selection.select(i); this.selection.select(i);
return true; return true;

View File

@ -1296,8 +1296,10 @@ Zotero.ItemTreeView.prototype.selectItem = function(id, expand, noRecurse)
// Clear the quicksearch and tag selection and try again (once) // Clear the quicksearch and tag selection and try again (once)
if (!noRecurse) { if (!noRecurse) {
this._ownerDocument.defaultView.ZoteroPane.clearQuicksearch(); if (this._ownerDocument.defaultView.ZoteroPane) {
this._ownerDocument.defaultView.ZoteroPane.clearTagSelection(); this._ownerDocument.defaultView.ZoteroPane.clearQuicksearch();
this._ownerDocument.defaultView.ZoteroPane.clearTagSelection();
}
return this.selectItem(id, expand, true); return this.selectItem(id, expand, true);
} }