From 9b461385d3a5bf613f9b07b15a8266f29283cafd Mon Sep 17 00:00:00 2001 From: piro Date: Thu, 18 Oct 2007 18:20:54 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AD=90=E5=AD=AB=E3=82=92=E6=8C=81=E3=81=9F?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=82=BF=E3=83=96=E3=81=AB=E6=96=B0=E3=81=97?= =?UTF-8?q?=E3=81=84=E5=AD=90=E3=82=BF=E3=83=96=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=97=E3=81=9F=E6=99=82=E3=80=81=E8=87=AA=E5=8B=95=E3=81=A7?= =?UTF-8?q?=E4=BB=96=E3=81=AE=E3=82=B5=E3=83=96=E3=83=84=E3=83=AA=E3=83=BC?= =?UTF-8?q?=E3=82=92=E9=96=89=E3=81=98=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@1228 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/config.xul | 8 +- content/treestyletab/treestyletab.js | 110 ++++++++++++--------- locale/en-US/treestyletab/treestyletab.dtd | 2 +- locale/ja/treestyletab/treestyletab.dtd | 2 +- 4 files changed, 68 insertions(+), 54 deletions(-) diff --git a/content/treestyletab/config.xul b/content/treestyletab/config.xul index 02bd1927..58170d03 100644 --- a/content/treestyletab/config.xul +++ b/content/treestyletab/config.xul @@ -14,9 +14,9 @@ - + type="bool"/--> - + label="&config.autoExpandSubTreeOnAppendChild;"/--> diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index be464f91..4458cdd8 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -39,7 +39,7 @@ var TreeStyleTabService = { _SessionStore : null, /* Utilities */ - + isEventFiredOnTabIcon : function(aEvent) { var tab = this.getTabFromEvent(aEvent); @@ -65,7 +65,7 @@ var TreeStyleTabService = { } return (node && node.getAttribute('class') == this.kTWISTY) ? true : false ; }, - + get browser() { return 'SplitBrowser' ? SplitBrowser.activeBrowser : gBrowser ; @@ -200,7 +200,7 @@ var TreeStyleTabService = { }, /* Initializing */ - + init : function() { if (!('gBrowser' in window)) return; @@ -237,7 +237,7 @@ var TreeStyleTabService = { this.initTabBrowser(gBrowser); }, - + initTabBrowser : function(aTabBrowser) { aTabBrowser.mTabContainer.addEventListener('TreeStyleTab:TabOpen', this, true); @@ -634,45 +634,10 @@ var TreeStyleTabService = { else if (tab.getAttribute(this.kCHILDREN) && (tab.getAttribute(this.kSUBTREE_COLLAPSED) == 'true') && this.getPref('extensions.treestyletab.autoCollapseExpandSubTreeOnSelect')) { - var expandedParentTabs = [ - tab.getAttribute(this.kID) - ]; - var parentTab = tab; - while (parentTab = this.getParentTabOf(parentTab)) - { - expandedParentTabs.push(parentTab.getAttribute(this.kID)); - } - expandedParentTabs = expandedParentTabs.join('|'); - try { - var xpathResult = document.evaluate( - 'child::xul:tab[@'+this.kCHILDREN+' and not(@'+this.kCOLLAPSED+'="true") and not(@'+this.kSUBTREE_COLLAPSED+'="true") and not(contains("'+expandedParentTabs+'", @'+this.kID+'))]', - b.mTabContainer, - this.NSResolver, - XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, - null - ); - var collapseTab; - var isDescendant; - for (var i = 0, maxi = xpathResult.snapshotLength; i < maxi; i++) - { - isDescendant = false; - collapseTab = xpathResult.snapshotItem(i); - var parentTab = collapseTab; - while (parentTab = this.getParentTabOf(parentTab)) - { - if (parentTab != tab) continue; - isDescendant = true; - } - if (!isDescendant) - this.collapseExpandTabSubTree(collapseTab, true); - } - } - catch(e) { - } - this.collapseExpandTabSubTree(tab, false); + this.collapseExpandTreesIntelligentlyFor(tab); } }, - + /* Tab Utilities */ getTabValue : function(aTab, aKey) @@ -901,13 +866,21 @@ var TreeStyleTabService = { if (newIndex > aChild._tPos) newIndex--; this.moveTabSubTreeTo(aChild, newIndex); - if (aParent.getAttribute(this.kSUBTREE_COLLAPSED) == 'true') { - if (this.getPref('extensions.treestyletab.autoExpandSubTreeOnAppendChild')) { - var p = aParent; - do { - this.collapseExpandTabSubTree(p, false); - } - while (p = this.getParentTabOf(p)); + if ( + ( + aParent.getAttribute(this.kSUBTREE_COLLAPSED) == 'true' || + children.indexOf('|') < 0 // first child + ) && + this.getPref('extensions.treestyletab.autoCollapseExpandSubTreeOnSelect') + ) { + this.collapseExpandTreesIntelligentlyFor(aChild); + } + else if (aParent.getAttribute(this.kSUBTREE_COLLAPSED) == 'true') { + var p = aParent; + do { + this.collapseExpandTabSubTree(p, false); + } + while (p = this.getParentTabOf(p)); } else this.collapseExpandTab(aChild, true); @@ -1008,6 +981,47 @@ var TreeStyleTabService = { this.collapseExpandTab(tabs[i], aCollapse); } }, + + collapseExpandTreesIntelligentlyFor : function(aTab) + { + var b = this.getTabBrowserFromChildren(aTab); + var expandedParentTabs = [ + aTab.getAttribute(this.kID) + ]; + var parentTab = aTab; + while (parentTab = this.getParentTabOf(parentTab)) + { + expandedParentTabs.push(parentTab.getAttribute(this.kID)); + } + expandedParentTabs = expandedParentTabs.join('|'); + try { + var xpathResult = document.evaluate( + 'child::xul:tab[@'+this.kCHILDREN+' and not(@'+this.kCOLLAPSED+'="true") and not(@'+this.kSUBTREE_COLLAPSED+'="true") and not(contains("'+expandedParentTabs+'", @'+this.kID+'))]', + b.mTabContainer, + this.NSResolver, + XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, + null + ); + var collapseTab; + var isDescendant; + for (var i = 0, maxi = xpathResult.snapshotLength; i < maxi; i++) + { + isDescendant = false; + collapseTab = xpathResult.snapshotItem(i); + var parentTab = collapseTab; + while (parentTab = this.getParentTabOf(parentTab)) + { + if (parentTab != aTab) continue; + isDescendant = true; + } + if (!isDescendant) + this.collapseExpandTabSubTree(collapseTab, true); + } + } + catch(e) { + } + this.collapseExpandTabSubTree(aTab, false); + }, /* Pref Listener */ diff --git a/locale/en-US/treestyletab/treestyletab.dtd b/locale/en-US/treestyletab/treestyletab.dtd index b67d4592..cbb2b348 100644 --- a/locale/en-US/treestyletab/treestyletab.dtd +++ b/locale/en-US/treestyletab/treestyletab.dtd @@ -3,7 +3,7 @@ - + diff --git a/locale/ja/treestyletab/treestyletab.dtd b/locale/ja/treestyletab/treestyletab.dtd index 09bb5e54..d16b996a 100644 --- a/locale/ja/treestyletab/treestyletab.dtd +++ b/locale/ja/treestyletab/treestyletab.dtd @@ -3,7 +3,7 @@ - +