Add option to disable confirmation dialog
authorGavin Sharp <gavin@gavinsharp.com>
Sat, 31 Oct 2009 01:42:01 -0400
changeset 12 a17a63e59463
parent 11 18807249b971
child 13 3b5a6ceb7e0f
push id13
push usergsharp@mozilla.com
push date2009-10-31 05:41 +0000
Add option to disable confirmation dialog
content/overlay.js
install.rdf
locale/en-US/tabcloser.properties
--- a/content/overlay.js
+++ b/content/overlay.js
@@ -73,37 +73,54 @@ var tabcloser = {
     label = PluralForm.get(tabCount, label).replace("#1", tabCount);
     this.contextMenuItem.setAttribute("label", label);
   },
 
   onMenuItemCommand: function(e) {
     var host = gBrowser.mContextTab.linkedBrowser.currentURI.host;
     var tabsToClose = this.getTabsToClose(host);
 
-    var message = this.strings.getFormattedString("areYouSure.message",
-                                                  [host]);
-    message = PluralForm.get(tabsToClose.length, message)
-                        .replace("#1", tabsToClose.length);
-    
-    var title = this.strings.getString("areYouSure");
-    var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
-                        getService(Ci.nsIPromptService);
-    
-    // don't prompt if there's only one tab
-    if (tabsToClose.length == 1 || promptService.confirm(window, title, message)) {
-      tabsToClose.forEach(function (t) {
-        // work around some strange bug in 3.0.x that causes removeTab to fail
-        // silently when closing the last tab this way. This isn't needed on
-        // trunk...
-        if (gBrowser.mTabs.length == 1)
-          closeWindow(true);
-        else
-          gBrowser.removeTab(t);
-      });
+    var shouldConfirm = true;
+    try {
+      shouldConfirm = gPrefService.getBoolPref("tabcloser.confirm");
+    } catch (ex) {}
+
+    // only prompt if there's more than one tab
+    if (shouldConfirm && tabsToClose.length > 1) {
+      var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
+                          getService(Ci.nsIPromptService);
+      var message = this.strings.getFormattedString("areYouSure.message",
+                                                    [host]);
+      message = PluralForm.get(tabsToClose.length, message)
+                          .replace("#1", tabsToClose.length);
+      
+      var title = this.strings.getString("areYouSure");
+      var dontPromptTitle = this.strings.getString("areYouSure.dontAskAgain");
+      var dontPrompt = {};
+
+      var doIt = 0 == promptService.confirmEx(window, title, message, 0, null, null, null, dontPromptTitle, dontPrompt);
+
+      // Only save the "don't ask" pref if the user didn't cancel
+      if (doIt && dontPrompt.value)
+        gPrefService.setBoolPref("tabcloser.confirm", false);
+
+      if (!doIt)
+        return;
     }
+
+    // Close the tabs
+    tabsToClose.forEach(function (t) {
+      // work around some strange bug in 3.0.x that causes removeTab to fail
+      // silently when closing the last tab this way. This isn't needed on
+      // trunk...
+      if (gBrowser.mTabs.length == 1)
+        closeWindow(true);
+      else
+        gBrowser.removeTab(t);
+    });
   },
 
   getTabsToClose : function(host) {
     var tabsToClose = [];
     var tabCount = gBrowser.mTabs.length;
     for (var i = tabCount - 1; i >= 0; i--) {
       var tab = gBrowser.mTabs[i];
       var browser = gBrowser.getBrowserForTab(tab);
--- a/install.rdf
+++ b/install.rdf
@@ -1,18 +1,19 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  xmlns:em="http://www.mozilla.org/2004/em-rdf#">
   <Description about="urn:mozilla:install-manifest">
     <em:id>tabcloser@gavinsharp.com</em:id>
     <em:name>TabCloser</em:name>
-    <em:version>1.05</em:version>
+    <em:version>1.06</em:version>
     <em:creator>Gavin Sharp</em:creator>
+    <em:contributor>Johnathan Nightingale</em:contributor>
     <em:description>Close all tabs for a given site.</em:description>
     <em:targetApplication>
       <Description>
         <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> <!-- firefox -->
         <em:minVersion>3.0</em:minVersion>
-        <em:maxVersion>3.6a1pre</em:maxVersion>
+        <em:maxVersion>3.7a1pre</em:maxVersion>
       </Description>
     </em:targetApplication>
   </Description>
 </RDF>
--- a/locale/en-US/tabcloser.properties
+++ b/locale/en-US/tabcloser.properties
@@ -2,9 +2,10 @@
 # Semi-colon list of plural forms.
 # See: http://developer.mozilla.org/en/docs/Localization_and_Plurals
 # #1 number of tabs
 # example: Close all 4 tabs from mxr.mozilla.org
 closeTabsForSite.label=Close #1 tab from %1$S;Close all #1 tabs from %1$S
 closeTabsForSite.accesskey=l
 areYouSure=Are you sure?
 areYouSure.message=Are you sure you want to close the tab from %1$S?;Are you sure you want to close all #1 tabs from %1$S?
+areYouSure.dontAskAgain=Don't ask again
 extensions.tabcloser.description=Close all tabs for a given site.