Bug 342169 Disable "Undo Close Tab" if no tabs to restore (r=mconnor)

This commit is contained in:
dietrich%mozilla.com 2006-06-28 20:44:35 +00:00
Родитель d07ba43f58
Коммит 528785f0f4
3 изменённых файлов: 28 добавлений и 7 удалений

Просмотреть файл

@ -6673,10 +6673,21 @@ window.controllers.appendController(BrowserController);
* This object is for augmenting tabs
*/
var AugmentTabs = {
tabContextMenu: null,
undoCloseTabMenu: null,
/**
* Called in delayedStartup
*/
init: function at_init() {
// get tab context menu
var tabbrowser = getBrowser();
this.tabContextMenu = document.getAnonymousElementByAttribute(tabbrowser, "anonid", "tabContextMenu");
// listen for tab-context menu showing
this.tabContextMenu.addEventListener("popupshowing", this.onTabContextMenuLoad, false);
// add the tab context menu for undo-close-tab (bz254021)
var ssEnabled = true;
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
@ -6693,10 +6704,6 @@ var AugmentTabs = {
* Add undo-close-tab to tab context menu
*/
_addUndoCloseTabContextMenu: function at_addUndoCloseTabContextMenu() {
// get tab context menu
var tabbrowser = getBrowser();
var tabMenu = document.getAnonymousElementByAttribute(tabbrowser,"anonid","tabContextMenu");
// get strings
var menuLabel = gNavigatorBundle.getString("tabContext.undoCloseTab");
var menuAccessKey = gNavigatorBundle.getString("tabContext.undoCloseTabAccessKey");
@ -6708,8 +6715,8 @@ var AugmentTabs = {
undoCloseTabItem.addEventListener("command", this.undoCloseTab, false);
// add to tab context menu
var insertPos = tabMenu.lastChild.previousSibling;
tabMenu.insertBefore(undoCloseTabItem, insertPos);
var insertPos = this.tabContextMenu.lastChild.previousSibling;
this.undoCloseTabMenu = this.tabContextMenu.insertBefore(undoCloseTabItem, insertPos);
},
/**
@ -6720,5 +6727,14 @@ var AugmentTabs = {
var ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
ss.undoCloseTab(window, 0);
},
onTabContextMenuLoad: function at_onTabContextMenuLoad() {
if (AugmentTabs.undoCloseTabMenu) {
// only add the menu of there are tabs to restore
var ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
AugmentTabs.undoCloseTabMenu.hidden = !(ss.getClosedTabCount(window) > 0);
}
}
};

Просмотреть файл

@ -54,6 +54,11 @@ interface nsISessionStore : nsISupports
*/
void init(in nsIDOMWindow aWindow);
/**
* Get the number of restore-able tabs for a window
*/
unsigned long getClosedTabCount(in nsIDOMWindow aWindow);
/**
* @param aWindow
* The window to reopen a closed tab in.

Просмотреть файл

@ -541,7 +541,7 @@ SessionStoreService.prototype = {
// DOMNodeRemoved is received *twice* after closing a tab, only take the first
var tabState = this._windows[aWindow.__SSi].tabs[aTab._tPos];
if (tabState) {
if (tabState && tabState.entries[0].url != "about:blank") {
this._windows[aWindow.__SSi]._closedTabs.unshift({
state: tabState,
title: aTab.getAttribute("label"),