From e80d307031c9ce90313e7112bacbb683c62af033 Mon Sep 17 00:00:00 2001 From: piro Date: Thu, 30 Jul 2009 07:56:11 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=84=E3=83=AA=E3=83=BC=E3=82=92=E3=81=BE?= =?UTF-8?q?=E3=81=A8=E3=82=81=E3=81=A6=E3=83=96=E3=83=83=E3=82=AF=E3=83=9E?= =?UTF-8?q?=E3=83=BC=E3=82=AF=E3=81=97=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=AB?= =?UTF-8?q?=E3=80=81=E3=83=84=E3=83=AA=E3=83=BC=E6=A7=8B=E9=80=A0=E3=82=92?= =?UTF-8?q?=E3=82=A2=E3=83=8E=E3=83=86=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=81=A8=E3=81=97=E3=81=A6=E4=BF=9D=E6=8C=81=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@4826 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/bookmarksOverlay.js | 43 +++++++-- content/treestyletab/treestyletab.js | 98 ++++++++++++++++++++- content/treestyletab/treestyletabbrowser.js | 20 +++-- 3 files changed, 148 insertions(+), 13 deletions(-) diff --git a/content/treestyletab/bookmarksOverlay.js b/content/treestyletab/bookmarksOverlay.js index c3471f1f..57c2abe9 100644 --- a/content/treestyletab/bookmarksOverlay.js +++ b/content/treestyletab/bookmarksOverlay.js @@ -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\([^;]+\);)/, 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' + + ) + ); + + eval('PlacesUIUtils.openURINodesInTabs = '+ + PlacesUIUtils.openURINodesInTabs.toSource().replace( + 'uri: aNodes[i].uri,', + 'id: aNodes[i].itemId, $&' ) ); diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index 9708a11c..3b149c1a 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -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 */ @@ -485,6 +497,41 @@ var TreeStyleTabService = { aNewPosition = aNewPosition.toLowerCase(); 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); - 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) @@ -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) diff --git a/content/treestyletab/treestyletabbrowser.js b/content/treestyletab/treestyletabbrowser.js index 75444a44..0f2d2b1b 100644 --- a/content/treestyletab/treestyletabbrowser.js +++ b/content/treestyletab/treestyletabbrowser.js @@ -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;