ツリーをまとめてブックマークした場合に、ツリー構造をアノテーションとして保持するようにした

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@4826 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2009-07-30 07:56:11 +00:00
parent c3faed24ba
commit e80d307031
3 changed files with 148 additions and 13 deletions

View File

@ -6,9 +6,24 @@ window.addEventListener('load', function() {
/(function[^\(]*\([^\)]+)(\))/,
'$1, aFolderTitle$2'
).replace(
'browserWindow.getBrowser().loadTabs(',
'var urls = [];',
'$& var ids = [];'
).replace(
'urls.push(item.uri);',
'$& ids.push(item.id);'
).replace(
/(browserWindow\.getBrowser\(\)\.loadTabs\([^;]+\);)/,
<![CDATA[
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 (
where.indexOf('tab') == 0 ||
aEvent.target.id == 'placesContext_openContainer:tabs' ||
@ -16,23 +31,41 @@ window.addEventListener('load', function() {
aEvent.target.getAttribute('openInTabs') == 'true'
) {
if (openGroupBookmarkBehavior & TreeStyleTabService.kGROUP_BOOKMARK_SUBTREE) {
TreeStyleTabService.readyToOpenNewTabGroup();
if (openGroupBookmarkBehavior & TreeStyleTabService.kGROUP_BOOKMARK_USE_DUMMY)
if (
openGroupBookmarkBehavior & TreeStyleTabService.kGROUP_BOOKMARK_USE_DUMMY &&
treeStructure.filter(function(aParent) { return aParent == -1; }).length > 1
) {
treeStructure.unshift(-1);
urls.unshift(TreeStyleTabService.getGroupTabURI(aFolderTitle));
}
TreeStyleTabService.readyToOpenNewTabGroup(null, treeStructure);
replaceCurrentTab = false;
}
else {
replaceCurrentTab = openGroupBookmarkBehavior & TreeStyleTabService.kGROUP_BOOKMARK_REPLACE ? true : false ;
}
}
$&]]>
$1
]]>
)
);
eval('PlacesUIUtils.openContainerNodeInTabs = '+
PlacesUIUtils.openContainerNodeInTabs.toSource().replace(
/(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, $&'
)
);

View File

@ -177,6 +177,16 @@ var TreeStyleTabService = {
},
_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()
{
if (!('_EffectiveTLD' in this)) {
@ -264,7 +274,7 @@ var TreeStyleTabService = {
ownerBrowser.treeStyleTab.insertBefore = refId;
},
readyToOpenNewTabGroup : function(aFrameOrTabBrowser) /* PUBLIC API */
readyToOpenNewTabGroup : function(aFrameOrTabBrowser, aTreeStructure) /* PUBLIC API */
{
if (!this.getTreePref('autoAttachNewTabsAsChildren')) return;
@ -277,6 +287,7 @@ var TreeStyleTabService = {
ownerBrowser.treeStyleTab.readyToAttachNewTabGroup = true;
ownerBrowser.treeStyleTab.readyToAttachMultiple = true;
ownerBrowser.treeStyleTab.multipleCount = 0;
ownerBrowser.treeStyleTab.treeStructure = aTreeStructure;
},
stopToOpenChildTab : function(aFrameOrTabBrowser) /* PUBLIC API */
@ -291,6 +302,7 @@ var TreeStyleTabService = {
ownerBrowser.treeStyleTab.multipleCount = 0;
ownerBrowser.treeStyleTab.parentTab = null;
ownerBrowser.treeStyleTab.insertBefore = null;
ownerBrowser.treeStyleTab.treeStructure = null;
},
checkToOpenChildTab : function(aFrameOrTabBrowser) /* PUBLIC API */
@ -486,6 +498,41 @@ var TreeStyleTabService = {
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 */
getTempTreeStyleTab : function(aTabBrowser)
{
@ -2364,7 +2411,13 @@ catch(e) {
bookmarkedTabs = bookmarkedTabs.concat(b.treeStyleTab.getDescendantTabs(aTab));
}, this);
this.beginAddBookmarksFromTabs(bookmarkedTabs);
try {
window['piro.sakura.ne.jp'].bookmarkMultipleTabs.addBookmarkFor(bookmarkedTabs, folderName);
}
catch(e) {
}
this.endAddBookmarksFromTabs();
},
openSelectionLinks : function(aFrame)
@ -2537,6 +2590,47 @@ catch(e) {
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)
{
switch (aTopic)

View File

@ -1370,13 +1370,21 @@ TreeStyleTabBrowser.prototype = {
this.initTab(tab);
if (this.readyToAttachNewTab) {
var parent = this.getTabById(this.parentTab);
if (parent)
this.attachTabTo(tab, parent);
var position = this.treeStructure && this.treeStructure.length ?
this.treeStructure.shift() : -1 ;
var refTab;
var newIndex = -1;
if (this.readyToAttachNewTab) {
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 &&
(refTab = this.getTabById(this.insertBefore))) {
newIndex = refTab._tPos;