ブックマークフォルダの内容をタブで開く際に、現在のタブが空でTab Mix Plusによって空のタブが使い回されると、開かれたタブのツリー構造が壊れる問題について対処した。

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@6659 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2010-05-06 09:57:51 +00:00
parent 9ff4533eb2
commit 3607ac93a0
2 changed files with 74 additions and 29 deletions

View File

@ -187,6 +187,59 @@ var TreeStyleTabBookmarksService = {
}, },
applyTreeStructureToTabs : function TSTBMService_applyTreeStructureToTabs(aTabs, aTreeStructure)
{ // based on TreeStyleTabBrowser.prototype.onTabAdded()
var b = this.getTabBrowserFromChild(aTabs[0]);
if (!b) return;
var sv = b.treeStyleTab;
aTabs = aTabs.slice(0, aTreeStructure.length);
aTreeStructure = aTreeStructure.slice(0, aTabs.length);
var parentTab = null;
aTabs.forEach(function(aTab, aIndex) {
if (sv.isCollapsed(aTab)) sv.collapseExpandTab(aTab, false, true);
sv.partTab(aTab);
var pareintIndexInTree = aTreeStructure[aIndex];
if (pareintIndexInTree < 0) { // there is no parent, so this is a new parent!
parentTab = aTab.getAttribute(sv.kID);
}
var parent = sv.getTabById(parentTab);
if (parent) {
let tabs = [parent].concat(sv.getDescendantTabs(parent));
parent = pareintIndexInTree < tabs.length ? tabs[pareintIndexInTree] : parent ;
}
if (parent) {
sv.attachTabTo(aTab, parent, {
dontExpand : true,
dontMove : true
});
}
}, sv);
},
getTabsInfo : function TSTBMService_getTabsInfo(aTabBrowser)
{
var tabs = this.getTabsArray(aTabBrowser);
return tabs.map(function(aTab) {
return aTab.getAttribute(this.kID)+'\n'+
aTab.getAttribute('busy')+'\n'+
aTab.linkedBrowser.currentURI.spec;
}, this);
},
getNewTabsFromPreviousTabsInfo : function TSTBMService_getNewTabsFromPreviousTabsInfo(aTabBrowser, aTabsInfo)
{
var tabs = this.getTabsArray(aTabBrowser);
var currentTabsInfo = this.getTabsInfo(aTabBrowser);
return tabs.filter(function(aTab, aIndex) {
return aTabsInfo.indexOf(currentTabsInfo[aIndex]) < 0;
});
},
init : function TSTBMService_init() init : function TSTBMService_init()
{ {
window.removeEventListener('load', this, false); window.removeEventListener('load', this, false);
@ -198,6 +251,9 @@ var TreeStyleTabBookmarksService = {
PlacesUIUtils._openTabset.toSource().replace( PlacesUIUtils._openTabset.toSource().replace(
/(function[^\(]*\([^\)]+)(\))/, /(function[^\(]*\([^\)]+)(\))/,
'$1, aFolderTitle$2' '$1, aFolderTitle$2'
).replace(
'{',
'{ var TSTTreeStructure = null, TSTPreviousTabs;'
).replace( ).replace(
'var urls = [];', 'var urls = [];',
'$& var ids = [];' '$& var ids = [];'
@ -245,7 +301,16 @@ var TreeStyleTabBookmarksService = {
urls.unshift(sv.getGroupTabURI(aFolderTitle)); urls.unshift(sv.getGroupTabURI(aFolderTitle));
} }
} }
sv.readyToOpenNewTabGroup(null, treeStructure);
if (sv.getTreePref('compatibility.TMP') &&
'TMP_Places' in browserWindow &&
'openGroup' in browserWindow.TMP_Places) {
TSTTreeStructure = treeStructure;
TSTPreviousTabs = browserWindow.TreeStyleTabBookmarksService.getTabsInfo(browserWindow.gBrowser);
}
else {
sv.readyToOpenNewTabGroup(null, treeStructure);
}
replaceCurrentTab = false; replaceCurrentTab = false;
} }
else { else {
@ -254,6 +319,14 @@ var TreeStyleTabBookmarksService = {
} }
$1 $1
]]> ]]>
).replace(
/(\}\)?)$/,
<![CDATA[
if (TSTTreeStructure && TSTPreviousTabs) {
let tabs = browserWindow.TreeStyleTabBookmarksService.getNewTabsFromPreviousTabsInfo(browserWindow.gBrowser, TSTPreviousTabs)
browserWindow.TreeStyleTabBookmarksService.applyTreeStructureToTabs(tabs, TSTTreeStructure);
}
$1]]>
) )
); );

View File

@ -553,34 +553,6 @@ TreeStyleTabService.overrideExtensionsOnInitAfter = function TSTService_override
) )
); );
eval('TMP_Bookmark.openGroup = '+
TMP_Bookmark.openGroup.toSource().replace(
'{',
'$& var TSTOpenGroupBookmarkBehavior = TreeStyleTabService.openGroupBookmarkBehavior();'
).replace(
'index = prevTab._tPos + 1;',
<![CDATA[
index = gBrowser.treeStyleTab.getNextSiblingTab(gBrowser.treeStyleTab.getRootTab(prevTab));
if (tabToSelect == aTab) index = gBrowser.treeStyleTab.getNextSiblingTab(index);
index = index ? index._tPos : (prevTab._tPos + 1);
]]>
).replace(
/(prevTab = aTab;)/,
<![CDATA[
$1
if (tabToSelect == aTab && TSTOpenGroupBookmarkBehavior & TreeStyleTabService.kGROUP_BOOKMARK_SUBTREE) {
TreeStyleTabService.readyToOpenChildTab(tabToSelect, true, gBrowser.treeStyleTab.getNextSiblingTab(tabToSelect));
}
]]>
).replace(
/(browser.mTabContainer.nextTab)/,
<![CDATA[
if (TSTOpenGroupBookmarkBehavior & TreeStyleTabService.kGROUP_BOOKMARK_SUBTREE)
TreeStyleTabService.stopToOpenChildTab(tabToSelect);
$1]]>
)
);
'setMultibarAttribute getMultiRowAttribute tabxTabClosed'.split(' ').forEach(function(aFunc) { 'setMultibarAttribute getMultiRowAttribute tabxTabClosed'.split(' ').forEach(function(aFunc) {
if (aFunc in window) if (aFunc in window)
eval('window.'+aFunc+' = '+ eval('window.'+aFunc+' = '+