ツリーをまとめてブックマークした場合に、ツリー構造をアノテーションとして保持するようにした
git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@4826 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
parent
c3faed24ba
commit
e80d307031
@ -6,9 +6,24 @@ window.addEventListener('load', function() {
|
|||||||
/(function[^\(]*\([^\)]+)(\))/,
|
/(function[^\(]*\([^\)]+)(\))/,
|
||||||
'$1, aFolderTitle$2'
|
'$1, aFolderTitle$2'
|
||||||
).replace(
|
).replace(
|
||||||
'browserWindow.getBrowser().loadTabs(',
|
'var urls = [];',
|
||||||
|
'$& var ids = [];'
|
||||||
|
).replace(
|
||||||
|
'urls.push(item.uri);',
|
||||||
|
'$& ids.push(item.id);'
|
||||||
|
).replace(
|
||||||
|
/(browserWindow\.getBrowser\(\)\.loadTabs\([^;]+\);)/,
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
var openGroupBookmarkBehavior = TreeStyleTabService.openGroupBookmarkBehavior();
|
var openGroupBookmarkBehavior = TreeStyleTabService.openGroupBookmarkBehavior();
|
||||||
|
var treeStructure = ids.map(function(aId) {
|
||||||
|
let annotations = PlacesUtils.getAnnotationsForItem(aId);
|
||||||
|
for (let i in annotations)
|
||||||
|
{
|
||||||
|
if (annotations[i].name != TreeStyleTabService.kPARENT) continue;
|
||||||
|
return ids.indexOf(annotations[i].value);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
});
|
||||||
if (
|
if (
|
||||||
where.indexOf('tab') == 0 ||
|
where.indexOf('tab') == 0 ||
|
||||||
aEvent.target.id == 'placesContext_openContainer:tabs' ||
|
aEvent.target.id == 'placesContext_openContainer:tabs' ||
|
||||||
@ -16,23 +31,41 @@ window.addEventListener('load', function() {
|
|||||||
aEvent.target.getAttribute('openInTabs') == 'true'
|
aEvent.target.getAttribute('openInTabs') == 'true'
|
||||||
) {
|
) {
|
||||||
if (openGroupBookmarkBehavior & TreeStyleTabService.kGROUP_BOOKMARK_SUBTREE) {
|
if (openGroupBookmarkBehavior & TreeStyleTabService.kGROUP_BOOKMARK_SUBTREE) {
|
||||||
TreeStyleTabService.readyToOpenNewTabGroup();
|
if (
|
||||||
if (openGroupBookmarkBehavior & TreeStyleTabService.kGROUP_BOOKMARK_USE_DUMMY)
|
openGroupBookmarkBehavior & TreeStyleTabService.kGROUP_BOOKMARK_USE_DUMMY &&
|
||||||
|
treeStructure.filter(function(aParent) { return aParent == -1; }).length > 1
|
||||||
|
) {
|
||||||
|
treeStructure.unshift(-1);
|
||||||
urls.unshift(TreeStyleTabService.getGroupTabURI(aFolderTitle));
|
urls.unshift(TreeStyleTabService.getGroupTabURI(aFolderTitle));
|
||||||
|
}
|
||||||
|
TreeStyleTabService.readyToOpenNewTabGroup(null, treeStructure);
|
||||||
replaceCurrentTab = false;
|
replaceCurrentTab = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
replaceCurrentTab = openGroupBookmarkBehavior & TreeStyleTabService.kGROUP_BOOKMARK_REPLACE ? true : false ;
|
replaceCurrentTab = openGroupBookmarkBehavior & TreeStyleTabService.kGROUP_BOOKMARK_REPLACE ? true : false ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$&]]>
|
$1
|
||||||
|
]]>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
eval('PlacesUIUtils.openContainerNodeInTabs = '+
|
eval('PlacesUIUtils.openContainerNodeInTabs = '+
|
||||||
PlacesUIUtils.openContainerNodeInTabs.toSource().replace(
|
PlacesUIUtils.openContainerNodeInTabs.toSource().replace(
|
||||||
/(this\._openTabset\([^\)]+)(\))/,
|
/(this\._openTabset\([^\)]+)(\))/,
|
||||||
'$1, aNode.title$2'
|
<![CDATA[
|
||||||
|
TreeStyleTabService.getItemIdsForContainerNode(aNode).forEach(function(aId, aIndex) {
|
||||||
|
urlsToOpen[aIndex].id = aId;
|
||||||
|
});
|
||||||
|
$1, aNode.title$2
|
||||||
|
]]>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
eval('PlacesUIUtils.openURINodesInTabs = '+
|
||||||
|
PlacesUIUtils.openURINodesInTabs.toSource().replace(
|
||||||
|
'uri: aNodes[i].uri,',
|
||||||
|
'id: aNodes[i].itemId, $&'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -177,6 +177,16 @@ var TreeStyleTabService = {
|
|||||||
},
|
},
|
||||||
_WindowMediator : null,
|
_WindowMediator : null,
|
||||||
|
|
||||||
|
get BookmarksService() {
|
||||||
|
if (!this._BookmarksService) {
|
||||||
|
this._BookmarksService = Components
|
||||||
|
.classes['@mozilla.org/browser/nav-bookmarks-service;1']
|
||||||
|
.getService(Components.interfaces.nsINavBookmarksService);
|
||||||
|
}
|
||||||
|
return this._BookmarksService;
|
||||||
|
},
|
||||||
|
_BookmarksService : null,
|
||||||
|
|
||||||
get EffectiveTLD()
|
get EffectiveTLD()
|
||||||
{
|
{
|
||||||
if (!('_EffectiveTLD' in this)) {
|
if (!('_EffectiveTLD' in this)) {
|
||||||
@ -264,7 +274,7 @@ var TreeStyleTabService = {
|
|||||||
ownerBrowser.treeStyleTab.insertBefore = refId;
|
ownerBrowser.treeStyleTab.insertBefore = refId;
|
||||||
},
|
},
|
||||||
|
|
||||||
readyToOpenNewTabGroup : function(aFrameOrTabBrowser) /* PUBLIC API */
|
readyToOpenNewTabGroup : function(aFrameOrTabBrowser, aTreeStructure) /* PUBLIC API */
|
||||||
{
|
{
|
||||||
if (!this.getTreePref('autoAttachNewTabsAsChildren')) return;
|
if (!this.getTreePref('autoAttachNewTabsAsChildren')) return;
|
||||||
|
|
||||||
@ -277,6 +287,7 @@ var TreeStyleTabService = {
|
|||||||
ownerBrowser.treeStyleTab.readyToAttachNewTabGroup = true;
|
ownerBrowser.treeStyleTab.readyToAttachNewTabGroup = true;
|
||||||
ownerBrowser.treeStyleTab.readyToAttachMultiple = true;
|
ownerBrowser.treeStyleTab.readyToAttachMultiple = true;
|
||||||
ownerBrowser.treeStyleTab.multipleCount = 0;
|
ownerBrowser.treeStyleTab.multipleCount = 0;
|
||||||
|
ownerBrowser.treeStyleTab.treeStructure = aTreeStructure;
|
||||||
},
|
},
|
||||||
|
|
||||||
stopToOpenChildTab : function(aFrameOrTabBrowser) /* PUBLIC API */
|
stopToOpenChildTab : function(aFrameOrTabBrowser) /* PUBLIC API */
|
||||||
@ -291,6 +302,7 @@ var TreeStyleTabService = {
|
|||||||
ownerBrowser.treeStyleTab.multipleCount = 0;
|
ownerBrowser.treeStyleTab.multipleCount = 0;
|
||||||
ownerBrowser.treeStyleTab.parentTab = null;
|
ownerBrowser.treeStyleTab.parentTab = null;
|
||||||
ownerBrowser.treeStyleTab.insertBefore = null;
|
ownerBrowser.treeStyleTab.insertBefore = null;
|
||||||
|
ownerBrowser.treeStyleTab.treeStructure = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
checkToOpenChildTab : function(aFrameOrTabBrowser) /* PUBLIC API */
|
checkToOpenChildTab : function(aFrameOrTabBrowser) /* PUBLIC API */
|
||||||
@ -485,6 +497,41 @@ var TreeStyleTabService = {
|
|||||||
aNewPosition = aNewPosition.toLowerCase();
|
aNewPosition = aNewPosition.toLowerCase();
|
||||||
this.setTreePref('tabbar.position', aNewPosition);
|
this.setTreePref('tabbar.position', aNewPosition);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
beginAddBookmarksFromTabs : function(aTabs) /* PUBLIC API */
|
||||||
|
{
|
||||||
|
this._addingBookmarks = [];
|
||||||
|
this._addingBookmarkTreeStructure = aTabs.map(function(aTab) {
|
||||||
|
var parent = this.getParentTab(aTab);
|
||||||
|
return aTabs.indexOf(parent);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
this.BookmarksService.addObserver(this, false);
|
||||||
|
},
|
||||||
|
endAddBookmarksFromTabs : function() /* PUBLIC API */
|
||||||
|
{
|
||||||
|
this.BookmarksService.removeObserver(this);
|
||||||
|
|
||||||
|
// this is adding bookmark folder from tabs, so ignroe the first item!
|
||||||
|
if (
|
||||||
|
this._addingBookmarks.length == this._addingBookmarkTreeStructure.length+1 &&
|
||||||
|
this.BookmarksService.getItemType(this._addingBookmarks[0].id) == this.BookmarksService.TYPE_FOLDER
|
||||||
|
)
|
||||||
|
this._addingBookmarks.shift();
|
||||||
|
|
||||||
|
if (this._addingBookmarks.length == this._addingBookmarkTreeStructure.length) {
|
||||||
|
this._addingBookmarks.forEach(function(aItem, aIndex) {
|
||||||
|
let index = this._addingBookmarkTreeStructure[aIndex];
|
||||||
|
PlacesUtils.setAnnotationsForItem(aItem.id, [{
|
||||||
|
name : this.kPARENT,
|
||||||
|
value : (index > -1 ? this._addingBookmarks[index].id : -1 ),
|
||||||
|
expires : PlacesUtils.annotations.EXPIRE_NEVER
|
||||||
|
}]);
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
|
this._addingBookmarks = [];
|
||||||
|
this._addingBookmarkTreeStructure = [];
|
||||||
|
},
|
||||||
|
|
||||||
/* backward compatibility */
|
/* backward compatibility */
|
||||||
getTempTreeStyleTab : function(aTabBrowser)
|
getTempTreeStyleTab : function(aTabBrowser)
|
||||||
@ -2364,7 +2411,13 @@ catch(e) {
|
|||||||
bookmarkedTabs = bookmarkedTabs.concat(b.treeStyleTab.getDescendantTabs(aTab));
|
bookmarkedTabs = bookmarkedTabs.concat(b.treeStyleTab.getDescendantTabs(aTab));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
window['piro.sakura.ne.jp'].bookmarkMultipleTabs.addBookmarkFor(bookmarkedTabs, folderName);
|
this.beginAddBookmarksFromTabs(bookmarkedTabs);
|
||||||
|
try {
|
||||||
|
window['piro.sakura.ne.jp'].bookmarkMultipleTabs.addBookmarkFor(bookmarkedTabs, folderName);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
}
|
||||||
|
this.endAddBookmarksFromTabs();
|
||||||
},
|
},
|
||||||
|
|
||||||
openSelectionLinks : function(aFrame)
|
openSelectionLinks : function(aFrame)
|
||||||
@ -2537,6 +2590,47 @@ catch(e) {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/* bookmarks and tabs */
|
||||||
|
|
||||||
|
// based on PlacesUtils.getURLsForContainerNode()
|
||||||
|
getItemIdsForContainerNode: function(aNode)
|
||||||
|
{
|
||||||
|
var ids = [];
|
||||||
|
if (!PlacesUtils.nodeIsContainer(aNode)) return ids;
|
||||||
|
|
||||||
|
var root = PlacesUtils.getContainerNodeWithOptions(aNode, false, true);
|
||||||
|
var oldViewer = root.parentResult.viewer;
|
||||||
|
var wasOpen = root.containerOpen;
|
||||||
|
if (!wasOpen) {
|
||||||
|
root.parentResult.viewer = null;
|
||||||
|
root.containerOpen = true;
|
||||||
|
}
|
||||||
|
for (let i = 0, maxi = root.childCount; i < maxi; ++i)
|
||||||
|
{
|
||||||
|
let child = root.getChild(i);
|
||||||
|
if (PlacesUtils.nodeIsURI(child)) ids.push(child.itemId || -1);
|
||||||
|
}
|
||||||
|
if (!wasOpen) {
|
||||||
|
root.containerOpen = false;
|
||||||
|
root.parentResult.viewer = oldViewer;
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
},
|
||||||
|
|
||||||
|
// observer for nsINavBookmarksService
|
||||||
|
onItemAdded : function(aID, aFolderID, aPosition)
|
||||||
|
{
|
||||||
|
this._addingBookmarks.push({
|
||||||
|
id : aID
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onItemRemoved : function(aID, aFolderID, aPosition) {},
|
||||||
|
onItemMoved : function(aID, aFolderID, aPosition) {},
|
||||||
|
onItemChanged : function(aID, aChange, aIsAnnotation, aNewValue) {},
|
||||||
|
onItemVisited : function(aID, aHistoryID, aDate) {},
|
||||||
|
onBeginUpdateBatch : function() {},
|
||||||
|
onEndUpdateBatch : function() {},
|
||||||
|
|
||||||
observe : function(aSubject, aTopic, aData)
|
observe : function(aSubject, aTopic, aData)
|
||||||
{
|
{
|
||||||
switch (aTopic)
|
switch (aTopic)
|
||||||
|
@ -1370,13 +1370,21 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
|
|
||||||
this.initTab(tab);
|
this.initTab(tab);
|
||||||
|
|
||||||
if (this.readyToAttachNewTab) {
|
var position = this.treeStructure && this.treeStructure.length ?
|
||||||
var parent = this.getTabById(this.parentTab);
|
this.treeStructure.shift() : -1 ;
|
||||||
if (parent)
|
|
||||||
this.attachTabTo(tab, parent);
|
|
||||||
|
|
||||||
var refTab;
|
if (this.readyToAttachNewTab) {
|
||||||
var newIndex = -1;
|
let parent = this.getTabById(this.parentTab);
|
||||||
|
if (parent) {
|
||||||
|
let tabs = [parent].concat(this.getDescendantTabs(parent));
|
||||||
|
parent = (position > -1 && position < tabs.length) ? tabs[position] : parent ;
|
||||||
|
}
|
||||||
|
if (parent) {
|
||||||
|
this.attachTabTo(tab, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
let refTab;
|
||||||
|
let newIndex = -1;
|
||||||
if (this.insertBefore &&
|
if (this.insertBefore &&
|
||||||
(refTab = this.getTabById(this.insertBefore))) {
|
(refTab = this.getTabById(this.insertBefore))) {
|
||||||
newIndex = refTab._tPos;
|
newIndex = refTab._tPos;
|
||||||
|
Loading…
Reference in New Issue
Block a user