diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index e5f78a328..6deb7331f 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -372,6 +372,7 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function* if (action == 'delete') { 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 let rows = []; @@ -399,6 +400,10 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function* row++; } while (row < this.rowCount && this.getLevel(row) > level); + + if (type == 'feed') { + refreshFeeds = true; + } break; } } @@ -411,6 +416,18 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function* 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(); } @@ -1186,26 +1203,15 @@ Zotero.CollectionTreeView.prototype.deleteSelection = Zotero.Promise.coroutine(f yield treeRow.ref.eraseTx({ deleteItems: true }); - } - if (treeRow.isCollection() || treeRow.isFeed()) { - yield treeRow.ref.erase(deleteItems); + if (treeRow.isFeed()) { + refreshFeeds = true; + } } else if (treeRow.isSearch()) { yield Zotero.Searches.erase(treeRow.ref.id); } } //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); - } }); diff --git a/chrome/content/zotero/xpcom/data/feed.js b/chrome/content/zotero/xpcom/data/feed.js index 72c642f07..2b9588bec 100644 --- a/chrome/content/zotero/xpcom/data/feed.js +++ b/chrome/content/zotero/xpcom/data/feed.js @@ -61,8 +61,8 @@ Zotero.Feed = function(params = {}) { // Return a proxy so that we can disable the object once it's deleted return new Proxy(this, { get: function(obj, prop) { - if (obj._disabled && !(prop == 'libraryID' || prop == 'id')) { - throw new Error("Feed (" + obj.libraryID + ") has been disabled"); + if (obj._disabled && !(prop == 'libraryID' || prop == 'id' || prop == 'treeViewID')) { + throw new Error("Feed " + obj.libraryID + " has been disabled"); } return obj[prop]; } diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index e4b2c3276..19c383278 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -1905,7 +1905,7 @@ var ZoteroPane = new function() "", "", "", {} ); if (index == 0) { - this.collectionsView.deleteSelection(deleteItems); + return this.collectionsView.deleteSelection(deleteItems); } } } diff --git a/test/tests/collectionTreeViewTest.js b/test/tests/collectionTreeViewTest.js index a955d560a..eae61b325 100644 --- a/test/tests/collectionTreeViewTest.js +++ b/test/tests/collectionTreeViewTest.js @@ -383,6 +383,15 @@ describe("Zotero.CollectionTreeView", function() { 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 () {