diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 0391a894fc..da09a8d9e3 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -287,20 +287,30 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function* return; } - if (action == 'refresh' && type == 'trash') { - // libraryID is passed as parameter to 'refresh' - let deleted = yield Zotero.Items.getDeleted(ids[0], true); - this._trashNotEmpty[ids[0]] = !!deleted.length; - return; - } - + // + // Actions that don't change the selection + // if (action == 'redraw') { this._treebox.invalidate(); return; } + if (action == 'refresh') { + // If trash is refreshed, we probably need to update the icon from full to empty + if (type == 'trash') { + // libraryID is passed as parameter to 'refresh' + let deleted = yield Zotero.Items.getDeleted(ids[0], true); + this._trashNotEmpty[ids[0]] = !!deleted.length; + let row = this.getRowIndexByID("T" + ids[0]); + this._treebox.invalidateRow(row); + } + return; + } + // + // Actions that can change the selection + // + var currentTreeRow = this.getRow(this.selection.currentIndex); this.selection.selectEventsSuppressed = true; - var savedSelection = this.saveSelection(); if (action == 'delete') { var selectedIndex = this.selection.count ? this.selection.currentIndex : 0; @@ -356,25 +366,45 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function* else if(action == 'move') { yield this.reload(); - - // Open the new parent collection if closed - for (var i=0; i level) { beforeRow = ++i; - if (i == this.rowCount) { - break; + if (i == this.rowCount || !this.getRow(i).isCollection()) { + break loop; } treeRow = this.getRow(i); rowLevel = this.getLevel(i); @@ -533,7 +564,7 @@ Zotero.CollectionTreeView.prototype._addSortedRow = Zotero.Promise.coroutine(fun beforeRow ); } - return true; + return beforeRow; }); @@ -763,7 +794,7 @@ Zotero.CollectionTreeView.prototype.setCellText = function (row, col, val) { } var treeRow = this.getRow(row); treeRow.ref.name = val; - treeRow.ref.save(); + treeRow.ref.saveTx(); } @@ -877,6 +908,13 @@ Zotero.CollectionTreeView.prototype.selectByID = Zotero.Promise.coroutine(functi }); +Zotero.CollectionTreeView.prototype.restoreSelection = Zotero.Promise.coroutine(function* (collectionTreeRow) { + yield this.selectByID(collectionTreeRow.id); + // Swap back in the previous tree row to avoid reselection and subsequent items view refresh + this._rows[this.selection.currentIndex] = collectionTreeRow; +}) + + /** * @param {Integer} libraryID Library to select */ @@ -1172,37 +1210,6 @@ Zotero.CollectionTreeView.prototype.getSelectedCollection = function(asID) { } -/* - * Saves the ids of the currently selected item for later - */ -Zotero.CollectionTreeView.prototype.saveSelection = function() -{ - for (var i=0, len=this.rowCount; i