From dba77cd3324705cef8e3347592130cf57bc47733 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 27 Aug 2021 16:48:17 -0400 Subject: [PATCH] Additional tab context menu tweaks (#2162) - Select last reopened tab instead of opening all in background - Rearrange Close/Close Other Tabs/Reopen Closed Tabs options - Use proper plural for Reopen Closed Tab[s] --- chrome/content/zotero/tabs.js | 54 +++++++++++++------- chrome/locale/en-US/zotero/zotero.properties | 2 +- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/chrome/content/zotero/tabs.js b/chrome/content/zotero/tabs.js index fb539f7759..26a239f6a4 100644 --- a/chrome/content/zotero/tabs.js +++ b/chrome/content/zotero/tabs.js @@ -234,7 +234,8 @@ var Zotero_Tabs = new function () { this.undoClose = function () { var historyEntry = this._history.pop(); if (historyEntry) { - for (var tab of historyEntry) { + let maxIndex = -1; + for (let tab of historyEntry) { if (Zotero.Items.exists(tab.data.itemID)) { Zotero.Reader.open(tab.data.itemID, null, @@ -243,8 +244,15 @@ var Zotero_Tabs = new function () { openInBackground: true } ); + if (tab.index > maxIndex) { + maxIndex = tab.index; + } } } + // Select last reopened tab + if (maxIndex > -1) { + this.jump(maxIndex); + } } }; @@ -383,25 +391,8 @@ var Zotero_Tabs = new function () { // Separator popup.appendChild(document.createElement('menuseparator')); } - // Undo close - menuitem = document.createElement('menuitem'); - menuitem.setAttribute('label', Zotero.getString('tabs.undoClose')); - menuitem.setAttribute('disabled', !this._history.length); - menuitem.addEventListener('command', () => { - this.undoClose(); - }); - popup.appendChild(menuitem); - if (!(this._tabs.length == 2 && id != 'zotero-pane')) { - // Close other tabs - menuitem = document.createElement('menuitem'); - menuitem.setAttribute('label', Zotero.getString('tabs.closeOther')); - menuitem.addEventListener('command', () => { - this.close(this._tabs.slice(1).filter(x => x.id != id).map(x => x.id)); - }); - popup.appendChild(menuitem); - } + // Close if (id != 'zotero-pane') { - // Close menuitem = document.createElement('menuitem'); menuitem.setAttribute('label', Zotero.getString('general.close')); menuitem.addEventListener('command', () => { @@ -409,6 +400,31 @@ var Zotero_Tabs = new function () { }); popup.appendChild(menuitem); } + // Close other tabs + if (!(this._tabs.length == 2 && id != 'zotero-pane')) { + menuitem = document.createElement('menuitem'); + menuitem.setAttribute('label', Zotero.getString('tabs.closeOther')); + menuitem.addEventListener('command', () => { + this.close(this._tabs.slice(1).filter(x => x.id != id).map(x => x.id)); + }); + popup.appendChild(menuitem); + } + // Undo close + menuitem = document.createElement('menuitem'); + menuitem.setAttribute( + 'label', + Zotero.getString( + 'tabs.undoClose', + [], + // If not disabled, show proper plural for tabs to reopen + this._history.length ? this._history[this._history.length - 1].length : 1 + ) + ); + menuitem.setAttribute('disabled', !this._history.length); + menuitem.addEventListener('command', () => { + this.undoClose(); + }); + popup.appendChild(menuitem); popup.openPopupAtScreen(x, y, true); }; diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index e48c2759c4..69fcc67e66 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -1360,5 +1360,5 @@ tabs.move = Move Tab tabs.moveToStart = Move to Start tabs.moveToEnd = Move to End tabs.moveToWindow = Move to New Window -tabs.undoClose = Reopen Closed Tab +tabs.undoClose = Reopen Closed Tab;Reopen Closed Tabs tabs.closeOther = Close Other Tabs