子孫を持たないタブに新しい子タブを追加した時、自動で他のサブツリーを閉じるようにした

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@1228 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2007-10-18 18:20:54 +00:00
parent 435e437371
commit 9b461385d3
4 changed files with 68 additions and 54 deletions

View File

@ -14,9 +14,9 @@
<preference id="extensions.treestyletab.autoCollapseExpandSubTreeOnSelect" <preference id="extensions.treestyletab.autoCollapseExpandSubTreeOnSelect"
name="extensions.treestyletab.autoCollapseExpandSubTreeOnSelect" name="extensions.treestyletab.autoCollapseExpandSubTreeOnSelect"
type="bool"/> type="bool"/>
<preference id="extensions.treestyletab.autoExpandSubTreeOnAppendChild" <!--preference id="extensions.treestyletab.autoExpandSubTreeOnAppendChild"
name="extensions.treestyletab.autoExpandSubTreeOnAppendChild" name="extensions.treestyletab.autoExpandSubTreeOnAppendChild"
type="bool"/> type="bool"/-->
<preference id="extensions.treestyletab.adoptChildrenToGrandParentOnRemoveTab" <preference id="extensions.treestyletab.adoptChildrenToGrandParentOnRemoveTab"
name="extensions.treestyletab.adoptChildrenToGrandParentOnRemoveTab" name="extensions.treestyletab.adoptChildrenToGrandParentOnRemoveTab"
type="bool" type="bool"
@ -32,9 +32,9 @@
<checkbox id="extensions.treestyletab.autoCollapseExpandSubTreeOnSelect-check" <checkbox id="extensions.treestyletab.autoCollapseExpandSubTreeOnSelect-check"
preference="extensions.treestyletab.autoCollapseExpandSubTreeOnSelect" preference="extensions.treestyletab.autoCollapseExpandSubTreeOnSelect"
label="&config.autoCollapseExpandSubTreeOnSelect;"/> label="&config.autoCollapseExpandSubTreeOnSelect;"/>
<checkbox id="extensions.treestyletab.autoExpandSubTreeOnAppendChild-check" <!--checkbox id="extensions.treestyletab.autoExpandSubTreeOnAppendChild-check"
preference="extensions.treestyletab.autoExpandSubTreeOnAppendChild" preference="extensions.treestyletab.autoExpandSubTreeOnAppendChild"
label="&config.autoExpandSubTreeOnAppendChild;"/> label="&config.autoExpandSubTreeOnAppendChild;"/-->
<checkbox id="extensions.treestyletab.adoptChildrenToGrandParentOnRemoveTab-check" <checkbox id="extensions.treestyletab.adoptChildrenToGrandParentOnRemoveTab-check"
preference="extensions.treestyletab.adoptChildrenToGrandParentOnRemoveTab" preference="extensions.treestyletab.adoptChildrenToGrandParentOnRemoveTab"
label="&config.adoptChildrenToGrandParentOnRemoveTab;"/> label="&config.adoptChildrenToGrandParentOnRemoveTab;"/>

View File

@ -634,42 +634,7 @@ var TreeStyleTabService = {
else if (tab.getAttribute(this.kCHILDREN) && else if (tab.getAttribute(this.kCHILDREN) &&
(tab.getAttribute(this.kSUBTREE_COLLAPSED) == 'true') && (tab.getAttribute(this.kSUBTREE_COLLAPSED) == 'true') &&
this.getPref('extensions.treestyletab.autoCollapseExpandSubTreeOnSelect')) { this.getPref('extensions.treestyletab.autoCollapseExpandSubTreeOnSelect')) {
var expandedParentTabs = [ this.collapseExpandTreesIntelligentlyFor(tab);
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);
} }
}, },
@ -901,8 +866,16 @@ var TreeStyleTabService = {
if (newIndex > aChild._tPos) newIndex--; if (newIndex > aChild._tPos) newIndex--;
this.moveTabSubTreeTo(aChild, newIndex); this.moveTabSubTreeTo(aChild, newIndex);
if (aParent.getAttribute(this.kSUBTREE_COLLAPSED) == 'true') { if (
if (this.getPref('extensions.treestyletab.autoExpandSubTreeOnAppendChild')) { (
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; var p = aParent;
do { do {
this.collapseExpandTabSubTree(p, false); this.collapseExpandTabSubTree(p, false);
@ -1009,6 +982,47 @@ var TreeStyleTabService = {
} }
}, },
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 */ /* Pref Listener */
domain : 'extensions.treestyletab', domain : 'extensions.treestyletab',

View File

@ -3,7 +3,7 @@
<!ENTITY config.tabs.general "General"> <!ENTITY config.tabs.general "General">
<!ENTITY config.autoCollapseExpandSubTreeOnSelect "Collapse distractive subtrees automatically, when a tab is focused"> <!ENTITY config.autoCollapseExpandSubTreeOnSelect "Collapse distractive subtrees automatically, when a tab is opened or focused">
<!ENTITY config.autoExpandSubTreeOnAppendChild "Expand subtree automatically, when tabs are inserted into the subtree"> <!ENTITY config.autoExpandSubTreeOnAppendChild "Expand subtree automatically, when tabs are inserted into the subtree">

View File

@ -3,7 +3,7 @@
<!ENTITY config.tabs.general "全般"> <!ENTITY config.tabs.general "全般">
<!ENTITY config.autoCollapseExpandSubTreeOnSelect "タブを切り替える時、関係ないサブツリーを自動的に折り畳む"> <!ENTITY config.autoCollapseExpandSubTreeOnSelect "タブを開く時やタブを切り替える時、関係ないサブツリーを自動的に折り畳む">
<!ENTITY config.autoExpandSubTreeOnAppendChild "折り畳まれたサブツリー内に子孫のタブが追加された時、サブツリーを自動的に展開する"> <!ENTITY config.autoExpandSubTreeOnAppendChild "折り畳まれたサブツリー内に子孫のタブが追加された時、サブツリーを自動的に展開する">