* ツリーを閉じる前後に 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))
|
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;
|
||||||
for (var i = tabs.length-1; i > -1; i--)
|
this.markAsClosedSet(aTabs);
|
||||||
{
|
var b = this.getTabBrowserFromChild(aTabs[0]);
|
||||||
b.removeTab(tabs[i]);
|
for (var i = tabs.length-1; i > -1; 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))
|
||||||
|
@ -1550,27 +1550,30 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
closeParentBehavior == this.CLOSE_PARENT_BEHAVIOR_CLOSE ||
|
closeParentBehavior == this.CLOSE_PARENT_BEHAVIOR_CLOSE ||
|
||||||
subtreeCollapsed
|
subtreeCollapsed
|
||||||
) {
|
) {
|
||||||
if (subtreeCollapsed)
|
|
||||||
this.stopRendering();
|
|
||||||
|
|
||||||
let tabs = this.getDescendantTabs(tab);
|
let tabs = this.getDescendantTabs(tab);
|
||||||
|
if (this.fireTabSubtreeClosingEvent(tab, tabs)) {
|
||||||
|
if (subtreeCollapsed)
|
||||||
|
this.stopRendering();
|
||||||
|
|
||||||
this.markAsClosedSet([tab].concat(tabs));
|
this.markAsClosedSet([tab].concat(tabs));
|
||||||
|
|
||||||
tabs.reverse().forEach(function(aTab) {
|
tabs.reverse().forEach(function(aTab) {
|
||||||
b.removeTab(aTab);
|
b.removeTab(aTab);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
// for last tab closing, we have to open new tab manually if running on Firefox 3.0.
|
// for last tab closing, we have to open new tab manually if running on Firefox 3.0.
|
||||||
if (
|
if (
|
||||||
!('_beginRemoveTab' in b) && !('_endRemoveTab' in b) && // Firefox 3.0.x
|
!('_beginRemoveTab' in b) && !('_endRemoveTab' in b) && // Firefox 3.0.x
|
||||||
this.getTabs(b).snapshotLength == 1 // last tab
|
this.getTabs(b).snapshotLength == 1 // last tab
|
||||||
) {
|
) {
|
||||||
b.addTab('about:blank');
|
b.addTab('about:blank');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.fireTabSubtreeClosedEvent(b, tab, tabs);
|
||||||
|
|
||||||
|
if (subtreeCollapsed)
|
||||||
|
this.startRendering();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subtreeCollapsed)
|
|
||||||
this.startRendering();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var firstChild = this.getFirstChildTab(tab);
|
var firstChild = this.getFirstChildTab(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) {
|
}, this);
|
||||||
var parent = this.getParentTab(aTab);
|
|
||||||
if (group.indexOf(parent) < 0) {
|
|
||||||
this.markAsClosedSet(group);
|
|
||||||
group = [aTab];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
group.push(aTab);
|
|
||||||
}
|
|
||||||
}, 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)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user