Bug 1455300 - Part 2: Include hidden tabs in the History menu r?mak
MozReview-Commit-ID: 8sKrAJVIAD5
--- a/browser/base/content/browser-menubar.inc
+++ b/browser/base/content/browser-menubar.inc
@@ -333,35 +333,41 @@
#endif
command="Browser:ShowAllHistory"/>
<menuitem id="sanitizeItem"
label="&clearRecentHistory.label;"
key="key_sanitize"
command="Tools:Sanitize"/>
<menuseparator id="sanitizeSeparator"/>
<menuitem id="sync-tabs-menuitem"
- class="syncTabsMenuItem"
label="&syncTabsMenu3.label;"
oncommand="BrowserOpenSyncTabs();"
hidden="true"/>
<menuitem id="historyRestoreLastSession"
label="&historyRestoreLastSession.label;"
command="Browser:RestoreLastSession"/>
+ <menu id="hiddenTabsMenu"
+ label="&hiddenTabs.label;"
+ hidden="true">
+ <menupopup
+#ifndef XP_MACOSX
+ placespopup="true"
+#endif
+ />
+ </menu>
<menu id="historyUndoMenu"
- class="recentlyClosedTabsMenu"
label="&historyUndoMenu.label;"
disabled="true">
<menupopup id="historyUndoPopup"
#ifndef XP_MACOSX
placespopup="true"
#endif
onpopupshowing="document.getElementById('history-menu')._placesView.populateUndoSubmenu();"/>
</menu>
<menu id="historyUndoWindowMenu"
- class="recentlyClosedWindowsMenu"
label="&historyUndoWindowMenu.label;"
disabled="true">
<menupopup id="historyUndoWindowPopup"
#ifndef XP_MACOSX
placespopup="true"
#endif
onpopupshowing="document.getElementById('history-menu')._placesView.populateUndoWindowSubmenu();"/>
</menu>
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -602,124 +602,140 @@ ChromeUtils.defineModuleGetter(this, "Re
// View for the history menu.
function HistoryMenu(aPopupShowingEvent) {
// Workaround for Bug 610187. The sidebar does not include all the Places
// views definitions, and we don't need them there.
// Defining the prototype inheritance in the prototype itself would cause
// browser.js to halt on "PlacesMenu is not defined" error.
this.__proto__.__proto__ = PlacesMenu.prototype;
+ Object.keys(this._elements).forEach(name => {
+ this[name] = document.getElementById(this._elements[name]);
+ });
+ this._hiddenTabsPopup = new TabsPopup({
+ filterFn: (tab) => tab.hidden,
+ popup: this.hiddenTabsMenu.firstChild,
+ });
PlacesMenu.call(this, aPopupShowingEvent,
"place:sort=4&maxResults=15");
}
HistoryMenu.prototype = {
+ _elements: {
+ undoTabMenu: "historyUndoMenu",
+ hiddenTabsMenu: "hiddenTabsMenu",
+ undoWindowMenu: "historyUndoWindowMenu",
+ syncTabsMenuitem: "sync-tabs-menuitem",
+ },
+
_getClosedTabCount() {
// SessionStore doesn't track the hidden window, so just return zero then.
if (window == Services.appShell.hiddenDOMWindow) {
return 0;
}
return SessionStore.getClosedTabCount(window);
},
+ toggleHiddenTabs() {
+ if (gBrowser.visibleTabs.length < gBrowser.tabs.length) {
+ this.hiddenTabsMenu.removeAttribute("hidden");
+ } else {
+ this.hiddenTabsMenu.setAttribute("hidden", "true");
+ }
+ },
+
toggleRecentlyClosedTabs: function HM_toggleRecentlyClosedTabs() {
// enable/disable the Recently Closed Tabs sub menu
- var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedTabsMenu")[0];
-
// no restorable tabs, so disable menu
if (this._getClosedTabCount() == 0)
- undoMenu.setAttribute("disabled", true);
+ this.undoTabMenu.setAttribute("disabled", true);
else
- undoMenu.removeAttribute("disabled");
+ this.undoTabMenu.removeAttribute("disabled");
},
/**
* Populate when the history menu is opened
*/
populateUndoSubmenu: function PHM_populateUndoSubmenu() {
- var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedTabsMenu")[0];
- var undoPopup = undoMenu.firstChild;
+ var undoPopup = this.undoTabMenu.firstChild;
// remove existing menu items
while (undoPopup.hasChildNodes())
undoPopup.firstChild.remove();
// no restorable tabs, so make sure menu is disabled, and return
if (this._getClosedTabCount() == 0) {
- undoMenu.setAttribute("disabled", true);
+ this.undoTabMenu.setAttribute("disabled", true);
return;
}
// enable menu
- undoMenu.removeAttribute("disabled");
+ this.undoTabMenu.removeAttribute("disabled");
// populate menu
let tabsFragment = RecentlyClosedTabsAndWindowsMenuUtils.getTabsFragment(window, "menuitem");
undoPopup.appendChild(tabsFragment);
},
toggleRecentlyClosedWindows: function PHM_toggleRecentlyClosedWindows() {
// enable/disable the Recently Closed Windows sub menu
- var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedWindowsMenu")[0];
-
// no restorable windows, so disable menu
if (SessionStore.getClosedWindowCount() == 0)
- undoMenu.setAttribute("disabled", true);
+ this.undoWindowMenu.setAttribute("disabled", true);
else
- undoMenu.removeAttribute("disabled");
+ this.undoWindowMenu.removeAttribute("disabled");
},
/**
* Populate when the history menu is opened
*/
populateUndoWindowSubmenu: function PHM_populateUndoWindowSubmenu() {
- let undoMenu = this._rootElt.getElementsByClassName("recentlyClosedWindowsMenu")[0];
- let undoPopup = undoMenu.firstChild;
+ let undoPopup = this.undoWindowMenu.firstChild;
// remove existing menu items
while (undoPopup.hasChildNodes())
undoPopup.firstChild.remove();
// no restorable windows, so make sure menu is disabled, and return
if (SessionStore.getClosedWindowCount() == 0) {
- undoMenu.setAttribute("disabled", true);
+ this.undoWindowMenu.setAttribute("disabled", true);
return;
}
// enable menu
- undoMenu.removeAttribute("disabled");
+ this.undoWindowMenu.removeAttribute("disabled");
// populate menu
let windowsFragment = RecentlyClosedTabsAndWindowsMenuUtils.getWindowsFragment(window, "menuitem");
undoPopup.appendChild(windowsFragment);
},
toggleTabsFromOtherComputers: function PHM_toggleTabsFromOtherComputers() {
// Enable/disable the Tabs From Other Computers menu. Some of the menus handled
// by HistoryMenu do not have this menuitem.
- let menuitem = this._rootElt.getElementsByClassName("syncTabsMenuItem")[0];
- if (!menuitem)
+ if (!this.syncTabsMenuitem)
return;
if (!PlacesUIUtils.shouldShowTabsFromOtherComputersMenuitem()) {
- menuitem.setAttribute("hidden", true);
+ this.syncTabsMenuitem.setAttribute("hidden", true);
return;
}
- menuitem.setAttribute("hidden", false);
+ this.syncTabsMenuitem.setAttribute("hidden", false);
},
_onPopupShowing: function HM__onPopupShowing(aEvent) {
PlacesMenu.prototype._onPopupShowing.apply(this, arguments);
// Don't handle events for submenus.
if (aEvent.target != aEvent.currentTarget)
return;
+ this.toggleHiddenTabs();
this.toggleRecentlyClosedTabs();
this.toggleRecentlyClosedWindows();
this.toggleTabsFromOtherComputers();
},
_onCommand: function HM__onCommand(aEvent) {
let placesNode = aEvent.target._placesNode;
if (placesNode) {