now we can set maximum level of nesting

This commit is contained in:
SHIMODA Hiroshi 2010-11-29 17:24:45 +09:00
parent ee0ad57175
commit 89732dc67b
4 changed files with 85 additions and 10 deletions

View File

@ -13,7 +13,7 @@
display: none;
}
.tabbrowser-tabs[treestyletab-allow-subtree-collapse="true"]
.tabbrowser-tab[treestyletab-children]
.tabbrowser-tab[treestyletab-children][treestyletab-allow-subtree-collapse="true"]
.treestyletab-twisty {
display: -moz-box;
}
@ -23,7 +23,7 @@
display: none;
}
.tabbrowser-tabs[treestyletab-allow-subtree-collapse="true"]
.tabbrowser-tab[treestyletab-children][treestyletab-subtree-collapsed="true"]
.tabbrowser-tab[treestyletab-children][treestyletab-subtree-collapsed="true"][treestyletab-allow-subtree-collapse="true"]
.treestyletab-counter-container {
display: -moz-box;
}

View File

@ -31,6 +31,9 @@ TreeStyleTabBrowser.prototype = {
invertedPositionProp : 'screenX',
invertedSizeProp : 'width',
maxTreeLevel : -1,
maxTreeLevelPhisical : false,
enableSubtreeIndent : true,
allowSubtreeCollapseExpand : true,
hideAlltabsButton : true,
@ -400,7 +403,7 @@ TreeStyleTabBrowser.prototype = {
<![CDATA[$&
var treeStyleTab = TreeStyleTabService.getTabBrowserFromChild(this).treeStyleTab;
treeStyleTab._focusChangedByShortcut = TreeStyleTabService.accelKeyPressed;
if (treeStyleTab.canCollapseSubtree() &&
if (treeStyleTab.canCollapseSubtree(this.selectedItem) &&
treeStyleTab.getTreePref('focusMode') == treeStyleTab.kFOCUS_VISIBLE) {
(function(aDir, aWrap, aSelf) {
var nextTab = (aDir < 0) ? treeStyleTab.getPreviousVisibleTab(aSelf.selectedItem) : treeStyleTab.getNextVisibleTab(aSelf.selectedItem) ;
@ -705,6 +708,7 @@ TreeStyleTabBrowser.prototype = {
}
}
this.onPrefChange('extensions.treestyletab.maxTreeLevel');
this.onPrefChange('extensions.treestyletab.tabbar.style');
this.onPrefChange('extensions.treestyletab.twisty.style');
this.onPrefChange('extensions.treestyletab.showBorderForFirstTab');
@ -1841,6 +1845,20 @@ TreeStyleTabBrowser.prototype = {
this.checkTabsIndentOverflow();
break;
case 'extensions.treestyletab.maxTreeLevel':
this.maxTreeLevel = value;
if (this.maxTreeLevelPhisical)
this.promoteTooDeepLevelTabs();
else
this.updateAllTabsIndent();
break;
case 'extensions.treestyletab.maxTreeLevel.phisical':
this.maxTreeLevelPhisical = value;
if (this.maxTreeLevelPhisical)
this.promoteTooDeepLevelTabs();
break;
case 'browser.tabs.animate':
case 'extensions.treestyletab.animation.enabled':
this.setTabbrowserAttribute(this.kANIMATION_ENABLED,
@ -3051,7 +3069,7 @@ TreeStyleTabBrowser.prototype = {
return;
if (this.isEventFiredOnTwisty(aEvent)) {
if (this.hasChildTabs(aTab) && this.canCollapseSubtree()) {
if (this.hasChildTabs(aTab) && this.canCollapseSubtree(aTab)) {
this.collapseExpandSubtree(aTab, aTab.getAttribute(this.kSUBTREE_COLLAPSED) != 'true');
aEvent.preventDefault();
aEvent.stopPropagation();
@ -3893,6 +3911,17 @@ TreeStyleTabBrowser.prototype = {
attachTabTo : function TSTBrowser_attachTabTo(aChild, aParent, aInfo) /* PUBLIC API */
{
aInfo = aInfo || {};
if (aParent && this.maxTreeLevelPhisical && this.maxTreeLevel > -1) {
let level = parseInt(aParent.getAttribute(this.kNEST) || 0) + 1;
while (aParent && level > this.maxTreeLevel)
{
level--;
aParent = this.getParentTab(aParent);
}
}
var currentParent;
if (
!aChild ||
@ -4013,6 +4042,8 @@ TreeStyleTabBrowser.prototype = {
this.checkTabsIndentOverflow();
}
this.promoteTooDeepLevelTabs(aChild);
this.fireAttachedEvent(aChild, aParent);
},
fireAttachedEvent : function TSTBrowser_fireAttachedEvent(aChild, aParent)
@ -4157,7 +4188,7 @@ TreeStyleTabBrowser.prototype = {
var b = this.mTabBrowser;
var margin = this.indent < 0 ? this.baseIndent : this.indent ;
var indent = margin * aLevel;
var indent = (this.maxTreeLevel < 0 ? aLevel : Math.min(aLevel, this.maxTreeLevel) ) * margin;
var multirow = this.isMultiRow();
if (multirow) {
@ -4169,6 +4200,14 @@ TreeStyleTabBrowser.prototype = {
if (!aTab.parentNode) return; // ignore removed tabs
this.updateTabIndent(aTab, indent, aJustNow);
aTab.setAttribute(this.kNEST, aLevel);
if (this.maxTreeLevel < 0 || this.maxTreeLevel > aLevel) {
aTab.setAttribute(this.kALLOW_COLLAPSE, true);
this.collapseExpandSubtree(aTab, this.isSubtreeCollapsed(aTab));
}
else {
this.collapseExpandSubtree(aTab, false);
aTab.removeAttribute(this.kALLOW_COLLAPSE);
}
this.updateTabsIndent(this.getChildTabs(aTab), aLevel+1, aJustNow);
}, this);
},
@ -4320,7 +4359,10 @@ TreeStyleTabBrowser.prototype = {
var self = this;
tabs.sort(function(aA, aB) { return Number(aA.getAttribute(self.kNEST)) - Number(aB.getAttribute(self.kNEST)); });
var nest = tabs[tabs.length-1].getAttribute(this.kNEST);
if (!nest) return;
if (this.maxTreeLevel > -1)
nest = Math.min(nest, this.maxTreeLevel);
if (!nest)
return;
var oldIndent = this.indent;
var indent = (oldIndent < 0 ? this.baseIndent : oldIndent ) * nest;
@ -4362,6 +4404,32 @@ TreeStyleTabBrowser.prototype = {
if (parent && !aDontUpdateAncestor)
this.updateTabsCount(parent);
},
promoteTooDeepLevelTabs : function TSTBrowser_promoteTooDeepLevelTabs(aParent)
{
if (this.maxTreeLevel < 0 || !this.maxTreeLevelPhisical)
return;
var tabs = aParent ? this.getDescendantTabs(aParent) : this.getAllTabsArray(this.mTabBrowser) ;
tabs.forEach(function(aTab) {
var level = parseInt(aTab.getAttribute(this.kNEST) || 0);
if (level <= this.maxTreeLevel)
return;
var parent = this.getParentTab(aTab);
var newParent = this.getParentTab(parent);
if (this.maxTreeLevel == 0 || !newParent) {
this.partTab(aTab);
}
else {
let nextSibling = this.getNextTab(aTab);
this.attachTabTo(aTab, newParent, {
dontMove : true,
insertBefore : nextSibling
});
}
}, this);
},
/* move */
@ -4539,7 +4607,7 @@ TreeStyleTabBrowser.prototype = {
aJustNow ||
this.collapseDuration < 1 ||
// !this.isVertical ||
!this.canCollapseSubtree()
!this.canCollapseSubtree(this.getParentTab(aTab))
) {
if (aCollapsed)
aTab.setAttribute(this.kCOLLAPSED_DONE, true);
@ -4646,7 +4714,7 @@ TreeStyleTabBrowser.prototype = {
{
if (!aTab ||
this.doingCollapseExpand ||
!this.canCollapseSubtree())
!this.canCollapseSubtree(aTab))
return;
var b = this.mTabBrowser;

View File

@ -56,6 +56,8 @@ pref("extensions.treestyletab.autoExpand.enabled", true);
pref("extensions.treestyletab.autoExpand.delay", 500);
pref("extensions.treestyletab.autoExpand.intelligently", true);
pref("extensions.treestyletab.autoExpand.collapseFinally", false);
pref("extensions.treestyletab.maxTreeLevel", -1);
pref("extensions.treestyletab.maxTreeLevel.phisical", false);
pref("extensions.treestyletab.indent", 12);
pref("extensions.treestyletab.indent.property", "margin");
// pref("extensions.treestyletab.indent.property.top", "");

View File

@ -1338,9 +1338,14 @@ var TreeStyleTabUtils = {
);
},
canCollapseSubtree : function TSTUtils_canCollapseSubtree(aTabBrowser) /* PUBLIC API */
canCollapseSubtree : function TSTUtils_canCollapseSubtree(aTabOrTabBrowser) /* PUBLIC API */
{
var b = this.getTabBrowserFromChild(aTabBrowser) || this.browser;
if (aTabOrTabBrowser &&
aTabOrTabBrowser.localName == 'tab' &&
aTabOrTabBrowser.getAttribute(this.kALLOW_COLLAPSE) != 'true')
return false;
var b = this.getTabBrowserFromChild(aTabOrTabBrowser) || this.browser;
return b.getAttribute(this.kALLOW_COLLAPSE) == 'true';
},