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);
_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];

View file

@ -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()

View file

@ -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;

View file

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