Gather up tabs before prompting so that we can supply a tab count as well. r=gavin
authorJohnathan Nightingale <johnath@mozilla.com>
Fri, 21 Nov 2008 10:49:14 -0500
changeset 1 07ba23598de5
parent 0 4d0aefb59445
child 2 118d31653787
push id2
push userjnightingale@mozilla.com
push date2008-11-21 15:49 +0000
reviewersgavin
Gather up tabs before prompting so that we can supply a tab count as well. r=gavin
content/overlay.js
install.rdf
locale/en-US/tabcloser.properties
--- a/content/overlay.js
+++ b/content/overlay.js
@@ -68,36 +68,39 @@ var tabcloser = {
     var label = this.strings.getFormattedString("closeTabsForSite.label",
                                                 [host]);
     this.contextMenuItem.setAttribute("label", label);
   },
 
   onMenuItemCommand: function(e) {
     var host = gBrowser.mContextTab.linkedBrowser.currentURI.host;
 
-    // prompt?
-    var message = this.strings.getFormattedString("areYouSure.message",
-                                                [host]);
-    var title = this.strings.getString("areYouSure");
-    var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
-                        getService(Ci.nsIPromptService);
-    var confirmed = promptService.confirm(null, title, message);
-    if (!confirmed)
-      return;
-
+    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);
       try {
         var tabHost = browser.currentURI.host;
       } catch (ex) {
         // Ignore failure to get .host
         continue;
       }
       if (host == tabHost) {
-        gBrowser.removeTab(tab);
+        tabsToClose.push(tab);
       }
     }
+    
+    // prompt?
+    var message = this.strings.getFormattedString("areYouSure.message",
+                                                [tabsToClose.length, host]);
+    var title = this.strings.getString("areYouSure");
+    var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
+                        getService(Ci.nsIPromptService);
+    if (promptService.confirm(null, title, message)) {
+      tabsToClose.forEach(function (el) {
+        gBrowser.removeTab(el);
+      });
+    }
   },
 
 };
 window.addEventListener("load", function(e) { tabcloser.onLoad(e); }, false);
--- a/install.rdf
+++ b/install.rdf
@@ -1,15 +1,15 @@
 <?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.0</em:version>
+    <em:version>1.01</em:version>
     <em:creator>Gavin Sharp</em:creator>
     <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.1b2pre</em:maxVersion>
       </Description>
--- a/locale/en-US/tabcloser.properties
+++ b/locale/en-US/tabcloser.properties
@@ -1,5 +1,5 @@
 closeTabsForSite.label=Close all %S tabs
 closeTabsForSite.accesskey=l
 areYouSure=Are you sure?
-areYouSure.message=Are you sure you want to close all %S tabs?
+areYouSure.message=Are you sure you want to close all %S tabs from %S?
 extensions.tabcloser.description=Close all tabs for a given site.