From 0ad276075d06dbbd3710c919df9ff381e6dd7384 Mon Sep 17 00:00:00 2001 From: "timeless%mozdev.org" Date: Wed, 25 Jun 2003 02:13:35 +0000 Subject: [PATCH] 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 --- mozilla/modules/libpref/src/init/all.js | 1 + .../browser/resources/content/navigator.js | 40 ++++++++++++++++++- .../browser/resources/content/navigator.xul | 1 + .../locale/en-US/navigator.properties | 4 ++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/mozilla/modules/libpref/src/init/all.js b/mozilla/modules/libpref/src/init/all.js index 22c8055d68f..91bca138b59 100644 --- a/mozilla/modules/libpref/src/init/all.js +++ b/mozilla/modules/libpref/src/init/all.js @@ -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 diff --git a/mozilla/xpfe/browser/resources/content/navigator.js b/mozilla/xpfe/browser/resources/content/navigator.js index 51d119301f3..86f7fce579b 100644 --- a/mozilla/xpfe/browser/resources/content/navigator.js +++ b/mozilla/xpfe/browser/resources/content/navigator.js @@ -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; +} diff --git a/mozilla/xpfe/browser/resources/content/navigator.xul b/mozilla/xpfe/browser/resources/content/navigator.xul index d84b1ae5b0e..73892f479d5 100644 --- a/mozilla/xpfe/browser/resources/content/navigator.xul +++ b/mozilla/xpfe/browser/resources/content/navigator.xul @@ -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;" diff --git a/mozilla/xpfe/browser/resources/locale/en-US/navigator.properties b/mozilla/xpfe/browser/resources/locale/en-US/navigator.properties index 87b2e2efcd0..736f7c9b8e5 100644 --- a/mozilla/xpfe/browser/resources/locale/en-US/navigator.properties +++ b/mozilla/xpfe/browser/resources/locale/en-US/navigator.properties @@ -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