Improved compatibility with Tab Utilities. (If TU is installed, TST failed to open trees of tabs from bookmark folders.)

This commit is contained in:
Piro / SHIMODA Hiroshi 2011-10-30 01:45:02 +09:00
parent 401b83b92f
commit 2e28ffe4c2

View File

@ -211,90 +211,109 @@ var TreeStyleTabBookmarksService = {
catch(e) { // Firefox 3.6 or older catch(e) { // Firefox 3.6 or older
ns = window; ns = window;
} }
var sv = this;
with (ns) { with (ns) {
eval('PlacesUIUtils._openTabset = '+ let (method = (sv.getTreePref('compatibility.TabUtilities') && PlacesUIUtils.TU__openTabset) ?
PlacesUIUtils._openTabset.toSource().replace( 'TU__openTabset' :
/(function[^\(]*\([^\)]+)(\))/, '_openTabset') {
'$1, aFolderTitle$2' eval('PlacesUIUtils.'+method+' = '+
).replace( PlacesUIUtils[method].toSource().replace(
'{', /(function[^\(]*\([^\)]+)(\))/,
'{ var TSTTreeStructure = null, TSTPreviousTabs, TSTOpenGroupBookmarkBehavior;' '$1, aFolderTitle$2'
).replace( ).replace(
'var urls = [];', '{',
'$& var ids = [];' '{ var TSTTreeStructure = null, TSTPreviousTabs, TSTOpenGroupBookmarkBehavior;'
).replace( ).replace(
'urls.push(item.uri);', 'var urls = [];',
'$& ids.push(item.id);' '$& var ids = [];'
).replace( ).replace(
/(browserWindow\.(?:getBrowser\(\)|gBrowser)\.loadTabs\([^;]+\);)/, 'urls.push(item.uri);',
<![CDATA[ '$& ids.push(item.id);'
var TSTResult = browserWindow.TreeStyleTabBookmarksService.handleTabsOpenProcess(where, aEvent, browserWindow, ids, urls, replaceCurrentTab, aFolderTitle); ).replace(
TSTTreeStructure = TSTResult.treeStructure; /(browserWindow\.(?:getBrowser\(\)|gBrowser)\.loadTabs\([^;]+\);)/,
TSTPreviousTabs = TSTResult.previousTabs; <![CDATA[
TSTOpenGroupBookmarkBehavior = TSTResult.behavior; var TSTResult = browserWindow.TreeStyleTabBookmarksService.handleTabsOpenProcess(where, aEvent, browserWindow, ids, urls, replaceCurrentTab, aFolderTitle);
replaceCurrentTab = TSTResult.replaceCurrentTab; TSTTreeStructure = TSTResult.treeStructure;
$1 TSTPreviousTabs = TSTResult.previousTabs;
]]> TSTOpenGroupBookmarkBehavior = TSTResult.behavior;
).replace( replaceCurrentTab = TSTResult.replaceCurrentTab;
/(\}\)?)$/, $1
<![CDATA[ ]]>
if (TSTTreeStructure && TSTPreviousTabs) { ).replace(
let tabs = browserWindow.TreeStyleTabBookmarksService.getNewTabsFromPreviousTabsInfo(browserWindow.gBrowser, TSTPreviousTabs) /(\}\)?)$/,
browserWindow.TreeStyleTabService.applyTreeStructureToTabs(tabs, TSTTreeStructure, TSTOpenGroupBookmarkBehavior & browserWindow.TreeStyleTabBookmarksService.kGROUP_BOOKMARK_EXPAND_ALL_TREE); <![CDATA[
} if (TSTTreeStructure && TSTPreviousTabs) {
$1]]> let tabs = browserWindow.TreeStyleTabBookmarksService.getNewTabsFromPreviousTabsInfo(browserWindow.gBrowser, TSTPreviousTabs)
) browserWindow.TreeStyleTabService.applyTreeStructureToTabs(tabs, TSTTreeStructure, TSTOpenGroupBookmarkBehavior & browserWindow.TreeStyleTabBookmarksService.kGROUP_BOOKMARK_EXPAND_ALL_TREE);
);
eval('PlacesUIUtils.openContainerNodeInTabs = '+
PlacesUIUtils.openContainerNodeInTabs.toSource().replace(
/(this\._openTabset\([^\)]+)(\))/,
<![CDATA[
let (w = '_getTopBrowserWin' in this ?
this._getTopBrowserWin() :
'_getCurrentActiveWin' in this ?
this._getCurrentActiveWin() :
window) {
let nodes = w.TreeStyleTabBookmarksService.getItemIdsForContainerNode(aNode);
for (let i in nodes) {
urlsToOpen[i].id = nodes[i];
} }
} $1]]>
$1, aNode.title$2 )
]]> );
) if (sv.getTreePref('compatibility.TabUtilities') && method.indexOf('TU_') > -1)
); window[method] = PlacesUIUtils[method];
}
eval('PlacesUIUtils.openURINodesInTabs = '+ let (method = (sv.getTreePref('compatibility.TabUtilities') && PlacesUIUtils.TU_openContainerNodeInTabs) ?
PlacesUIUtils.openURINodesInTabs.toSource().replace( 'TU_openContainerNodeInTabs' :
'{', 'openContainerNodeInTabs') {
<![CDATA[{ eval('PlacesUIUtils.'+method+' = '+
var TSTBS; PlacesUIUtils[method].toSource().replace(
let (w = '_getTopBrowserWin' in this ? /(this\._openTabset\([^\)]+)(\))/,
this._getTopBrowserWin() : <![CDATA[
'_getCurrentActiveWin' in this ? let (w = '_getTopBrowserWin' in this ?
this._getCurrentActiveWin() : this._getTopBrowserWin() :
window) { '_getCurrentActiveWin' in this ?
TSTBS = w.TreeStyleTabBookmarksService; this._getCurrentActiveWin() :
} window) {
]]>.toString() let nodes = w.TreeStyleTabBookmarksService.getItemIdsForContainerNode(aNode);
).replace( for (let i in nodes) {
'uri: aNodes[i].uri,', urlsToOpen[i].id = nodes[i];
'id: aNodes[i].itemId, $&' }
).replace( }
/(this\._openTabset\([^\)]+)(\))/, $1, aNode.title$2
<![CDATA[$1, ]]>
TSTBS.treeBundle )
.getFormattedString( );
PlacesUtils.nodeIsBookmark(aNodes[0]) ? if (sv.getTreePref('compatibility.TabUtilities') && method.indexOf('TU_') > -1)
'openSelectedPlaces.bookmarks' : window[method] = PlacesUIUtils[method];
'openSelectedPlaces.history', }
[aNodes[0].title, aNodes.length]
) let (method = (sv.getTreePref('compatibility.TabUtilities') && PlacesUIUtils.TU_openURINodesInTabs) ?
$2]]> 'TU_openURINodesInTabs' :
) 'openURINodesInTabs') {
); eval('PlacesUIUtils.'+method+' = '+
PlacesUIUtils[method].toSource().replace(
'{',
<![CDATA[{
var TSTBS;
let (w = '_getTopBrowserWin' in this ?
this._getTopBrowserWin() :
'_getCurrentActiveWin' in this ?
this._getCurrentActiveWin() :
window) {
TSTBS = w.TreeStyleTabBookmarksService;
}
]]>.toString()
).replace(
'uri: aNodes[i].uri,',
'id: aNodes[i].itemId, $&'
).replace(
/(this\._openTabset\([^\)]+)(\))/,
<![CDATA[$1,
TSTBS.treeBundle
.getFormattedString(
PlacesUtils.nodeIsBookmark(aNodes[0]) ?
'openSelectedPlaces.bookmarks' :
'openSelectedPlaces.history',
[aNodes[0].title, aNodes.length]
)
$2]]>
)
);
if (sv.getTreePref('compatibility.TabUtilities') && method.indexOf('TU_') > -1)
window[method] = PlacesUIUtils[method];
}
PlacesUIUtils.__treestyletab__done = true; PlacesUIUtils.__treestyletab__done = true;