Fix reselection of trash after restart

This commit is contained in:
Dan Stillman 2015-05-24 22:04:40 -04:00
parent dd52206b37
commit 6933f64616
2 changed files with 19 additions and 16 deletions

View File

@ -848,8 +848,8 @@ Zotero.CollectionTreeView.prototype.selectByID = Zotero.Promise.coroutine(functi
switch (type) { switch (type) {
case 'L': case 'L':
yield this.selectLibrary(id); var found = yield this.selectLibrary(id);
return true; break;
case 'C': case 'C':
var found = yield this.expandToCollection(id); var found = yield this.expandToCollection(id);
@ -859,6 +859,10 @@ Zotero.CollectionTreeView.prototype.selectByID = Zotero.Promise.coroutine(functi
var search = yield Zotero.Searches.getAsync(id); var search = yield Zotero.Searches.getAsync(id);
var found = yield this.expandLibrary(search.libraryID); var found = yield this.expandLibrary(search.libraryID);
break; break;
case 'T':
var found = yield this.selectTrash(id);
break;
} }
if (!found) { if (!found) {
@ -927,29 +931,18 @@ Zotero.CollectionTreeView.prototype.selectTrash = Zotero.Promise.coroutine(funct
// Check if trash is already selected // Check if trash is already selected
if (this.selection.currentIndex != -1) { if (this.selection.currentIndex != -1) {
let itemGroup = this._getItemAtRow(this.selection.currentIndex); let itemGroup = this.getRow(this.selection.currentIndex);
if (itemGroup.isTrash() && itemGroup.ref.libraryID == libraryID) { if (itemGroup.isTrash() && itemGroup.ref.libraryID == libraryID) {
this._treebox.ensureRowIsVisible(this.selection.currentIndex); this._treebox.ensureRowIsVisible(this.selection.currentIndex);
return true; return true;
} }
} }
// If in My Library and it's collapsed, open it
if (!libraryID && !this.isContainerOpen(0)) {
yield this.toggleOpenState(0);
}
// Find library trash // Find library trash
for (let i = 0; i < this.rowCount; i++) { for (let i = 0; i < this.rowCount; i++) {
let itemGroup = this._getItemAtRow(i); let itemGroup = this.getRow(i);
// If group header is closed, open it
if (itemGroup.isHeader() && itemGroup.ref.id == 'group-libraries-header'
&& !this.isContainerOpen(i)) {
yield this.toggleOpenState(i);
continue;
}
// If library is closed, open it
if (itemGroup.isLibrary(true) && itemGroup.ref.libraryID == libraryID if (itemGroup.isLibrary(true) && itemGroup.ref.libraryID == libraryID
&& !this.isContainerOpen(i)) { && !this.isContainerOpen(i)) {
yield this.toggleOpenState(i); yield this.toggleOpenState(i);

View File

@ -56,6 +56,16 @@ describe("Zotero.CollectionTreeView", function() {
}) })
}) })
describe("#selectByID", function () {
it("should select the trash", function* () {
yield collectionsView.selectByID("T1");
var row = collectionsView.selection.currentIndex;
var treeRow = collectionsView.getRow(row);
assert.ok(treeRow.isTrash());
assert.equal(treeRow.ref.libraryID, Zotero.Libraries.userLibraryID);
})
})
describe("#notify()", function () { describe("#notify()", function () {
it("should select a new collection", function* () { it("should select a new collection", function* () {
// Create collection // Create collection