ドラッグ&ドロップによるツリーの移動をブラッシュアップ

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@3191 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2008-10-17 17:16:16 +00:00
parent 870d11e0cb
commit 54c96e04cb
3 changed files with 139 additions and 136 deletions

View File

@ -403,13 +403,13 @@ TreeStyleTabService.overrideExtensionsOnInitAfter = function() {
).replace(
/(var newIndex =)/,
<><![CDATA[
if (isTabReorder && TSTTabBrowser.treeStyleTab.processDropAction(dropActionInfo, aDragSession.sourceNode))
if (isTabReorder && TSTTabBrowser.treeStyleTab.performDrop(dropActionInfo, aDragSession.sourceNode))
return;
]]></>
).replace(
/(aTab = gBrowser.addTab\(url\));/,
<><![CDATA[
TSTTabBrowser.treeStyleTab.processDropAction(dropActionInfo, $1);
TSTTabBrowser.treeStyleTab.performDrop(dropActionInfo, $1);
return;
]]></>
).replace(
@ -421,7 +421,7 @@ TreeStyleTabService.overrideExtensionsOnInitAfter = function() {
TreeStyleTabService.getTreePref('loadDroppedLinkToNewChildTab') ||
dropActionInfo.position != TreeStyleTabService.kDROP_ON
) {
TSTTabBrowser.treeStyleTab.processDropAction(dropActionInfo, TSTTabBrowser.loadOneTab(url, null, null, null, bgLoad, false));
TSTTabBrowser.treeStyleTab.performDrop(dropActionInfo, TSTTabBrowser.loadOneTab(url, null, null, null, bgLoad, false));
return;
}
]]></>

View File

