From 9ddf18c0ae4072d5193fea5003eea86dce716a3b Mon Sep 17 00:00:00 2001 From: piro Date: Fri, 26 Oct 2007 19:27:30 +0000 Subject: [PATCH] =?UTF-8?q?moveTabTo=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=81=A7=E7=9B=B4=E6=8E=A5=E3=82=BF=E3=83=96=E3=81=AE=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E3=82=92=E5=8B=95=E3=81=8B=E3=81=95=E3=82=8C=E3=81=9F?= =?UTF-8?q?=E6=99=82=E3=81=AB=E3=80=81=E8=87=AA=E5=8B=95=E7=9A=84=E3=81=AB?= =?UTF-8?q?=E3=83=84=E3=83=AA=E3=83=BC=E3=82=92=E4=BF=AE=E5=BE=A9=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=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@1346 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/config.xul | 4 +- content/treestyletab/treestyletab.js | 74 +++++++++++++++++++++++++--- 2 files changed, 69 insertions(+), 9 deletions(-) diff --git a/content/treestyletab/config.xul b/content/treestyletab/config.xul index 27b25eb1..987ed7a4 100644 --- a/content/treestyletab/config.xul +++ b/content/treestyletab/config.xul @@ -62,7 +62,7 @@ - + - + ) ); @@ -580,6 +582,7 @@ catch(e) { ).replace( 'this.moveTabToEnd();', <> ) ); @@ -1153,18 +1157,54 @@ catch(e) { var tab = aEvent.originalTarget; this.initTabContents(tab); // twisty vanished after the tab is moved!! + var rebuildTreeDone = false; + var b = this.getTabBrowserFromChildren(tab); if (tab.getAttribute(this.kCHILDREN) && !b.__treestyletab__isSubTreeMoving) { this.moveTabSubTreeTo(tab, tab._tPos); + rebuildTreeDone = true; } var parentTab = this.getParentTab(tab); if (parentTab && !b.__treestyletab__isSubTreeChildrenMoving) { - var children = this.getChildTabs(parentTab); - children.sort(function(aA, aB) { return aA._tPos - aB._tPos; }); - var self = this; - this.setTabValue(parentTab, this.kCHILDREN, children.map(function(aItem) { return aItem.getAttribute(self.kID); }).join('|')); + this.updateChildrenArray(parentTab); } + + if ( + rebuildTreeDone || + b.__treestyletab__isSubTreeMoving || + b.__treestyletab__internallyTabMoving + ) + return; + + var nest = Number(tab.getAttribute(this.kNEST) || 0); + var parent = this.getParentTab(tab); + var prevParent = this.getParentTab(tab.previousSibling); + var nextParent = this.getParentTab(tab.nextSibling); + var prevNest = tab.previousSibling ? Number(tab.previousSibling.getAttribute(this.kNEST)) : -1 ; + var nextNest = tab.nextSibling ? Number(tab.nextSibling.getAttribute(this.kNEST)) : -1 ; + + if ( + !tab.previousSibling || !tab.nextSibling || + prevParent == nextParent || + prevNest > nextNest + ) { + if (prevParent) + this.attachTabTo(tab, prevParent, { insertBefore : tab.nextSibling }); + else + this.partTab(tab); + } + else if (prevNest < nextNest) { + this.attachTabTo(tab, tab.previousSibling, { insertBefore : tab.nextSibling }); + } + }, + updateChildrenArray : function(aTab) + { + var children = this.getChildTabs(aTab); + children.sort(function(aA, aB) { return aA._tPos - aB._tPos; }); + var self = this; + this.setTabValue(aTab, this.kCHILDREN, + children.map(function(aItem) { return aItem.getAttribute(self.kID); }).join('|')); }, onTabRestored : function(aEvent) @@ -1210,7 +1250,9 @@ catch(e) { if (!parent && (before = this.getTabById(before, b))) { var index = before._tPos; if (index > tab._tPos) index--; + b.__treestyletab__internallyTabMoving = true; b.moveTabTo(tab, index); + b.__treestyletab__internallyTabMoving = false; } this.deleteTabValue(tab, this.kINSERT_BEFORE); @@ -1299,7 +1341,9 @@ catch(e) { ) { var newIndex = aInfo.insertBefore ? aInfo.insertBefore._tPos : tabs.length - 1 ; if (aInfo.insertBefore && newIndex > aTarget._tPos) newIndex--; + b.__treestyletab__internallyTabMoving = true; b.moveTabTo(aTarget, newIndex); + b.__treestyletab__internallyTabMoving = false; } return true; }, @@ -1395,9 +1439,9 @@ catch(e) { getParentTab : function(aTab) { - var id = aTab.getAttribute(this.kID); + if (!aTab) return null; return this.evaluateXPath( - 'parent::*/child::xul:tab[contains(@'+this.kCHILDREN+', "'+id+'")]', + 'parent::*/child::xul:tab[contains(@'+this.kCHILDREN+', "'+aTab.getAttribute(this.kID)+'")]', aTab, XPathResult.FIRST_ORDERED_NODE_TYPE ).singleNodeValue; @@ -1405,6 +1449,8 @@ catch(e) { getNextSiblingTab : function(aTab) { + if (!aTab) return null; + var id = aTab.getAttribute(this.kID); var parentTab = this.getParentTab(aTab); @@ -1432,6 +1478,8 @@ catch(e) { getPreviousSiblingTab : function(aTab) { + if (!aTab) return null; + var id = aTab.getAttribute(this.kID); var parentTab = this.getParentTab(aTab); @@ -1459,7 +1507,9 @@ catch(e) { getChildTabs : function(aTab, aAllTabsArray) { - var tabs = []; + var tabs = []; + if (!aTab) return null; + var children = aTab.getAttribute(this.kCHILDREN); if (!children) return tabs; @@ -1489,6 +1539,8 @@ catch(e) { getFirstChildTab : function(aTab) { + if (!aTab) return null; + var b = this.getTabBrowserFromChildren(aTab); var children = aTab.getAttribute(this.kCHILDREN); var firstChild = null; @@ -1505,6 +1557,8 @@ catch(e) { getLastChildTab : function(aTab) { + if (!aTab) return null; + var b = this.getTabBrowserFromChildren(aTab); var children = aTab.getAttribute(this.kCHILDREN); var lastChild = null; @@ -1988,14 +2042,18 @@ catch(e) { var b = this.getTabBrowserFromChildren(aTab); b.__treestyletab__isSubTreeMoving = true; + b.__treestyletab__internallyTabMoving = true; b.moveTabTo(aTab, aIndex); + b.__treestyletab__internallyTabMoving = false; b.__treestyletab__isSubTreeChildrenMoving = true; + b.__treestyletab__internallyTabMoving = true; var tabs = this.getDescendantTabs(aTab); for (var i = 0, maxi = tabs.length; i < maxi; i++) { b.moveTabTo(tabs[i], aTab._tPos+i+(aTab._tPos < tabs[i]._tPos ? 1 : 0 )); } + b.__treestyletab__internallyTabMoving = false; b.__treestyletab__isSubTreeChildrenMoving = false; b.__treestyletab__isSubTreeMoving = false; @@ -2024,12 +2082,14 @@ catch(e) { else { var nextTab = this.getNextSiblingTab(parentTab); this.partTab(b.mCurrentTab); + b.__treestyletab__internallyTabMoving = true; if (nextTab) { b.moveTabTo(b.mCurrentTab, nextTab._tPos - 1); } else { b.moveTabTo(b.mCurrentTab, b.mTabContainer.lastChild._tPos); } + b.__treestyletab__internallyTabMoving = false; b.mCurrentTab.focus(); return true; }