サブツリーのウィンドウ外へのドラッグによるサブツリーの別ウィンドウへの切り離しをサポート

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@3412 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2008-12-01 08:30:36 +00:00
parent e10c5bca75
commit cc35a7bf1f
2 changed files with 115 additions and 47 deletions

View File

@ -862,6 +862,22 @@ var TreeStyleTabService = {
window.addEventListener('SSTabRestoring', this, true);
if ('swapBrowsersAndCloseOther' in document.getElementById('content')) {
var source = window.BrowserStartup.toSource();
if (source.indexOf('!MultipleTabService.tearOffSelectedTabsFromRemote()') > -1) {
eval('window.BrowserStartup = '+source.replace(
'!MultipleTabService.tearOffSelectedTabsFromRemote()',
'!TreeStyleTabService.tearOffSubTreeFromRemote() && $&'
));
}
else {
eval('window.BrowserStartup = '+source.replace(
'gBrowser.swapBrowsersAndCloseOther(gBrowser.selectedTab, uriToLoad);',
'if (!TreeStyleTabService.tearOffSubTreeFromRemote()) { $& }'
));
}
}
this.overrideExtensionsPreInit(); // hacks.js
},
preInitialized : false,
@ -1916,6 +1932,36 @@ catch(e) {
},
_collapseExpandPostProcess : [],
tearOffSubTreeFromRemote : function()
{
var remoteTab = window.arguments[0];
var remoteWindow = remoteTab.ownerDocument.defaultView;
var remoteService = remoteWindow.TreeStyleTabService;
var remoteMultipleTabService = remoteWindow.MultipleTabService;
if (remoteService.hasChildTabs(remoteTab) ||
remoteMultipleTabService.isSelected(remoteTab)) {
var remoteBrowser = remoteService.getTabBrowserFromChild(remoteTab);
var actionInfo = {
action : this.kACTIONS_FOR_DESTINATION | this.kACTION_IMPORT
};
var tabsInfo = remoteBrowser.treeStyleTab.getDraggedTabsInfoFromOneTab(actionInfo, remoteTab);
if (tabsInfo.draggedTabs.length == remoteBrowser.mTabContainer.childNodes.length) {
window.close();
}
else {
window.setTimeout(function() {
var blankTab = gBrowser.selectedTab;
gBrowser.treeStyleTab.performDrop(actionInfo, remoteTab);
window.setTimeout(function() {
gBrowser.removeTab(blankTab);
}, 0);
}, 0);
}
return true;
}
return false;
},
/* Pref Listener */
domains : [

View File

@ -2147,45 +2147,17 @@ TreeStyleTabBrowser.prototype = {
performDrop : function(aInfo, aDraggedTab)
{
aDraggedTab = this.getTabFromChild(aDraggedTab);
var tabsInfo = this.getDraggedTabsInfoFromOneTab(aInfo, aDraggedTab);
aDraggedTab = tabsInfo.draggedTab;
var draggedTabs = tabsInfo.draggedTabs;
var draggedRoots = tabsInfo.draggedRoots;
var targetBrowser = this.mTabBrowser;
var tabs = targetBrowser.mTabContainer.childNodes;
var draggedTabs = [aDraggedTab];
var draggedRoots = [aDraggedTab];
var sourceWindow = aDraggedTab.ownerDocument.defaultView;
var sourceBrowser = this.getTabBrowserFromChild(aDraggedTab);
var isSelectionMove = (
'MultipleTabService' in sourceWindow &&
sourceWindow.MultipleTabService.isSelected(aDraggedTab) &&
MultipleTabService.allowMoveMultipleTabs
);
if (isSelectionMove) {
draggedTabs = sourceWindow.MultipleTabService.getSelectedTabs(sourceBrowser);
if (!(aInfo.action & this.kACTIONS_FOR_DESTINATION)) {
draggedRoots = [];
draggedTabs.forEach(function(aTab) {
var parent = aTab,
current;
do {
current = parent;
parent = sourceBrowser.treeStyleTab.getParentTab(parent)
if (parent && sourceWindow.MultipleTabService.isSelected(parent)) continue;
draggedRoots.push(current);
return;
}
while (parent);
}, this);
}
}
else if (aInfo.action & this.kACTIONS_FOR_DESTINATION) {
draggedTabs = draggedTabs.concat(sourceBrowser.treeStyleTab.getDescendantTabs(aDraggedTab));
}
if (aInfo.action & this.kACTIONS_FOR_SOURCE) {
if (aInfo.action & this.kACTION_PART) {
this.partTabsOnDrop(draggedRoots);
@ -2228,7 +2200,7 @@ TreeStyleTabBrowser.prototype = {
var tab = aTab;
if (aInfo.action & this.kACTIONS_FOR_DESTINATION) {
var parent = sourceBrowser.treeStyleTab.getParentTab(aTab);
if (isSelectionMove)
if (tabsInfo.isSelectionMove)
sourceWindow.MultipleTabService.setSelection(aTab, false);
if (aInfo.action & this.kACTION_IMPORT &&
'swapBrowsersAndCloseOther' in targetBrowser) {
@ -2246,7 +2218,7 @@ TreeStyleTabBrowser.prototype = {
oldTabs.push(aTab);
}
newTabs.push(tab);
if (isSelectionMove)
if (tabsInfo.isSelectionMove)
MultipleTabService.setSelection(tab, true);
if (!parent || draggedTabs.indexOf(parent) < 0)
newRoots.push(tab);
@ -2286,6 +2258,56 @@ TreeStyleTabBrowser.prototype = {
return true;
},
getDraggedTabsInfoFromOneTab : function(aInfo, aTab)
{
aTab = this.getTabFromChild(aTab);
var targetBrowser = this.mTabBrowser;
var tabs = targetBrowser.mTabContainer.childNodes;
var draggedTabs = [aTab];
var draggedRoots = [aTab];
var sourceWindow = aTab.ownerDocument.defaultView;
var sourceBrowser = this.getTabBrowserFromChild(aTab);
var isSelectionMove = (
'MultipleTabService' in sourceWindow &&
sourceWindow.MultipleTabService.isSelected(aTab) &&
MultipleTabService.allowMoveMultipleTabs
);
if (isSelectionMove) {
draggedTabs = sourceWindow.MultipleTabService.getSelectedTabs(sourceBrowser);
if (!(aInfo.action & this.kACTIONS_FOR_DESTINATION)) {
draggedRoots = [];
draggedTabs.forEach(function(aTab) {
var parent = aTab,
current;
do {
current = parent;
parent = sourceBrowser.treeStyleTab.getParentTab(parent)
if (parent && sourceWindow.MultipleTabService.isSelected(parent)) continue;
draggedRoots.push(current);
return;
}
while (parent);
}, this);
}
}
else if (aInfo.action & this.kACTIONS_FOR_DESTINATION) {
draggedTabs = draggedTabs.concat(sourceBrowser.treeStyleTab.getDescendantTabs(aTab));
}
return {
draggedTab : aTab,
draggedTabs : draggedTabs,
draggedRoots : draggedRoots,
isSelectionMove : isSelectionMove
};
},
attachTabsOnDrop : function(aTabs, aParent)
{
this.mTabBrowser.movingSelectedTabs = true; // Multiple Tab Handler