From 8ef44b89f5a663ff968aa7e3c830c1c06a8a3fd9 Mon Sep 17 00:00:00 2001 From: piro Date: Wed, 17 Oct 2007 23:48:30 +0000 Subject: [PATCH] =?UTF-8?q?=E3=82=BF=E3=83=96=E3=82=92=E9=96=8B=E3=81=8D?= =?UTF-8?q?=E7=9B=B4=E3=81=97=E3=81=9F=E9=9A=9B=E3=81=AB=E5=90=84=E7=A8=AE?= =?UTF-8?q?=E6=83=85=E5=A0=B1=E3=82=92=E5=BE=A9=E5=85=83=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F=20=EF=BC=88?= =?UTF-8?q?=E3=81=9F=E3=81=A0=E3=81=97=E3=80=81=E3=82=B5=E3=83=96=E3=83=84?= =?UTF-8?q?=E3=83=AA=E3=83=BC=E3=81=AE=E5=BE=A9=E5=85=83=E3=81=AF=E3=80=81?= =?UTF-8?q?=E5=BE=A9=E5=85=83=E3=81=97=E3=81=9F=E3=82=BF=E3=83=96=E3=81=8C?= =?UTF-8?q?=E8=A6=AA=E3=81=AE=E3=82=BF=E3=83=96=E3=81=8B=E3=82=89=E8=A6=8B?= =?UTF-8?q?=E3=81=A6=E6=9C=80=E5=BE=8C=E3=81=AE=E5=AD=90=E3=81=A7=E3=81=82?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=AE=E3=81=BF=20?= =?UTF-8?q?=E3=80=80=E6=AD=A3=E3=81=97=E3=81=8F=E5=8B=95=E4=BD=9C=E3=81=97?= =?UTF-8?q?=E3=80=81=E3=81=9D=E3=81=86=E3=81=A7=E3=81=AA=E3=81=84=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=AF=E5=AD=90=E5=AD=AB=E3=82=BF=E3=83=96=E3=81=AE?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E3=81=8C=E3=81=9A=E3=82=8C=E3=82=8B=E5=95=8F?= =?UTF-8?q?=E9=A1=8C=E3=81=8C=E8=B5=B7=E3=81=93=E3=82=8B=E3=80=82=E8=A6=81?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=80=82=EF=BC=89?= 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@1223 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/treestyletab.js | 67 ++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index 4f8026fd..7a8aac28 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -226,6 +226,8 @@ var TreeStyleTabService = { { aTabBrowser.mTabContainer.addEventListener('TreeStyleTab:TabOpen', this, true); aTabBrowser.mTabContainer.addEventListener('TabClose', this, true); + aTabBrowser.mTabContainer.addEventListener('TabMove', this, true); + aTabBrowser.mTabContainer.addEventListener('SSTabRestoring', this, true); aTabBrowser.mPanelContainer.addEventListener('click', this, true); @@ -313,6 +315,8 @@ var TreeStyleTabService = { { aTabBrowser.mTabContainer.removeEventListener('TreeStyleTab:TabOpen', this, true); aTabBrowser.mTabContainer.removeEventListener('TabClose', this, true); + aTabBrowser.mTabContainer.removeEventListener('TabMove', this, true); + aTabBrowser.mTabContainer.removeEventListener('SSTabRestoring', this, true); aTabBrowser.mPanelContainer.removeEventListener('click', this, true); // var tabContextMenu = document.getAnonymousElementByAttribute(aTabBrowser, 'anonid', 'tabContextMenu'); @@ -338,6 +342,18 @@ var TreeStyleTabService = { this.onTabRemoved(aEvent); break; + case 'TabMove': + var tab = aEvent.originalTarget; + var b = this.getTabBrowserFromChildren(tab); + if (tab.getAttribute(this.kCHILDREN) && !b.__treestyletab__isSubTreeMoving) { + this.moveTabSubTreeTo(tab, tab._tPos); + } + break; + + case 'SSTabRestoring': + this.onTabRestored(aEvent); + break; + case 'click': var isMiddleClick = ( aEvent.button == 1 || @@ -401,6 +417,7 @@ var TreeStyleTabService = { var nextFocusedTab = null; if (firstChild) { + var backupChildren = this.getTabValue(tab, this.kCHILDREN); var children = this.getChildTabsOf(tab); var self = this; var adoption = this.getPref('extensions.treestyletab.adoptChildrenToGrandParentOnRemoveTab'); @@ -421,6 +438,7 @@ var TreeStyleTabService = { if (adoption) { nextFocusedTab = firstChild; } + this.setTabValue(tab, this.kCHILDREN, backupChildren); } if (!nextFocusedTab) { @@ -445,6 +463,24 @@ var TreeStyleTabService = { b.selectedTab = nextFocusedTab; }, + onTabRestored : function(aEvent) + { + var tab = aEvent.originalTarget; + var id = this.setTabValue(tab, this.kID, this.getTabValue(tab, this.kID)); + var children = this.setTabValue(tab, this.kCHILDREN, this.getTabValue(tab, this.kCHILDREN)); + + var children = this.getChildTabsOf(tab); + for (var i = 0, maxi = children.length; i < maxi; i++) + { + this.adoptTabTo(children[i], tab); + } + + var parentTab = this.getParentTabOf(tab); + if (parentTab) { + this.adoptTabTo(tab, parentTab); + } + }, + onTabClick : function(aEvent) { if (aEvent.button != 0) return; @@ -490,6 +526,23 @@ var TreeStyleTabService = { /* Tab Utilities */ + getTabValue : function(aTab, aKey) + { + var value = null; + try { + value = this.SessionStore.getTabValue(aTab, aKey); + } + catch(e) { + } + + if (value) + aTab.setAttribute(aKey, value); + else + aTab.removeAttribute(aKey); + + return value; + }, + setTabValue : function(aTab, aKey, aValue) { if (!aValue) { @@ -501,6 +554,7 @@ var TreeStyleTabService = { } catch(e) { } + return aValue; }, deleteTabValue : function(aTab, aKey) @@ -704,6 +758,10 @@ var TreeStyleTabService = { var children = aParent.getAttribute(this.kCHILDREN); var newIndex; + if (children.indexOf(id) > -1) { + children = ('|'+children).replace('|'+id, '').replace(/^\|/); + } + var beforeTab = aInsertBefore ? aInsertBefore.getAttribute(this.kID) : null ; if (aInsertBefore && children.indexOf(beforeTab) > -1) { children = children.replace(new RegExp(beforeTab), id+'|'+beforeTab); @@ -718,7 +776,7 @@ var TreeStyleTabService = { this.setTabValue(aParent, this.kCHILDREN, children); if (newIndex > aChild._tPos) newIndex--; - b.moveTabTo(aChild, newIndex); + this.moveTabSubTreeTo(aChild, newIndex); this.updateTabsIndent([aChild]); }, @@ -761,15 +819,18 @@ var TreeStyleTabService = { moveTabSubTreeTo : function(aTab, aIndex) { - var tabs = this.getDescendantTabsOf(aTab); - var b = this.getTabBrowserFromChildren(aTab); + b.__treestyletab__isSubTreeMoving = true; + b.moveTabTo(aTab, aIndex); + var tabs = this.getDescendantTabsOf(aTab); for (var i = 0, maxi = tabs.length; i < maxi; i++) { b.moveTabTo(tabs[i], aTab._tPos+i+1); } + + b.__treestyletab__isSubTreeMoving = false; }, /* Pref Listener */