From e18a267860a26685759fdc8740a871551d892549 Mon Sep 17 00:00:00 2001 From: piro Date: Sat, 26 Dec 2009 04:49:58 +0000 Subject: [PATCH] =?UTF-8?q?*=20=E3=83=84=E3=83=AA=E3=83=BC=E3=82=92?= =?UTF-8?q?=E9=96=89=E3=81=98=E3=82=8B=E5=89=8D=E5=BE=8C=E3=81=AB=20TreeSt?= =?UTF-8?q?yleTabSubtreeClosing=20/=20TreeStyleTabSubtreeClosed=20?= =?UTF-8?q?=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88=E3=82=92=E7=99=BA=E8=A1=8C?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= =?UTF-8?q?=20*=20newAPI:=20splitTabsToSubtrees()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5649 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/treestyletab.js | 58 ++++++++++++++++--- content/treestyletab/treestyletabbrowser.js | 63 +++++++++------------ 2 files changed, 79 insertions(+), 42 deletions(-) diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index bdaf2ee4..a7b2f042 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -1282,16 +1282,60 @@ catch(e) { if (!this.warnAboutClosingTabs(tabs.length)) return; - this.markAsClosedSet(tabs); - - var b = this.getTabBrowserFromChild(tabs[0]); - for (var i = tabs.length-1; i > -1; i--) - { - b.removeTab(tabs[i]); - } + 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(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)) diff --git a/content/treestyletab/treestyletabbrowser.js b/content/treestyletab/treestyletabbrowser.js index dbb018b6..ae1da0c1 100644 --- a/content/treestyletab/treestyletabbrowser.js +++ b/content/treestyletab/treestyletabbrowser.js @@ -1550,27 +1550,30 @@ TreeStyleTabBrowser.prototype = { closeParentBehavior == this.CLOSE_PARENT_BEHAVIOR_CLOSE || subtreeCollapsed ) { - if (subtreeCollapsed) - this.stopRendering(); - 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) { - b.removeTab(aTab); - }, this); + tabs.reverse().forEach(function(aTab) { + b.removeTab(aTab); + }, this); - // for last tab closing, we have to open new tab manually if running on Firefox 3.0. - if ( - !('_beginRemoveTab' in b) && !('_endRemoveTab' in b) && // Firefox 3.0.x - this.getTabs(b).snapshotLength == 1 // last tab - ) { - b.addTab('about:blank'); + // for last tab closing, we have to open new tab manually if running on Firefox 3.0. + if ( + !('_beginRemoveTab' in b) && !('_endRemoveTab' in b) && // Firefox 3.0.x + this.getTabs(b).snapshotLength == 1 // last tab + ) { + b.addTab('about:blank'); + } + + this.fireTabSubtreeClosedEvent(b, tab, tabs); + + if (subtreeCollapsed) + this.startRendering(); } - - if (subtreeCollapsed) - this.startRendering(); } var firstChild = this.getFirstChildTab(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); - - this.markAsClosedSet(group); + this.splitTabsToSubtrees(aTabs).forEach(function(aTabs) { + this.markAsClosedSet(aTabs); + }, this); }, 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)) {