* ツリーを閉じる前後に 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:
parent
ebdea3391b
commit
e18a267860
@ -1282,16 +1282,60 @@ catch(e) {
|
||||
if (!this.warnAboutClosingTabs(tabs.length))
|
||||
return;
|
||||
|
||||
this.markAsClosedSet(tabs);
|
||||
|
||||
var b = this.getTabBrowserFromChild(tabs[0]);
|
||||
this.splitTabsToSubtrees(tabs).forEach(function(aTabs) {
|
||||
if (!this.fireTabSubtreeClosingEvent(aTabs[0], aTabs))
|
||||
return;
|
||||
this.markAsClosedSet(aTabs);
|
||||
var b = this.getTabBrowserFromChild(aTabs[0]);
|
||||
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
|
||||
|
||||
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)
|
||||
{
|
||||
if (!this.shouldCloseTabSubtreeOf(aTab))
|
||||
|
@ -1550,11 +1550,11 @@ TreeStyleTabBrowser.prototype = {
|
||||
closeParentBehavior == this.CLOSE_PARENT_BEHAVIOR_CLOSE ||
|
||||
subtreeCollapsed
|
||||
) {
|
||||
let tabs = this.getDescendantTabs(tab);
|
||||
if (this.fireTabSubtreeClosingEvent(tab, tabs)) {
|
||||
if (subtreeCollapsed)
|
||||
this.stopRendering();
|
||||
|
||||
let tabs = this.getDescendantTabs(tab);
|
||||
|
||||
this.markAsClosedSet([tab].concat(tabs));
|
||||
|
||||
tabs.reverse().forEach(function(aTab) {
|
||||
@ -1569,9 +1569,12 @@ TreeStyleTabBrowser.prototype = {
|
||||
b.addTab('about:blank');
|
||||
}
|
||||
|
||||
this.fireTabSubtreeClosedEvent(b, tab, tabs);
|
||||
|
||||
if (subtreeCollapsed)
|
||||
this.startRendering();
|
||||
}
|
||||
}
|
||||
|
||||
var firstChild = this.getFirstChildTab(tab);
|
||||
var parentTab = this.getParentTab(tab);
|
||||
@ -1746,20 +1749,9 @@ TreeStyleTabBrowser.prototype = {
|
||||
|
||||
onTabsRemoved : function TSTBrowser_onTabsRemoved(aTabs)
|
||||
{
|
||||
var group = [];
|
||||
this.cleanUpTabsArray(aTabs)
|
||||
.forEach(function(aTab) {
|
||||
var parent = this.getParentTab(aTab);
|
||||
if (group.indexOf(parent) < 0) {
|
||||
this.markAsClosedSet(group);
|
||||
group = [aTab];
|
||||
}
|
||||
else {
|
||||
group.push(aTab);
|
||||
}
|
||||
this.splitTabsToSubtrees(aTabs).forEach(function(aTabs) {
|
||||
this.markAsClosedSet(aTabs);
|
||||
}, this);
|
||||
|
||||
this.markAsClosedSet(group);
|
||||
},
|
||||
|
||||
onTabMove : function TSTBrowser_onTabMove(aEvent)
|
||||
@ -3074,11 +3066,7 @@ TreeStyleTabBrowser.prototype = {
|
||||
aChild == aParent ||
|
||||
(currentParent = this.getParentTab(aChild)) == aParent
|
||||
) {
|
||||
/* PUBLIC API */
|
||||
let event = document.createEvent('Events');
|
||||
event.initEvent('TreeStyleTabAttached', true, false);
|
||||
event.parentTab = aParent;
|
||||
aChild.dispatchEvent(event);
|
||||
this.fireAttachedEvent(aChild, aParent);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -3180,6 +3168,10 @@ TreeStyleTabBrowser.prototype = {
|
||||
this.checkTabsIndentOverflow();
|
||||
}
|
||||
|
||||
this.fireAttachedEvent(aChild, aParent);
|
||||
},
|
||||
fireAttachedEvent : function TSTBrowser_fireAttachedEvent(aChild, aParent)
|
||||
{
|
||||
/* PUBLIC API */
|
||||
var event = document.createEvent('Events');
|
||||
event.initEvent('TreeStyleTabAttached', true, false);
|
||||
@ -3224,6 +3216,7 @@ TreeStyleTabBrowser.prototype = {
|
||||
/* PUBLIC API */
|
||||
var event = document.createEvent('Events');
|
||||
event.initEvent('TreeStyleTabParted', true, false);
|
||||
event.parentTab = parentTab;
|
||||
aChild.dispatchEvent(event);
|
||||
|
||||
if (this.isGroupTab(parentTab) && !this.hasChildTabs(parentTab)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user