From 63a72c9e623b625a362a56f792e043db7e6a894c Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Wed, 21 Aug 2013 03:42:50 +0900 Subject: [PATCH] Don't close the window with the last group tab, if the last child of the group is closed. (#537) This behaviour can be disabled (and get the old behaviour) by setting the preference "extensions.treestyletab.autoRemoveNeedlessGroupTab.lastTab" to "true". --- defaults/preferences/treestyletab.js | 12 ++++++++++++ modules/base.js | 10 ++++++++++ modules/browser.js | 14 ++++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/defaults/preferences/treestyletab.js b/defaults/preferences/treestyletab.js index 669b97d3..7a3960e0 100644 --- a/defaults/preferences/treestyletab.js +++ b/defaults/preferences/treestyletab.js @@ -625,6 +625,18 @@ pref("extensions.treestyletab.createSubtree.underParent", true); */ pref("extensions.treestyletab.pinnedTab.faviconized", true); +/** + * Behaviour when the last child tab of the last group tab is closed. + * By default TST closes needless group tabs when they have no child anymore. + * However, if it is the last tab of an window or a group, then TST closes + * the window (or enters to the tab groups view). + * By changing these preferences, you can allow/disallow to close the window + * (or enter to the groups view). + * true: allow to close the last group tab automatically. + * false: disallow to close the last group tab automatically. + */ +pref("extensions.treestyletab.autoRemoveNeedlessGroupTab.lastTab", false); + /** * Compatibility hack flags for other addons. They can be disabled by each * addon, when the addon become working with TST without dirty hacks. diff --git a/modules/base.js b/modules/base.js index 53ab2f7c..0905cdbf 100644 --- a/modules/base.js +++ b/modules/base.js @@ -1310,6 +1310,16 @@ var TreeStyleTabBase = { return Array.slice(b.mTabContainer.querySelectorAll('tab:not([hidden="true"])')); }, + /** + * Returns all hidden tabs in background groups as an array. + */ + getHiddenTabs : function TSTBase_getHiddenTabs(aTabBrowserChild) + { + var b = this.getTabBrowserFromChild(aTabBrowserChild || this.browser); + this.assertBeforeDestruction(b && b.mTabContainer); + return Array.slice(b.mTabContainer.querySelectorAll('tab[hidden="true"]')); + }, + getAllTabsArray : function TSTBase_getAllTabsArray(aTabBrowserChild) /* for backward compatibility */ { return this.getAllTabs(aTabBrowserChild); diff --git a/modules/browser.js b/modules/browser.js index efc55163..2786da52 100644 --- a/modules/browser.js +++ b/modules/browser.js @@ -3105,7 +3105,8 @@ TreeStyleTabBrowser.prototype = { var shouldCloseParentTab = ( parent && this.isGroupTab(parent) && - this.getDescendantTabs(parent).length == 1 + this.getDescendantTabs(parent).length == 1 && + this._canCloseLastGroupTab(parent) ); if (shouldCloseParentTab) tabs.push(parent); @@ -3113,6 +3114,14 @@ TreeStyleTabBrowser.prototype = { return tabs; }, + _canCloseLastGroupTab : function TSTBrowser_canCloseLastGroupTab(aGroupTab) + { + return ( + utils.getTreePref('autoRemoveNeedlessGroupTab.lastTab') || + this.getSiblingTabs(aGroupTab).length > 0 + ); + }, + _reserveCloseRelatedTabs : function TSTBrowser_reserveCloseRelatedTabs(aTabs) { if (!aTabs.length) @@ -5092,7 +5101,8 @@ TreeStyleTabBrowser.prototype = { if (this.isGroupTab(parentTab) && !this.hasChildTabs(parentTab)) { this.window.setTimeout(function(aTabBrowser) { - if (parentTab.parentNode) + if (parentTab.parentNode && + aTabBrowser.treeStyleTab._canCloseLastGroupTab(parentTab)) aTabBrowser.removeTab(parentTab, { animate : true }); parentTab = null; }, 0, this.getTabBrowserFromChild(parentTab));