サブツリーをブックマークに保存する処理についてライブラリを使うようにした

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@4694 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2009-07-09 04:26:36 +00:00
parent 107f0a254d
commit a8c9189abc
4 changed files with 173 additions and 73 deletions

View File

@ -5,6 +5,9 @@ overlay chrome://browser/content/browser.xul chrome://treestyletab/content/trees
overlay chrome://browser/content/bookmarks/bookmarksPanel.xul chrome://treestyletab/content/bookmarksOverlay.xul
overlay chrome://multipletab/content/config.xul chrome://treestyletab/content/multipletabConfigOverlay.xul
overlay chrome://browser/content/browser.xul chrome://treestyletab/content/res/bookmarkMultipleTabs.xul
overlay chrome://browser/content/places/bookmarkProperties2.xul chrome://treestyletab/content/res/bookmarkMultipleTabs_bookmarkPropertiesOverlay.xul
style chrome://browser/content/browser.xul chrome://treestyletab/content/treestyletab-3.5.css appversion>=3.1
locale treestyletab en-US jar:chrome/treestyletab.jar!/locale/en-US/treestyletab/

View File

@ -0,0 +1,115 @@
<?xml version="1.0"?>
<!--
Bookmark Multiple Tabs library for Firefox 2 or later
Usage:
in chrome.manifest:
overlay chrome://browser/content/browser.xul
chrome://***/content/bookmarkMultipleTabs.xul
overlay chrome://browser/content/places/bookmarkProperties2.xul
chrome://***/content/bookmarkMultipleTabs_bookmarkPropertiesOverlay.xul
in JS files:
window['piro.sakura.ne.jp'].bookmarkMultipleTabs.addBookmarkFor(tabsArray, folderName);
lisence: The MIT License, Copyright (c) 2009 SHIMODA "Piro" Hiroshi
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
original:
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/bookmarkMultipleTabs.xul
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/bookmarkMultipleTabs_bookmarkPropertiesOverlay.xul
-->
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript"><![CDATA[
window.addEventListener('DOMContentLoaded', function() {
window.removeEventListener('DOMContentLoaded', arguments.callee, true);
const currentRevision = 1;
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
var loadedRevision = 'bookmarkMultipleTabs' in window['piro.sakura.ne.jp'] ?
window['piro.sakura.ne.jp'].bookmarkMultipleTabs.revision :
0 ;
if (loadedRevision && loadedRevision > currentRevision) {
return;
}
window['piro.sakura.ne.jp'].bookmarkMultipleTabs = {
revision : currentRevision,
addBookmarkFor : function(aTabs, aFolderName)
{
if (!aTabs) return;
var b = this.getTabBrowserFromChild(aTabs[0]);
if ('PlacesUIUtils' in window || 'PlacesUtils' in window) { // Firefox 3
if (aFolderName)
this.Prefs.setCharPref('temp.showMinimalAddMultiBookmarkUI.folderName', unescape(encodeURIComponent(aFolderName)));
var utils = 'PlacesUIUtils' in window ? PlacesUIUtils : PlacesUtils ;
utils.showMinimalAddMultiBookmarkUI(Array.slice(aTabs).map(this.addBookmarkTabsFilter));
this.Prefs.clearUserPref('temp.showMinimalAddMultiBookmarkUI.folderName');
return;
}
var currentTabInfo;
var tabsInfo = Array.slice(aTabs).map(function(aTab) {
var webNav = aTab.linkedBrowser.webNavigation;
var url = webNav.currentURI.spec;
var name = '';
var charSet, description;
try {
var doc = webNav.document;
name = doc.title || url;
charSet = doc.characterSet;
description = BookmarksUtils.getDescriptionFromDocument(doc);
}
catch (e) {
name = url;
}
return {
name : name,
url : url,
charset : charSet,
description : description
};
});
window.openDialog(
'chrome://browser/content/bookmarks/addBookmark2.xul',
'',
BROWSER_ADD_BM_FEATURES,
(aTabs.length == 1 ?
tabsInfo[0] :
{
name : (aFolderName || gNavigatorBundle.getString('bookmarkAllTabsDefault')),
bBookmarkAllTabs : true,
objGroup : tabsInfo
}
)
);
},
addBookmarkTabsFilter : function(aTab)
{
return aTab.linkedBrowser.currentURI;
},
Prefs : Components.classes['@mozilla.org/preferences;1']
.getService(Components.interfaces.nsIPrefBranch),
getTabBrowserFromChild : function(aTab)
{
return aTab.ownerDocument.evaluate(
'ancestor-or-self::*[local-name()="tabbrowser"]',
aTab,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
}
};
}, true);
]]></script>
</overlay>

View File