@ -42,11 +42,13 @@ var TreeStyleTabService = {
kDROP_AFTER : 1,
kACTION_MOVE : 1,
kACTION_ATTACH : 2,
kACTION_PART : 4,
kACTION_DUPLICATE : 8,
kACTION_MOVE_FROM_OTHER_WINDOW : 16,
kACTION_MAY_DUPLICATE : 24,
kACTION_STAY : 2,
kACTION_DUPLICATE : 4,
kACTION_IMPORT : 8,
kACTION_ATTACH : 1024,
kACTION_PART : 2048,
kACTIONS_FOR_SOURCE : 1 | 2,
kACTIONS_FOR_DESTINATION : 4 | 8,
kTABBAR_TOP : 1,
kTABBAR_BOTTOM : 2,
@ -1038,13 +1040,13 @@ catch(e) {
).replace( // Firefox 2
/(if \(aDragSession[^\)]+\) \{)/,
<><![CDATA[$1
if (TSTTabBrowser.treeStyleTab.processDropAction(dropActionInfo, TST_DRAGSESSION.sourceNode))
if (TSTTabBrowser.treeStyleTab.performDrop(dropActionInfo, TST_DRAGSESSION.sourceNode))
return;
]]></>
).replace( // Firefox 3.0.x, 3.1 or later
/(if \((accelKeyPressed|isCopy|dropEffect == "copy")\) {)/,
<><![CDATA[
if (TSTTabBrowser.treeStyleTab.processDropAction(dropActionInfo, draggedTab))
if (TSTTabBrowser.treeStyleTab.performDrop(dropActionInfo, draggedTab))
return;
$1]]></>
).replace( // Firefox 3, duplication of tab
@ -1056,13 +1058,13 @@ catch(e) {
).replace( // Firefox 3, dragging tab from another window
'else if (draggedTab) {',
<><![CDATA[$&
if (TSTTabBrowser.treeStyleTab.processDropAction(dropActionInfo, draggedTab))
if (TSTTabBrowser.treeStyleTab.performDrop(dropActionInfo, draggedTab))
return;
]]></>
).replace(
/(this.loadOneTab\([^;]+\));/,
<><![CDATA[
TSTTabBrowser.treeStyleTab.processDropAction(dropActionInfo, $1);
TSTTabBrowser.treeStyleTab.performDrop(dropActionInfo, $1);
return;
]]></>
).replace(
@ -1077,7 +1079,7 @@ catch(e) {
TreeStyleTabService.getTreePref('loadDroppedLinkToNewChildTab') ||
dropActionInfo.position != TreeStyleTabService.kDROP_ON
) {
TSTTabBrowser.treeStyleTab.processDropAction(dropActionInfo, TSTTabBrowser.loadOneTab(getShortcutOrURI(url), null, null, null, bgLoad, false));
TSTTabBrowser.treeStyleTab.performDrop(dropActionInfo, TSTTabBrowser.loadOneTab(getShortcutOrURI(url), null, null, null, bgLoad, false));
return;
}
]]></>

View File

@ -1974,26 +1974,31 @@ TreeStyleTabBrowser.prototype = {
if (tab) {
var isCopy = this.isAccelKeyPressed(aEvent);
if (isCopy && 'duplicateTab' in this.mTabBrowser) {
info.action = this.kACTION_DUPLICATE;
info.action |= this.kACTION_DUPLICATE;
}
if (
!isCopy &&
tab.ownerDocument != document &&
this.getTabBrowserFromChild(tab) != this.mTabBrowser &&
(
('duplicateTab' in this.mTabBrowser) ||
('swapBrowsersAndCloseOther' in this.mTabBrowser)
)
) {
info.action |= this.kACTION_MOVE_FROM_OTHER_WINDOW;
info.action |= this.kACTION_IMPORT;
}
if (info.action & this.kACTIONS_FOR_DESTINATION) {
if (info.action & this.kACTION_MOVE) info.action ^= this.kACTION_MOVE;
if (info.action & this.kACTION_STAY) info.action ^= this.kACTION_STAY;
}
if (info.action & this.kACTION_ATTACH) {
var orig = tab;
if (orig == info.parent) {
if (info.parent == tab) {
info.canDrop = false;
}
else {
var tab = info.target;
var orig = tab;
tab = info.target;
while (tab = this.getParentTab(tab))
{
if (tab != orig) continue;
@ -2023,7 +2028,7 @@ TreeStyleTabBrowser.prototype = {
var isTabMoveFromOtherWindow = aSourceTab && aSourceTab.ownerDocument != document;
if (tab.localName != 'tab') {
var action = isTabMoveFromOtherWindow ? 0 : (this.kACTION_MOVE | this.kACTION_PART) ;
var action = isTabMoveFromOtherWindow ? this.kACTION_STAY : (this.kACTION_MOVE | this.kACTION_PART) ;
if (aEvent[this.positionProp] < tabs[0].boxObject[this.positionProp]) {
info.target = info.parent = info.insertBefore = tabs[0];
info.position = isInverted ? this.kDROP_AFTER : this.kDROP_BEFORE ;
@ -2059,7 +2064,7 @@ TreeStyleTabBrowser.prototype = {
switch (info.position)
{
case this.kDROP_ON:
info.action = this.kACTION_ATTACH;
info.action = this.kACTION_STAY | this.kACTION_ATTACH;
info.parent = tab;
info.insertBefore = this.getNextVisibleTab(tab);
break;
@ -2122,7 +2127,7 @@ TreeStyleTabBrowser.prototype = {
return info;
},
processDropAction : function(aInfo, aDraggedTab)
performDrop : function(aInfo, aDraggedTab)
{
aDraggedTab = this.getTabFromChild(aDraggedTab);
@ -2135,15 +2140,15 @@ TreeStyleTabBrowser.prototype = {
var sourceWindow = aDraggedTab.ownerDocument.defaultView;
var sourceBrowser = this.getTabBrowserFromChild(aDraggedTab);
var moveSelection = (
var isSelectionMove = (
'MultipleTabService' in sourceWindow &&
sourceWindow.MultipleTabService.isSelected(aDraggedTab) &&
MultipleTabService.allowMoveMultipleTabs
);
if (moveSelection) {
if (isSelectionMove) {
draggedTabs = sourceWindow.MultipleTabService.getSelectedTabs(sourceBrowser);
if (!(aInfo.action & this.kACTION_MAY_DUPLICATE)) {
if (!(aInfo.action & this.kACTIONS_FOR_DESTINATION)) {
draggedRoots = [];
draggedTabs.forEach(function(aTab) {
var parent = aTab,
@ -2159,47 +2164,39 @@ TreeStyleTabBrowser.prototype = {
}, this);
}
}
else if (sourceWindow != window || aInfo.action & this.kACTION_DUPLICATE) {
else if (aInfo.action & this.kACTIONS_FOR_DESTINATION) {
draggedTabs = draggedTabs.concat(sourceBrowser.treeStyleTab.getDescendantTabs(aDraggedTab));
}
if (aDraggedTab && aInfo.action & this.kACTION_PART) {
if (!(aInfo.action & this.kACTION_MAY_DUPLICATE))
if (aInfo.action & this.kACTIONS_FOR_SOURCE) {
if (aInfo.action & this.kACTION_PART) {
this.partTabsOnDrop(draggedRoots);
}
else if (aInfo.action & this.kACTION_ATTACH) {
if (!(aInfo.action & this.kACTION_MAY_DUPLICATE))
this.attachTabsOnDrop(draggedRoots, aInfo.parent);
}
else if (
(draggedTabs.length > 1) &&
(
(aInfo.action & this.kACTION_MOVE_FROM_OTHER_WINDOW) ||
(aInfo.action & this.kACTION_MAY_DUPLICATE)
)
) {
}
else {
return false;
}
var newSelection = [];
if (
(
aInfo.action & this.kACTION_MOVE ||
aInfo.action & this.kACTION_MAY_DUPLICATE
) &&
(
!aInfo.insertBefore ||
sourceBrowser.treeStyleTab.getNextVisibleTab(draggedTabs[0]) != aInfo.insertBefore
)
if ( // if this move will cause no change...
sourceBrowser == targetBrowser &&
sourceBrowser.treeStyleTab.getNextVisibleTab(draggedTabs[draggedTabs.length-1]) == aInfo.insertBefore
) {
targetBrowser.duplicatingSelectedTabs = (aInfo.action & this.kACTION_MAY_DUPLICATE) ? true : false ; // Multiple Tab Handler
targetBrowser.movingSelectedTabs = true; // Multiple Tab Handler
// then, do nothing
return true;
}
}
// prevent Multiple Tab Handler feature
targetBrowser.duplicatingSelectedTabs = true;
targetBrowser.movingSelectedTabs = true;
var newRoots = [];
var shouldClose = (
aInfo.action & this.kACTION_MOVE_FROM_OTHER_WINDOW &&
aInfo.action & this.kACTION_IMPORT &&
sourceBrowser.mTabContainer.childNodes.length == draggedTabs.length
);
var oldTabs = [];
@ -2211,11 +2208,11 @@ TreeStyleTabBrowser.prototype = {
draggedTabs.forEach(function(aTab) {
var tab = aTab;
if (aInfo.action & this.kACTION_MAY_DUPLICATE) {
if (aInfo.action & this.kACTIONS_FOR_DESTINATION) {
var parent = sourceBrowser.treeStyleTab.getParentTab(aTab);
if (moveSelection)
if (isSelectionMove)
sourceWindow.MultipleTabService.setSelection(aTab, false);
if (aInfo.action & this.kACTION_MOVE_FROM_OTHER_WINDOW &&
if (aInfo.action & this.kACTION_IMPORT &&
'swapBrowsersAndCloseOther' in targetBrowser) {
tab = targetBrowser.addTab();
tab.linkedBrowser.stop();
@ -2227,11 +2224,11 @@ TreeStyleTabBrowser.prototype = {
tab = targetBrowser.duplicateTab(aTab);
this.deleteTabValue(tab, this.kCHILDREN);
this.deleteTabValue(tab, this.kPARENT);
if (aInfo.action & this.kACTION_MOVE_FROM_OTHER_WINDOW)
if (aInfo.action & this.kACTION_IMPORT)
oldTabs.push(aTab);
}
newTabs.push(tab);
if (moveSelection)
if (isSelectionMove)
MultipleTabService.setSelection(tab, true);
if (!parent || draggedTabs.indexOf(parent) < 0)
newRoots.push(tab);
@ -2247,28 +2244,30 @@ TreeStyleTabBrowser.prototype = {
}, this);
// close imported tabs from the source browser
oldTabs.forEach(function(aTab) {
sourceBrowser.removeTab(aTab);
});
if (shouldClose) this.closeOwner(sourceBrowser);
// restore tree structure for newly opened tabs
newTabs.forEach(function(aTab, aIndex) {
var index = treeStructure[aIndex];
if (index < 0) return;
targetBrowser.treeStyleTab.attachTabTo(aTab, newTabs[index]);
});
if (aInfo.action & this.kACTION_MAY_DUPLICATE &&
if (aInfo.action & this.kACTIONS_FOR_DESTINATION &&
aInfo.action & this.kACTION_ATTACH)
this.attachTabsOnDrop(newRoots, aInfo.parent);
if (shouldClose) this.closeOwner(sourceBrowser);
targetBrowser.movingSelectedTabs = false; // Multiple Tab Handler
targetBrowser.duplicatingSelectedTabs = false; // Multiple Tab Handler
}
// Multiple Tab Handler
targetBrowser.movingSelectedTabs = false;
targetBrowser.duplicatingSelectedTabs = false;
return true;
},
attachTabsOnDrop : function(aTabs, aParent)
{
this.mTabBrowser.movingSelectedTabs = true; // Multiple Tab Handler
@ -2281,6 +2280,7 @@ TreeStyleTabBrowser.prototype = {
}, this);
this.mTabBrowser.movingSelectedTabs = false; // Multiple Tab Handler
},
partTabsOnDrop : function(aTabs)
{
this.mTabBrowser.movingSelectedTabs = true; // Multiple Tab Handler
@ -2290,6 +2290,7 @@ TreeStyleTabBrowser.prototype = {
}, this);
this.mTabBrowser.movingSelectedTabs = false; // Multiple Tab Handler
},
closeOwner : function(aTabOwner)
{
var w = aTabOwner.ownerDocument.defaultView;