Bug 577121 - Tab context menu item "Close Other Tabs" should exclude pinned tabs. r=dao
authorMichael Kohler <michaelkohler@live.com>
Thu, 22 Jul 2010 17:51:55 +0200
changeset 48120 f4fd78850340c58f4ed4702c1e5329f0d6ff9a0d
parent 48119 05a194f6de30fb8694bc5e4c98b56eeb9092c885
child 48121 54c9709c9ee9169aa665ed5d9ada52b95107f1c8
push id14581
push userdgottwald@mozilla.com
push dateFri, 23 Jul 2010 07:29:15 +0000
treeherderautoland@06a37463c15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs577121
milestone2.0b3pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 577121 - Tab context menu item "Close Other Tabs" should exclude pinned tabs. r=dao
browser/base/content/browser.js
browser/base/content/browser.xul
browser/base/content/tabbrowser.xml
browser/base/content/test/Makefile.in
browser/base/content/test/browser_bug577121.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -7770,16 +7770,22 @@ var TabContextMenu = {
     document.getElementById("context_undoCloseTab").hidden =
       Cc["@mozilla.org/browser/sessionstore;1"].
       getService(Ci.nsISessionStore).
       getClosedTabCount(window) == 0;
       
     // Only one of pin/unpin should be visible
     document.getElementById("context_pinTab").hidden = this.contextTab.pinned;
     document.getElementById("context_unpinTab").hidden = !this.contextTab.pinned;
+
+    // Disable "Close other Tabs" if there is only one unpinned tab and
+    // hide it when the user rightclicked on a pinned tab.
+    var unpinnedTabs = gBrowser.tabs.length - gBrowser._numPinnedTabs;
+    document.getElementById("context_closeOtherTabs").disabled = unpinnedTabs <= 1;
+    document.getElementById("context_closeOtherTabs").hidden = this.contextTab.pinned;
   }
 };
 
 XPCOMUtils.defineLazyGetter(this, "HUDConsoleUI", function () {
   Cu.import("resource://gre/modules/HUDService.jsm");
   try {
     return HUDService.consoleUI;
   }
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -110,17 +110,16 @@
                onpopupshowing="if (event.target == this) TabContextMenu.updateContextMenu(this);"
                onpopuphidden="if (event.target == this) TabContextMenu.contextTab = null;">
       <menuitem id="context_reloadTab" label="&reloadTab.label;" accesskey="&reloadTab.accesskey;"
                 oncommand="gBrowser.reloadTab(TabContextMenu.contextTab);"/>
       <menuitem id="context_reloadAllTabs" label="&reloadAllTabs.label;" accesskey="&reloadAllTabs.accesskey;"
                 tbattr="tabbrowser-multiple"
                 oncommand="gBrowser.reloadAllTabs();"/>
       <menuitem id="context_closeOtherTabs" label="&closeOtherTabs.label;" accesskey="&closeOtherTabs.accesskey;"
-                tbattr="tabbrowser-multiple"
                 oncommand="gBrowser.removeAllTabsBut(TabContextMenu.contextTab);"/>
       <menuseparator/>
       <menuitem id="context_openTabInWindow" label="&openTabInNewWindow.label;"
                 accesskey="&openTabInNewWindow.accesskey;"
                 tbattr="tabbrowser-multiple"
                 oncommand="gBrowser.replaceTabWithWindow(TabContextMenu.contextTab);"/>
       <menuitem id="context_pinTab" label="&pinTab.label;"
                 accesskey="&pinTab.accesskey;"
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -1211,18 +1211,19 @@
         </body>
       </method>
 
       <method name="warnAboutClosingTabs">
       <parameter name="aAll"/>
       <body>
         <![CDATA[
           var tabsToClose = this.tabs.length;
+
           if (!aAll)
-            --tabsToClose;
+            tabsToClose -= 1 + gBrowser._numPinnedTabs;
           if (tabsToClose <= 1)
             return true;
 
           const pref = "browser.tabs.warnOnClose";
           var shouldPrompt = Services.prefs.getBoolPref(pref);
 
           if (!shouldPrompt)
             return true;
@@ -1259,21 +1260,24 @@
         ]]>
       </body>
       </method>
 
       <method name="removeAllTabsBut">
         <parameter name="aTab"/>
         <body>
           <![CDATA[
+            if (aTab.pinned)
+              return;
+
             if (this.warnAboutClosingTabs(false)) {
               this.selectedTab = aTab;
 
               for (let i = this.tabs.length - 1; i >= 0; --i) {
-                if (this.tabs[i] != aTab)
+                if (this.tabs[i] != aTab && !this.tabs[i].pinned)
                   this.removeTab(this.tabs[i]);
               }
             }
           ]]>
         </body>
       </method>
 
       <method name="removeCurrentTab">
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -131,16 +131,17 @@ endif
                  browser_bug537474.js \
                  browser_bug550565.js \
                  browser_bug553455.js \
                  browser_bug555224.js \
                  browser_bug555767.js \
                  browser_bug556061.js \
                  browser_bug562649.js \
                  browser_bug563588.js \
+                 browser_bug577121.js \
                  browser_contextSearchTabPosition.js \
                  browser_ctrlTab.js \
                  browser_discovery.js \
                  browser_drag.js \
                  browser_gestureSupport.js \
                  browser_getshortcutoruri.js \
                  browser_inspector_initialization.js \
                  browser_inspector_treeSelection.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_bug577121.js
@@ -0,0 +1,56 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is bug 577121 test.
+ *
+ * The Initial Developer of the Original Code is
+ * Michael Kohler <michaelkohler@live.com>.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+function test() {
+  // Open 2 other tabs, and pin the second one. Like that, the initial tab
+  // should get closed.
+  let testTab1 = gBrowser.addTab();
+  let testTab2 = gBrowser.addTab();
+  gBrowser.pinTab(testTab2);
+
+  // Now execute "Close other Tabs" on the first manually opened tab (tab1).
+  // -> tab2 ist pinned, tab1 should remain open and the initial tab should
+  // get closed.
+  gBrowser.removeAllTabsBut(testTab1);
+
+  is(gBrowser.tabs.length, 2, "there are two remaining tabs open");
+  is(gBrowser.tabs[0], testTab2, "pinned tab2 stayed open");
+  is(gBrowser.tabs[1], testTab1, "tab1 stayed open");
+  
+  // Cleanup. Close only one tab because we need an opened tab at the end of
+  // the test.
+  gBrowser.removeTab(testTab2);
+}