moveTabToメソッドで直接タブの位置を動かされた時に、自動的にツリーを修復するようにした
git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@1346 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
parent
2399885518
commit
9ddf18c0ae
@ -62,7 +62,7 @@
|
|||||||
<spacer/>
|
<spacer/>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<vbox pack="start">
|
<vbox pack="start" align="end">
|
||||||
<radio value="left" label="&config.tabbar.position.left;"/>
|
<radio value="left" label="&config.tabbar.position.left;"/>
|
||||||
<checkbox id="extensions.treestyletab.tabbar.invertScrollbar-check"
|
<checkbox id="extensions.treestyletab.tabbar.invertScrollbar-check"
|
||||||
preference="extensions.treestyletab.tabbar.invertScrollbar"
|
preference="extensions.treestyletab.tabbar.invertScrollbar"
|
||||||
@ -70,7 +70,7 @@
|
|||||||
disabled="true"/>
|
disabled="true"/>
|
||||||
</vbox>
|
</vbox>
|
||||||
<box style="border: ThreeDShadow 1px solid; margin: 0.3em; background: white;"/>
|
<box style="border: ThreeDShadow 1px solid; margin: 0.3em; background: white;"/>
|
||||||
<vbox pack="start">
|
<vbox pack="start" align="start">
|
||||||
<radio value="right" label="&config.tabbar.position.right;"/>
|
<radio value="right" label="&config.tabbar.position.right;"/>
|
||||||
<checkbox id="extensions.treestyletab.tabbar.invertUI-check"
|
<checkbox id="extensions.treestyletab.tabbar.invertUI-check"
|
||||||
preference="extensions.treestyletab.tabbar.invertUI"
|
preference="extensions.treestyletab.tabbar.invertUI"
|
||||||
|
@ -557,6 +557,7 @@ catch(e) {
|
|||||||
).replace(
|
).replace(
|
||||||
'this.moveTabToStart();',
|
'this.moveTabToStart();',
|
||||||
<><![CDATA[
|
<><![CDATA[
|
||||||
|
this.__treestyletab__internallyTabMoving = true;
|
||||||
var parentTab = TreeStyleTabService.getParentTab(this.mCurrentTab);
|
var parentTab = TreeStyleTabService.getParentTab(this.mCurrentTab);
|
||||||
if (parentTab) {
|
if (parentTab) {
|
||||||
this.moveTabTo(this.mCurrentTab, TreeStyleTabService.getFirstChildTab(parentTab)._tPos);
|
this.moveTabTo(this.mCurrentTab, TreeStyleTabService.getFirstChildTab(parentTab)._tPos);
|
||||||
@ -565,6 +566,7 @@ catch(e) {
|
|||||||
else {
|
else {
|
||||||
this.moveTabToStart();
|
this.moveTabToStart();
|
||||||
}
|
}
|
||||||
|
this.__treestyletab__internallyTabMoving = false;
|
||||||
]]></>
|
]]></>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -580,6 +582,7 @@ catch(e) {
|
|||||||
).replace(
|
).replace(
|
||||||
'this.moveTabToEnd();',
|
'this.moveTabToEnd();',
|
||||||
<><![CDATA[
|
<><![CDATA[
|
||||||
|
this.__treestyletab__internallyTabMoving = true;
|
||||||
var parentTab = TreeStyleTabService.getParentTab(this.mCurrentTab);
|
var parentTab = TreeStyleTabService.getParentTab(this.mCurrentTab);
|
||||||
if (parentTab) {
|
if (parentTab) {
|
||||||
this.moveTabTo(this.mCurrentTab, TreeStyleTabService.getLastChildTab(parentTab)._tPos);
|
this.moveTabTo(this.mCurrentTab, TreeStyleTabService.getLastChildTab(parentTab)._tPos);
|
||||||
@ -588,6 +591,7 @@ catch(e) {
|
|||||||
else {
|
else {
|
||||||
this.moveTabToEnd();
|
this.moveTabToEnd();
|
||||||
}
|
}
|
||||||
|
this.__treestyletab__internallyTabMoving = false;
|
||||||
]]></>
|
]]></>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -1153,18 +1157,54 @@ catch(e) {
|
|||||||
var tab = aEvent.originalTarget;
|
var tab = aEvent.originalTarget;
|
||||||
this.initTabContents(tab); // twisty vanished after the tab is moved!!
|
this.initTabContents(tab); // twisty vanished after the tab is moved!!
|
||||||
|
|
||||||
|
var rebuildTreeDone = false;
|
||||||
|
|
||||||
var b = this.getTabBrowserFromChildren(tab);
|
var b = this.getTabBrowserFromChildren(tab);
|
||||||
if (tab.getAttribute(this.kCHILDREN) && !b.__treestyletab__isSubTreeMoving) {
|
if (tab.getAttribute(this.kCHILDREN) && !b.__treestyletab__isSubTreeMoving) {
|
||||||
this.moveTabSubTreeTo(tab, tab._tPos);
|
this.moveTabSubTreeTo(tab, tab._tPos);
|
||||||
|
rebuildTreeDone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var parentTab = this.getParentTab(tab);
|
var parentTab = this.getParentTab(tab);
|
||||||
if (parentTab && !b.__treestyletab__isSubTreeChildrenMoving) {
|
if (parentTab && !b.__treestyletab__isSubTreeChildrenMoving) {
|
||||||
var children = this.getChildTabs(parentTab);
|
this.updateChildrenArray(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('|'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
onTabRestored : function(aEvent)
|
||||||
@ -1210,7 +1250,9 @@ catch(e) {
|
|||||||
if (!parent && (before = this.getTabById(before, b))) {
|
if (!parent && (before = this.getTabById(before, b))) {
|
||||||
var index = before._tPos;
|
var index = before._tPos;
|
||||||
if (index > tab._tPos) index--;
|
if (index > tab._tPos) index--;
|
||||||
|
b.__treestyletab__internallyTabMoving = true;
|
||||||
b.moveTabTo(tab, index);
|
b.moveTabTo(tab, index);
|
||||||
|
b.__treestyletab__internallyTabMoving = false;
|
||||||
}
|
}
|
||||||
this.deleteTabValue(tab, this.kINSERT_BEFORE);
|
this.deleteTabValue(tab, this.kINSERT_BEFORE);
|
||||||
|
|
||||||
@ -1299,7 +1341,9 @@ catch(e) {
|
|||||||
) {
|
) {
|
||||||
var newIndex = aInfo.insertBefore ? aInfo.insertBefore._tPos : tabs.length - 1 ;
|
var newIndex = aInfo.insertBefore ? aInfo.insertBefore._tPos : tabs.length - 1 ;
|
||||||
if (aInfo.insertBefore && newIndex > aTarget._tPos) newIndex--;
|
if (aInfo.insertBefore && newIndex > aTarget._tPos) newIndex--;
|
||||||
|
b.__treestyletab__internallyTabMoving = true;
|
||||||
b.moveTabTo(aTarget, newIndex);
|
b.moveTabTo(aTarget, newIndex);
|
||||||
|
b.__treestyletab__internallyTabMoving = false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
@ -1395,9 +1439,9 @@ catch(e) {
|
|||||||
|
|
||||||
getParentTab : function(aTab)
|
getParentTab : function(aTab)
|
||||||
{
|
{
|
||||||
var id = aTab.getAttribute(this.kID);
|
if (!aTab) return null;
|
||||||
return this.evaluateXPath(
|
return this.evaluateXPath(
|
||||||
'parent::*/child::xul:tab[contains(@'+this.kCHILDREN+', "'+id+'")]',
|
'parent::*/child::xul:tab[contains(@'+this.kCHILDREN+', "'+aTab.getAttribute(this.kID)+'")]',
|
||||||
aTab,
|
aTab,
|
||||||
XPathResult.FIRST_ORDERED_NODE_TYPE
|
XPathResult.FIRST_ORDERED_NODE_TYPE
|
||||||
).singleNodeValue;
|
).singleNodeValue;
|
||||||
@ -1405,6 +1449,8 @@ catch(e) {
|
|||||||
|
|
||||||
getNextSiblingTab : function(aTab)
|
getNextSiblingTab : function(aTab)
|
||||||
{
|
{
|
||||||
|
if (!aTab) return null;
|
||||||
|
|
||||||
var id = aTab.getAttribute(this.kID);
|
var id = aTab.getAttribute(this.kID);
|
||||||
var parentTab = this.getParentTab(aTab);
|
var parentTab = this.getParentTab(aTab);
|
||||||
|
|
||||||
@ -1432,6 +1478,8 @@ catch(e) {
|
|||||||
|
|
||||||
getPreviousSiblingTab : function(aTab)
|
getPreviousSiblingTab : function(aTab)
|
||||||
{
|
{
|
||||||
|
if (!aTab) return null;
|
||||||
|
|
||||||
var id = aTab.getAttribute(this.kID);
|
var id = aTab.getAttribute(this.kID);
|
||||||
var parentTab = this.getParentTab(aTab);
|
var parentTab = this.getParentTab(aTab);
|
||||||
|
|
||||||
@ -1459,7 +1507,9 @@ catch(e) {
|
|||||||
|
|
||||||
getChildTabs : function(aTab, aAllTabsArray)
|
getChildTabs : function(aTab, aAllTabsArray)
|
||||||
{
|
{
|
||||||
var tabs = [];
|
var tabs = [];
|
||||||
|
if (!aTab) return null;
|
||||||
|
|
||||||
var children = aTab.getAttribute(this.kCHILDREN);
|
var children = aTab.getAttribute(this.kCHILDREN);
|
||||||
if (!children) return tabs;
|
if (!children) return tabs;
|
||||||
|
|
||||||
@ -1489,6 +1539,8 @@ catch(e) {
|
|||||||
|
|
||||||
getFirstChildTab : function(aTab)
|
getFirstChildTab : function(aTab)
|
||||||
{
|
{
|
||||||
|
if (!aTab) return null;
|
||||||
|
|
||||||
var b = this.getTabBrowserFromChildren(aTab);
|
var b = this.getTabBrowserFromChildren(aTab);
|
||||||
var children = aTab.getAttribute(this.kCHILDREN);
|
var children = aTab.getAttribute(this.kCHILDREN);
|
||||||
var firstChild = null;
|
var firstChild = null;
|
||||||
@ -1505,6 +1557,8 @@ catch(e) {
|
|||||||
|
|
||||||
getLastChildTab : function(aTab)
|
getLastChildTab : function(aTab)
|
||||||
{
|
{
|
||||||
|
if (!aTab) return null;
|
||||||
|
|
||||||
var b = this.getTabBrowserFromChildren(aTab);
|
var b = this.getTabBrowserFromChildren(aTab);
|
||||||
var children = aTab.getAttribute(this.kCHILDREN);
|
var children = aTab.getAttribute(this.kCHILDREN);
|
||||||
var lastChild = null;
|
var lastChild = null;
|
||||||
@ -1988,14 +2042,18 @@ catch(e) {
|
|||||||
var b = this.getTabBrowserFromChildren(aTab);
|
var b = this.getTabBrowserFromChildren(aTab);
|
||||||
b.__treestyletab__isSubTreeMoving = true;
|
b.__treestyletab__isSubTreeMoving = true;
|
||||||
|
|
||||||
|
b.__treestyletab__internallyTabMoving = true;
|
||||||
b.moveTabTo(aTab, aIndex);
|
b.moveTabTo(aTab, aIndex);
|
||||||
|
b.__treestyletab__internallyTabMoving = false;
|
||||||
|
|
||||||
b.__treestyletab__isSubTreeChildrenMoving = true;
|
b.__treestyletab__isSubTreeChildrenMoving = true;
|
||||||
|
b.__treestyletab__internallyTabMoving = true;
|
||||||
var tabs = this.getDescendantTabs(aTab);
|
var tabs = this.getDescendantTabs(aTab);
|
||||||
for (var i = 0, maxi = tabs.length; i < maxi; i++)
|
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.moveTabTo(tabs[i], aTab._tPos+i+(aTab._tPos < tabs[i]._tPos ? 1 : 0 ));
|
||||||
}
|
}
|
||||||
|
b.__treestyletab__internallyTabMoving = false;
|
||||||
b.__treestyletab__isSubTreeChildrenMoving = false;
|
b.__treestyletab__isSubTreeChildrenMoving = false;
|
||||||
|
|
||||||
b.__treestyletab__isSubTreeMoving = false;
|
b.__treestyletab__isSubTreeMoving = false;
|
||||||
@ -2024,12 +2082,14 @@ catch(e) {
|
|||||||
else {
|
else {
|
||||||
var nextTab = this.getNextSiblingTab(parentTab);
|
var nextTab = this.getNextSiblingTab(parentTab);
|
||||||
this.partTab(b.mCurrentTab);
|
this.partTab(b.mCurrentTab);
|
||||||
|
b.__treestyletab__internallyTabMoving = true;
|
||||||
if (nextTab) {
|
if (nextTab) {
|
||||||
b.moveTabTo(b.mCurrentTab, nextTab._tPos - 1);
|
b.moveTabTo(b.mCurrentTab, nextTab._tPos - 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
b.moveTabTo(b.mCurrentTab, b.mTabContainer.lastChild._tPos);
|
b.moveTabTo(b.mCurrentTab, b.mTabContainer.lastChild._tPos);
|
||||||
}
|
}
|
||||||
|
b.__treestyletab__internallyTabMoving = false;
|
||||||
b.mCurrentTab.focus();
|
b.mCurrentTab.focus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user