From 74e8806e17ed516e8dfd3a7cae959b51223e1d28 Mon Sep 17 00:00:00 2001 From: piro Date: Fri, 19 Oct 2007 13:05:29 +0000 Subject: [PATCH] =?UTF-8?q?=E3=82=BF=E3=83=96=E3=81=AB=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=BC=E3=82=AB=E3=82=B9=E3=81=97=E3=81=9F=E7=8A=B6=E6=85=8B?= =?UTF-8?q?=E3=81=A7=E3=81=AECtrl-=E4=B8=8A=E4=B8=8B=E5=B7=A6=E5=8F=B3?= =?UTF-8?q?=E3=81=A7=E3=81=AE=E3=82=BF=E3=83=96=E3=81=AE=E7=A7=BB=E5=8B=95?= =?UTF-8?q?=E3=80=81=E3=83=84=E3=83=AA=E3=83=BC=E3=81=AE=E7=B7=A8=E9=9B=86?= =?UTF-8?q?=E3=81=AB=E5=AF=BE=E5=BF=9C?= 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@1236 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/treestyletab.js | 163 +++++++++++++++++++++++---- 1 file changed, 143 insertions(+), 20 deletions(-) diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index 73675fe5..4a92d547 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -19,7 +19,9 @@ var TreeStyleTabService = { kFOCUS_ALL : 0, kFOCUS_VISIBLE : 1, - levelMargin : 12, + levelMargin : 12, + positionProp : 'screenY', + sizeProp : 'width', NSResolver : { lookupNamespaceURI : function(aPrefix) @@ -318,6 +320,114 @@ var TreeStyleTabService = { ) ); + eval('aTabBrowser.canDrop = '+ + aTabBrowser.canDrop.toSource().replace( + /\.screenX/g, '[TreeStyleTabService.positionProp]' + ).replace( + /\.width/g, '[TreeStyleTabService.sizeProp]' + ).replace( + /return true;/, + <> + ) + ); + + eval('aTabBrowser.moveTabForward = '+ + aTabBrowser.moveTabForward.toSource().replace( + '{', '{ var nextTab;' + ).replace( + 'tabPos < this.browsers.length - 1', + 'nextTab = TreeStyleTabService.getNextSiblingTabOf(this.mCurrentTab)' + ).replace( + 'tabPos + 1', 'nextTab._tPos' + ).replace( + 'this.moveTabTo(', + <> + ).replace( + 'this.moveTabToStart();', + <> + ) + ); + + eval('aTabBrowser.moveTabBackward = '+ + aTabBrowser.moveTabBackward.toSource().replace( + '{', '{ var prevTab;' + ).replace( + 'tabPos > 0', + 'prevTab = TreeStyleTabService.getPreviousSiblingTabOf(this.mCurrentTab)' + ).replace( + 'tabPos - 1', 'prevTab._tPos' + ).replace( + 'this.moveTabToEnd();', + <> + ) + ); + + eval('aTabBrowser.moveTabOver = '+ + aTabBrowser.moveTabOver.toSource().replace( + '{', + <> + ) + ); + var addTabMethod = 'addTab'; var removeTabMethod = 'removeTab'; if (aTabBrowser.__tabextensions__addTab) { @@ -468,12 +578,7 @@ var TreeStyleTabService = { return; case 'TabMove': - var tab = aEvent.originalTarget; - this.initTabContents(tab); // twisty vanished after the tab is moved!! - var b = this.getTabBrowserFromChildren(tab); - if (tab.getAttribute(this.kCHILDREN) && !b.__treestyletab__isSubTreeMoving) { - this.moveTabSubTreeTo(tab, tab._tPos); - } + this.onTabMove(aEvent); return; case 'SSTabRestoring': @@ -630,6 +735,25 @@ var TreeStyleTabService = { b.selectedTab = nextFocusedTab; }, + onTabMove : function(aEvent) + { + var tab = aEvent.originalTarget; + this.initTabContents(tab); // twisty vanished after the tab is moved!! + + var b = this.getTabBrowserFromChildren(tab); + if (tab.getAttribute(this.kCHILDREN) && !b.__treestyletab__isSubTreeMoving) { + this.moveTabSubTreeTo(tab, tab._tPos); + } + + var parentTab = this.getParentTabOf(tab); + if (parentTab && !b.__treestyletab__isSubTreeChildrenMoving) { + var children = this.getChildTabsOf(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('|')); + } + }, + onTabRestored : function(aEvent) { var tab = aEvent.originalTarget; @@ -793,11 +917,11 @@ var TreeStyleTabService = { var list = ('|'+children).split('|'+id)[1].split('|'); for (var i = 0, maxi = list.length; i < maxi; i++) { - firstChild = this.getTabById(list[i], b); - if (firstChild) break; + var firstChild = this.getTabById(list[i], b); + if (firstChild) return firstChild; } } - return firstChild; + return null; }, getPreviousSiblingTabOf : function(aTab) @@ -820,11 +944,11 @@ var TreeStyleTabService = { var list = ('|'+children).split('|'+id)[0].split('|'); for (var i = list.length-1; i > -1; i--) { - lastChild = this.getTabById(list[i], b) - if (lastChild) break; + var lastChild = this.getTabById(list[i], b) + if (lastChild) return lastChild; } } - return lastChild; + return null; }, getDescendantTabsOf : function(aTab) @@ -916,13 +1040,10 @@ var TreeStyleTabService = { } else { children = ((children || '')+'|'+id).replace(/^\|/, ''); - var refTab = aParent; - var lastChild = this.getLastChildTabOf(aParent); - if (lastChild) { - var descendant = this.getDescendantTabsOf(lastChild); - if (descendant.length) lastChild = descendant[descendant.length-1]; - } - newIndex = (lastChild ? lastChild : aParent )._tPos+1; + var refTab = aParent; + var descendant = TreeStyleTabService.getDescendantTabsOf(aParent); + if (descendant.length) refTab = descendant[descendant.length-1]; + newIndex = refTab._tPos+1; } this.setTabValue(aParent, this.kCHILDREN, children); @@ -1027,11 +1148,13 @@ var TreeStyleTabService = { b.moveTabTo(aTab, aIndex); + b.__treestyletab__isSubTreeChildrenMoving = true; var tabs = this.getDescendantTabsOf(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__isSubTreeChildrenMoving = false; b.__treestyletab__isSubTreeMoving = false; },