Bug 108973 Multi-tabbed windows should confirm close

patch by riceman+bmo@mail.rit.edu r=neil sr=jag


git-svn-id: svn://10.0.0.236/trunk@144131 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
timeless%mozdev.org
2003-06-25 02:13:35 +00:00
parent e11bc6808c
commit 0ad276075d
4 changed files with 44 additions and 2 deletions

View File

@@ -198,6 +198,7 @@ pref("browser.tabs.opentabfor.middleclick", false);
pref("browser.tabs.opentabfor.urlbar", false);
pref("browser.tabs.opentabfor.windowopen", false);
pref("browser.tabs.opentabfor.bookmarks", false);
pref("browser.tabs.warnOnClose", true);
// lets new tab/window load something different than first window
// -1 - use navigator startup preference

View File

@@ -457,6 +457,8 @@ function Startup()
.getService(Components.interfaces.nsIPrefService);
pref = prefService.getBranch(null);
window.tryToClose = WindowIsClosing;
webNavigation = getWebNavigation();
if (!webNavigation)
throw "no XBL binding for browser";
@@ -1212,7 +1214,7 @@ function BrowserEditBookmarks()
function updateCloseItems()
{
var browser = getBrowser();
if (browser && browser.localName == 'tabbrowser' && browser.getStripVisibility()) {
if (browser.getStripVisibility()) {
document.getElementById('menu_close').setAttribute('label', gNavigatorBundle.getString('tabs.closeTab'));
document.getElementById('menu_closeWindow').hidden = false;
document.getElementById('menu_closeOtherTabs').hidden = false;
@@ -1236,7 +1238,7 @@ function BrowserCloseOtherTabs()
function BrowserCloseTabOrWindow()
{
var browser = getBrowser();
if (browser && browser.localName == 'tabbrowser' && browser.mTabContainer.childNodes.length > 1) {
if (browser.mTabContainer.childNodes.length > 1) {
// Just close up a tab.
browser.removeCurrentTab();
return;
@@ -2271,3 +2273,37 @@ function maybeInitPopupContext()
}
return null;
}
function WindowIsClosing()
{
var browser = getBrowser();
var numtabs = browser.mTabContainer.childNodes.length;
var reallyClose = true;
if (numtabs > 1) {
var shouldPrompt = pref.getBoolPref("browser.tabs.warnOnClose");
if (shouldPrompt) {
var promptService =
Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
//default to true: if it were false, we wouldn't get this far
var warnOnClose = {value:true};
var buttonPressed = promptService.confirmEx(window,
gNavigatorBundle.getString('tabs.closeWarningTitle'),
gNavigatorBundle.getFormattedString("tabs.closeWarning", [numtabs]),
(promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0)
+ (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1),
gNavigatorBundle.getString('tabs.closeButton'),
null, null,
gNavigatorBundle.getString('tabs.closeWarningPromptMe'),
warnOnClose);
reallyClose = (buttonPressed == 0);
//don't set the pref unless they press OK and it's false
if (reallyClose && !warnOnClose.value) {
pref.setBoolPref("browser.tabs.warnOnClose", false);
}
} //if the warn-me pref was true
} //if multiple tabs are open
return reallyClose;
}

View File

@@ -47,6 +47,7 @@ Contributor(s):
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="Startup()" onunload="Shutdown()"
onclose="return WindowIsClosing();"
contenttitlesetting="true"
title="&mainWindow.title;"
titlemodifier="&mainWindow.titlemodifier;"

View File

@@ -60,6 +60,10 @@ showskinsdescription=true
tabs.closeTab=Close Tab
tabs.close=Close
tabs.closeWarningTitle=Confirm close
tabs.closeWarning=This window has %S Navigator tabs open. Do you want to close the window and all its open tabs?
tabs.closeButton=Close all tabs
tabs.closeWarningPromptMe=Warn me when closing multiple tabs
tabs.historyItem=Group of Tabs
# urlbarBindings.xml