@ -0,0 +1,50 @@
<?xml version="1.0"?>
<!--
Bookmark Multiple Tabs library for Firefox 2 or later
Usage:
in chrome.manifest:
overlay chrome://browser/content/browser.xul
chrome://***/content/bookmarkMultipleTabs.xul
overlay chrome://browser/content/places/bookmarkProperties2.xul
chrome://***/content/bookmarkMultipleTabs_bookmarkPropertiesOverlay.xul
in JS files:
window['piro.sakura.ne.jp'].bookmarkMultipleTabs.addBookmarkFor(tabsArray, folderName);
lisence: The MIT License, Copyright (c) 2009 SHIMODA "Piro" Hiroshi
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
original:
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/bookmarkMultipleTabs.xul
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/bookmarkMultipleTabs_bookmarkPropertiesOverlay.xul
-->
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript; version=1.7"><![CDATA[
(function() {
if (!('BookmarkPropertiesPanel' in window) ||
!BookmarkPropertiesPanel._determineItemInfo ||
BookmarkPropertiesPanel._determineItemInfo.toSource().indexOf('__folderNameOverride') > -1)
return;
eval('BookmarkPropertiesPanel._determineItemInfo = '+
BookmarkPropertiesPanel._determineItemInfo.toSource().replace(
'{',
['{',
'var __folderNameOverride = null;',
'try {',
' __folderNameOverride = Components.classes["@mozilla.org/preferences;1"]',
' .getService(Components.interfaces.nsIPrefBranch)',
' .getCharPref("temp.showMinimalAddMultiBookmarkUI.folderName");',
' __folderNameOverride = decodeURIComponent(escape(__folderNameOverride));',
'}',
'catch(e) {',
'}'
].join('')
).replace(
'this._strings.getString("bookmarkAllTabsDefault")',
'__folderNameOverride || $&'
).replace()
);
})();
]]></script>
</overlay>

View File

@ -2170,84 +2170,16 @@ catch(e) {
tabs = [aTabOrTabs];
}
var folderName = null;
if (this.isGroupTab(tabs[0], true)) {
folderName = tabs[0].label;
tabs.splice(0, 1);
}
var folderName = this.isGroupTab(tabs[0], true) ? tabs[0].label : 0 ;
var b = this.getTabBrowserFromChild(tabs[0]);
var bookmarkedTabs = [];
tabs.forEach(function(aTab) {
if (!this.isGroupTab(aTab)) bookmarkedTabs.push(aTab);
tabs.forEach(function(aTab, aIndex) {
if (!this.isGroupTab(aTab, aIndex == 0)) bookmarkedTabs.push(aTab);
bookmarkedTabs = bookmarkedTabs.concat(b.treeStyleTab.getDescendantTabs(aTab));
}, this);
if ('MultipleTabService' in window &&
'addBookmarkFor' in MultipleTabService) {
MultipleTabService.addBookmarkFor(bookmarkedTabs, folderName);
}
else {
this._addBookmarkFor(bookmarkedTabs, folderName);
}
},
_addBookmarkFor : function(aTabs, aFolder) // from Multiple Tab Handler
{
if (!aTabs) return;
var b = this.getTabBrowserFromChild(aTabs[0]);
if ('PlacesUIUtils' in window || 'PlacesUtils' in window) { // Firefox 3
var utils = 'PlacesUIUtils' in window ? PlacesUIUtils : PlacesUtils ;
utils.showMinimalAddMultiBookmarkUI(Array.slice(aTabs).map(this.addBookmarkTabsFilter));
return;
}
var currentTabInfo;
var tabsInfo = Array.slice(aTabs)
.filter(function(aTab) {
return aTab.parentNode; // ignore removed tabs
})
.map(function(aTab) {
var webNav = aTab.linkedBrowser.webNavigation;
var url = webNav.currentURI.spec;
var name = '';
var charSet, description;
try {
var doc = webNav.document;
name = doc.title || url;
charSet = doc.characterSet;
description = BookmarksUtils.getDescriptionFromDocument(doc);
}
catch (e) {
name = url;
}
return {
name : name,
url : url,
charset : charSet,
description : description
};
});
window.openDialog(
'chrome://browser/content/bookmarks/addBookmark2.xul',
'',
BROWSER_ADD_BM_FEATURES,
(aTabs.length == 1 ?
tabsInfo[0] :
{
name : (aFolderName || gNavigatorBundle.getString('bookmarkAllTabsDefault')),
bBookmarkAllTabs : true,
objGroup : tabsInfo
}
)
);
},
addBookmarkTabsFilter : function(aTab)
{
return aTab.linkedBrowser.currentURI;
window['piro.sakura.ne.jp'].bookmarkMultipleTabs.addBookmarkFor(bookmarkedTabs, folderName);
},
openSelectionLinks : function(aFrame)