Fix #1054, UI breakage after unsubscribing from feed

This commit is contained in:
Dan Stillman 2016-06-28 14:29:15 -04:00
parent 9e6565fe00
commit 622530e889
4 changed files with 32 additions and 17 deletions

View file

@ -372,6 +372,7 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function*
if (action == 'delete') { if (action == 'delete') {
var selectedIndex = this.selection.count ? this.selection.currentIndex : 0; var selectedIndex = this.selection.count ? this.selection.currentIndex : 0;
let refreshFeeds = false;
// Since a delete involves shifting of rows, we have to do it in reverse order // Since a delete involves shifting of rows, we have to do it in reverse order
let rows = []; let rows = [];
@ -399,6 +400,10 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function*
row++; row++;
} }
while (row < this.rowCount && this.getLevel(row) > level); while (row < this.rowCount && this.getLevel(row) > level);
if (type == 'feed') {
refreshFeeds = true;
}
break; break;
} }
} }
@ -411,6 +416,18 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function*
this._removeRow(row); this._removeRow(row);
} }
// If a feed was removed and there are no more, remove Feeds header
if (refreshFeeds && !Zotero.Feeds.haveFeeds()) {
for (let i = 0; i < this._rows.length; i++) {
let row = this._rows[i];
if (row.ref.id == 'feed-libraries-header') {
this._removeRow(i);
this._removeRow(i - 1);
break;
}
}
}
this._refreshRowMap(); this._refreshRowMap();
} }
@ -1186,26 +1203,15 @@ Zotero.CollectionTreeView.prototype.deleteSelection = Zotero.Promise.coroutine(f
yield treeRow.ref.eraseTx({ yield treeRow.ref.eraseTx({
deleteItems: true deleteItems: true
}); });
if (treeRow.isFeed()) {
refreshFeeds = true;
} }
if (treeRow.isCollection() || treeRow.isFeed()) {
yield treeRow.ref.erase(deleteItems);
} }
else if (treeRow.isSearch()) { else if (treeRow.isSearch()) {
yield Zotero.Searches.erase(treeRow.ref.id); yield Zotero.Searches.erase(treeRow.ref.id);
} }
} }
//this._treebox.endUpdateBatch(); //this._treebox.endUpdateBatch();
if (end.value < this.rowCount) {
var row = this.getRow(end.value);
if (row.isSeparator()) {
return;
}
this.selection.select(end.value);
}
else {
this.selection.select(this.rowCount-1);
}
}); });

View file

@ -61,8 +61,8 @@ Zotero.Feed = function(params = {}) {
// Return a proxy so that we can disable the object once it's deleted // Return a proxy so that we can disable the object once it's deleted
return new Proxy(this, { return new Proxy(this, {
get: function(obj, prop) { get: function(obj, prop) {
if (obj._disabled && !(prop == 'libraryID' || prop == 'id')) { if (obj._disabled && !(prop == 'libraryID' || prop == 'id' || prop == 'treeViewID')) {
throw new Error("Feed (" + obj.libraryID + ") has been disabled"); throw new Error("Feed " + obj.libraryID + " has been disabled");
} }
return obj[prop]; return obj[prop];
} }

View file

@ -1905,7 +1905,7 @@ var ZoteroPane = new function()
"", "", "", {} "", "", "", {}
); );
if (index == 0) { if (index == 0) {
this.collectionsView.deleteSelection(deleteItems); return this.collectionsView.deleteSelection(deleteItems);
} }
} }
} }

View file

@ -383,6 +383,15 @@ describe("Zotero.CollectionTreeView", function() {
assert.equal(cv.getSelectedLibraryID(), feed.id); assert.equal(cv.getSelectedLibraryID(), feed.id);
}) })
it("should remove deleted feed", function* () {
var feed = yield createFeed();
yield cv.selectLibrary(feed.libraryID);
waitForDialog();
var id = feed.treeViewID;
yield win.ZoteroPane.deleteSelectedCollection();
assert.isFalse(cv.getRowIndexByID(id))
})
}) })
describe("#drop()", function () { describe("#drop()", function () {