* ツリーを閉じる前後に TreeStyleTabSubtreeClosing / TreeStyleTabSubtreeClosed イベントを発行するようにした

* newAPI: splitTabsToSubtrees()

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5649 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2009-12-26 04:49:58 +00:00
parent ebdea3391b
commit e18a267860
2 changed files with 79 additions and 42 deletions

View File

@ -1282,16 +1282,60 @@ catch(e) {
if (!this.warnAboutClosingTabs(tabs.length)) if (!this.warnAboutClosingTabs(tabs.length))
return; return;
this.markAsClosedSet(tabs); this.splitTabsToSubtrees(tabs).forEach(function(aTabs) {
if (!this.fireTabSubtreeClosingEvent(aTabs[0], aTabs))
var b = this.getTabBrowserFromChild(tabs[0]); return;
this.markAsClosedSet(aTabs);
var b = this.getTabBrowserFromChild(aTabs[0]);
for (var i = tabs.length-1; i > -1; i--) for (var i = tabs.length-1; i > -1; i--)
{ {
b.removeTab(tabs[i]); b.removeTab(aTabs[i]);
} }
this.fireTabSubtreeClosedEvent(b, aTabs[0], aTabs)
}, this);
}, },
removeTabSubTree : function() { return this.removeTabSubtree.apply(this, arguments); }, // obsolete, for backward compatibility removeTabSubTree : function() { return this.removeTabSubtree.apply(this, arguments); }, // obsolete, for backward compatibility
splitTabsToSubtrees : function TSTService_splitTabsToSubtrees(aTabs) /* PUBLIC API */
{
var groups = [];
var group = [];
this.cleanUpTabsArray(aTabs)
.forEach(function(aTab) {
var parent = this.getParentTab(aTab);
if (group.indexOf(parent) < 0) {
groups.push(group);
group = [aTab];
}
else {
group.push(aTab);
}
}, this);
groups.push(group);
return groups;
},
fireTabSubtreeClosingEvent : function TSTService_fireTabSubtreeClosingEvent(aParentTab, aClosedTabs)
{
/* PUBLIC API */
var event = document.createEvent('Events');
event.initEvent('TreeStyleTabSubtreeClosing', true, true);
event.parent = aParentTab;
event.tabs = aClosedTabs;
this.getTabBrowserFromChild(aParentTab).dispatchEvent(event);
return !event.getPreventDefault();
},
fireTabSubtreeClosedEvent : function TSTService_fireTabSubtreeClosedEvent(aTabBrowser, aParentTab, aClosedTabs)
{
/* PUBLIC API */
var event = document.createEvent('Events');
event.initEvent('TreeStyleTabSubtreeClosed', true, false);
event.parent = aParentTab;
event.tabs = aClosedTabs.filter(function(aTab) { return !aTab.parentNode; });
aTabBrowser.dispatchEvent(event);
},
warnAboutClosingTabSubtreeOf : function TSTService_warnAboutClosingTabSubtreeOf(aTab) warnAboutClosingTabSubtreeOf : function TSTService_warnAboutClosingTabSubtreeOf(aTab)
{ {
if (!this.shouldCloseTabSubtreeOf(aTab)) if (!this.shouldCloseTabSubtreeOf(aTab))

View File

@ -1550,11 +1550,11 @@ TreeStyleTabBrowser.prototype = {
closeParentBehavior == this.CLOSE_PARENT_BEHAVIOR_CLOSE || closeParentBehavior == this.CLOSE_PARENT_BEHAVIOR_CLOSE ||
subtreeCollapsed subtreeCollapsed
) { ) {
let tabs = this.getDescendantTabs(tab);
if (this.fireTabSubtreeClosingEvent(tab, tabs)) {
if (subtreeCollapsed) if (subtreeCollapsed)
this.stopRendering(); this.stopRendering();
let tabs = this.getDescendantTabs(tab);
this.markAsClosedSet([tab].concat(tabs)); this.markAsClosedSet([tab].concat(tabs));
tabs.reverse().forEach(function(aTab) { tabs.reverse().forEach(function(aTab) {
@ -1569,9 +1569,12 @@ TreeStyleTabBrowser.prototype = {
b.addTab('about:blank'); b.addTab('about:blank');
} }
this.fireTabSubtreeClosedEvent(b, tab, tabs);
if (subtreeCollapsed) if (subtreeCollapsed)
this.startRendering(); this.startRendering();
} }
}
var firstChild = this.getFirstChildTab(tab); var firstChild = this.getFirstChildTab(tab);
var parentTab = this.getParentTab(tab); var parentTab = this.getParentTab(tab);
@ -1746,20 +1749,9 @@ TreeStyleTabBrowser.prototype = {
onTabsRemoved : function TSTBrowser_onTabsRemoved(aTabs) onTabsRemoved : function TSTBrowser_onTabsRemoved(aTabs)
{ {
var group = []; this.splitTabsToSubtrees(aTabs).forEach(function(aTabs) {
this.cleanUpTabsArray(aTabs) this.markAsClosedSet(aTabs);
.forEach(function(aTab) {
var parent = this.getParentTab(aTab);
if (group.indexOf(parent) < 0) {
this.markAsClosedSet(group);
group = [aTab];
}
else {
group.push(aTab);
}
}, this); }, this);
this.markAsClosedSet(group);
}, },
onTabMove : function TSTBrowser_onTabMove(aEvent) onTabMove : function TSTBrowser_onTabMove(aEvent)
@ -3074,11 +3066,7 @@ TreeStyleTabBrowser.prototype = {
aChild == aParent || aChild == aParent ||
(currentParent = this.getParentTab(aChild)) == aParent (currentParent = this.getParentTab(aChild)) == aParent
) { ) {
/* PUBLIC API */ this.fireAttachedEvent(aChild, aParent);
let event = document.createEvent('Events');
event.initEvent('TreeStyleTabAttached', true, false);
event.parentTab = aParent;
aChild.dispatchEvent(event);
return; return;
} }
@ -3180,6 +3168,10 @@ TreeStyleTabBrowser.prototype = {
this.checkTabsIndentOverflow(); this.checkTabsIndentOverflow();
} }
this.fireAttachedEvent(aChild, aParent);
},
fireAttachedEvent : function TSTBrowser_fireAttachedEvent(aChild, aParent)
{
/* PUBLIC API */ /* PUBLIC API */
var event = document.createEvent('Events'); var event = document.createEvent('Events');
event.initEvent('TreeStyleTabAttached', true, false); event.initEvent('TreeStyleTabAttached', true, false);
@ -3224,6 +3216,7 @@ TreeStyleTabBrowser.prototype = {
/* PUBLIC API */ /* PUBLIC API */
var event = document.createEvent('Events'); var event = document.createEvent('Events');
event.initEvent('TreeStyleTabParted', true, false); event.initEvent('TreeStyleTabParted', true, false);
event.parentTab = parentTab;
aChild.dispatchEvent(event); aChild.dispatchEvent(event);
if (this.isGroupTab(parentTab) && !this.hasChildTabs(parentTab)) { if (this.isGroupTab(parentTab) && !this.hasChildTabs(parentTab)) {