mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 367025 - 'Bookmark All Tabs' command is always enabled in places-bookmarks builds. r=sspitzer.
This commit is contained in:
parent
dae01d62ef
commit
91990f7ffa
@ -421,7 +421,7 @@
|
||||
ref="NC:BookmarksRoot" flags="dont-test-empty"
|
||||
template='bookmarks-template'
|
||||
infer="forward-proxy"
|
||||
onpopupshowing="UpdateBookmarkAllTabsMenuitem(); BookmarksMenu.onShowMenu(event.target)"
|
||||
onpopupshowing="BookmarksMenu.onShowMenu(event.target)"
|
||||
onpopuphidden="BookmarksMenu.onHideMenu(event.target)"
|
||||
oncommand="BookmarksMenu.loadBookmark(event, event.target, this.database)"
|
||||
onclick="BookmarksMenu.loadBookmarkMiddleClick(event, this.database)"
|
||||
|
@ -37,67 +37,6 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* A BookmarkAllTabs command for the BrowserController in browser.js
|
||||
*/
|
||||
function BookmarkAllTabsCommand() {
|
||||
}
|
||||
BookmarkAllTabsCommand.prototype = {
|
||||
/**
|
||||
* true if the command is enabled, false otherwise.
|
||||
*/
|
||||
get enabled() {
|
||||
return getBrowser().tabContainer.childNodes.length > 1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Performs the command (bookmarking all tabs).
|
||||
*/
|
||||
execute: function BATC_execute() {
|
||||
var tabURIs = this._getUniqueTabInfo(getBrowser());
|
||||
PlacesUtils.showAddMultiBookmarkUI(tabURIs);
|
||||
},
|
||||
|
||||
/**
|
||||
* This function returns a list of nsIURI objects characterizing the
|
||||
* tabs currently open in the given browser. The URIs will appear in the
|
||||
* list in the order in which their corresponding tabs appeared. However,
|
||||
* only the first instance of each URI will be returned.
|
||||
*
|
||||
* @param tabBrowser
|
||||
* the tabBrowser to get the contents of
|
||||
* @returns a list of nsIURI objects representing unique locations open
|
||||
*/
|
||||
_getUniqueTabInfo: function BATC__getUniqueTabInfo(tabBrowser) {
|
||||
var tabList = [];
|
||||
var seenURIs = [];
|
||||
|
||||
const activeBrowser = tabBrowser.selectedBrowser;
|
||||
const browsers = tabBrowser.browsers;
|
||||
for (var i = 0; i < browsers.length; ++i) {
|
||||
var webNav = browsers[i].webNavigation;
|
||||
var uri = webNav.currentURI;
|
||||
|
||||
// skip redundant entries
|
||||
if (uri.spec in seenURIs)
|
||||
continue;
|
||||
|
||||
// add to the set of seen URIs
|
||||
seenURIs[uri.spec] = true;
|
||||
|
||||
tabList.push(uri);
|
||||
}
|
||||
return tabList;
|
||||
}
|
||||
};
|
||||
BookmarkAllTabsCommand.NAME = "Browser:BookmarkAllTabs";
|
||||
|
||||
// Tell the BrowserController about this command.
|
||||
BrowserController.commands[BookmarkAllTabsCommand.NAME] =
|
||||
new BookmarkAllTabsCommand();
|
||||
BrowserController.events[BrowserController.EVENT_TABCHANGE] =
|
||||
[BookmarkAllTabsCommand.NAME];
|
||||
|
||||
var PlacesCommandHook = {
|
||||
|
||||
/**
|
||||
@ -173,12 +112,42 @@ var PlacesCommandHook = {
|
||||
var selectedBrowser = getBrowser().selectedBrowser;
|
||||
PlacesUtils.showAddBookmarkUI(selectedBrowser.currentURI);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* This function returns a list of nsIURI objects characterizing the
|
||||
* tabs currently open in the browser. The URIs will appear in the
|
||||
* list in the order in which their corresponding tabs appeared. However,
|
||||
* only the first instance of each URI will be returned.
|
||||
*
|
||||
* @returns a list of nsIURI objects representing unique locations open
|
||||
*/
|
||||
_getUniqueTabInfo: function BATC__getUniqueTabInfo() {
|
||||
var tabList = [];
|
||||
var seenURIs = [];
|
||||
|
||||
var browsers = getBrowser().browsers;
|
||||
for (var i = 0; i < browsers.length; ++i) {
|
||||
var webNav = browsers[i].webNavigation;
|
||||
var uri = webNav.currentURI;
|
||||
|
||||
// skip redundant entries
|
||||
if (uri.spec in seenURIs)
|
||||
continue;
|
||||
|
||||
// add to the set of seen URIs
|
||||
seenURIs[uri.spec] = true;
|
||||
tabList.push(uri);
|
||||
}
|
||||
return tabList;
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a folder with bookmarks to all of the currently open tabs in this
|
||||
* window.
|
||||
*/
|
||||
bookmarkCurrentPages: function PCH_bookmarkCurrentPages() {
|
||||
var tabURIs = this._getUniqueTabInfo();
|
||||
PlacesUtils.showAddMultiBookmarkUI(tabURIs);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -146,11 +146,14 @@
|
||||
oncommand="PlacesCommandHook.bookmarkLink(gContextMenu.linkURL, gContextMenu.linkText());"/>
|
||||
<command id="Browser:AddBookmarkAs"
|
||||
oncommand="PlacesCommandHook.bookmarkCurrentPage();"/>
|
||||
<command id="Browser:BookmarkAllTabs" oncommand="BrowserController.doCommand('Browser:BookmarkAllTabs');"/>
|
||||
#else
|
||||
<command id="Browser:AddBookmarkAs" oncommand="addBookmarkAs(document.getElementById('content'), false);"/>
|
||||
<command id="Browser:BookmarkAllTabs" oncommand="addBookmarkAs(document.getElementById('content'), true);"/>
|
||||
#endif
|
||||
<!-- The command is disabled for the hidden window. Otherwise its enabled
|
||||
state is handler by the BookmarkAllTabsHandler object. -->
|
||||
<command id="Browser:BookmarkAllTabs"
|
||||
oncommand="gBookmarkAllTabsHandler.doCommand();"
|
||||
disabled="true"/>
|
||||
<command id="Browser:Home" oncommand="BrowserHome();"/>
|
||||
<command id="Browser:Back" oncommand="BrowserBack();" disabled="true"/>
|
||||
<command id="Browser:Forward" oncommand="BrowserForward();" disabled="true"/>
|
||||
@ -184,14 +187,6 @@
|
||||
</commandset>
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_PLACES_BOOKMARKS
|
||||
<commandset id="multipleTabsCommands"
|
||||
commandupdater="true" events="select"
|
||||
oncommandupdate="BrowserController.onEvent(BrowserController.EVENT_TABCHANGE);">
|
||||
<command id="Browser:BookmarkAllTabs" disabled="true"/>
|
||||
</commandset>
|
||||
#endif
|
||||
|
||||
<broadcasterset id="mainBroadcasterSet">
|
||||
#ifdef MOZ_PLACES_NEW_HISTORY_UI
|
||||
<broadcaster id="viewHistoryPlaces" autoCheck="false" label="&historyButton.label;"
|
||||
|
@ -120,6 +120,7 @@ var gSanitizeListener = null;
|
||||
|
||||
var gURLBarAutoFillPrefListener = null;
|
||||
var gAutoHideTabbarPrefListener = null;
|
||||
var gBookmarkAllTabsHandler = null;
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
var gClickAndHoldTimer = null;
|
||||
@ -278,20 +279,6 @@ function SetClickAndHoldHandlers()
|
||||
#endif
|
||||
|
||||
#ifndef MOZ_PLACES_BOOKMARKS
|
||||
function UpdateBookmarkAllTabsMenuitem()
|
||||
{
|
||||
var tabbrowser = getBrowser();
|
||||
var numTabs = 0;
|
||||
if (tabbrowser)
|
||||
numTabs = tabbrowser.tabContainer.childNodes.length;
|
||||
|
||||
var bookmarkAllCommand = document.getElementById("Browser:BookmarkAllTabs");
|
||||
if (numTabs > 1)
|
||||
bookmarkAllCommand.removeAttribute("disabled");
|
||||
else
|
||||
bookmarkAllCommand.setAttribute("disabled", "true");
|
||||
}
|
||||
|
||||
function addBookmarkMenuitems()
|
||||
{
|
||||
var tabbrowser = getBrowser();
|
||||
@ -300,8 +287,6 @@ function addBookmarkMenuitems()
|
||||
bookmarkAllTabsItem.setAttribute("label", gNavigatorBundle.getString("bookmarkAllTabs_label"));
|
||||
bookmarkAllTabsItem.setAttribute("accesskey", gNavigatorBundle.getString("bookmarkAllTabs_accesskey"));
|
||||
bookmarkAllTabsItem.setAttribute("command", "Browser:BookmarkAllTabs");
|
||||
// set up the bookmarkAllTabs menu item correctly when the menu popup is shown
|
||||
tabMenu.addEventListener("popupshowing", UpdateBookmarkAllTabsMenuitem, false);
|
||||
var bookmarkCurTabItem = document.createElement("menuitem");
|
||||
bookmarkCurTabItem.setAttribute("label", gNavigatorBundle.getString("bookmarkCurTab_label"));
|
||||
bookmarkCurTabItem.setAttribute("accesskey", gNavigatorBundle.getString("bookmarkCurTab_accesskey"));
|
||||
@ -1128,6 +1113,9 @@ function delayedStartup()
|
||||
|
||||
// browser-specific tab augmentation
|
||||
AugmentTabs.init();
|
||||
|
||||
// bookmark-all-tabs command
|
||||
gBookmarkAllTabsHandler = new BookmarkAllTabsHandler();
|
||||
}
|
||||
|
||||
function BrowserShutdown()
|
||||
@ -5612,71 +5600,7 @@ var FeedHandler = {
|
||||
};
|
||||
|
||||
#ifdef MOZ_PLACES
|
||||
|
||||
/**
|
||||
* This is a generic command controller for browser commands. Features can
|
||||
* register commands with this controller and the events that should trigger
|
||||
* updates to their state. Each command object must implement this interface:
|
||||
*
|
||||
* readonly attribute boolean enabled; // true if the command is enabled
|
||||
* void execute(); // performs the command
|
||||
*/
|
||||
var BrowserController = {
|
||||
EVENT_TABCHANGE: "tabchange",
|
||||
|
||||
/**
|
||||
* A hash of command-name->command-objects
|
||||
*/
|
||||
commands: { },
|
||||
|
||||
/**
|
||||
* A hash of event-name->array-of-command-names
|
||||
*/
|
||||
events: { },
|
||||
|
||||
/**
|
||||
* See nsIController.idl
|
||||
*/
|
||||
supportsCommand: function BC_supportsCommand(command) {
|
||||
//LOG("BrowserController.supportsCommand: " + command);
|
||||
return command in this.commands;
|
||||
},
|
||||
|
||||
/**
|
||||
* See nsIController.idl
|
||||
*/
|
||||
isCommandEnabled: function BC_isCommandEnabled(command) {
|
||||
//LOG("BrowserController.isCommandEnabled: " + command);
|
||||
NS_ASSERT(this.supportsCommand(command),
|
||||
"Controller does not support: " + command);
|
||||
return this.commands[command].enabled;
|
||||
},
|
||||
|
||||
/**
|
||||
* See nsIController.idl
|
||||
*/
|
||||
doCommand: function BC_doCommand(command) {
|
||||
//LOG("BrowserController.doCommand: " + command);
|
||||
NS_ASSERT(this.supportsCommand(command),
|
||||
"Controller does not support: " + command);
|
||||
this.commands[command].execute();
|
||||
},
|
||||
|
||||
/**
|
||||
* See nsIController.idl
|
||||
*/
|
||||
onEvent: function BC_onEvent(event) {
|
||||
if (event in this.events) {
|
||||
var commandsForEvent = this.events[event];
|
||||
for (var i = 0; i < commandsForEvent.length; ++i)
|
||||
CommandUpdater.updateCommand(commandsForEvent[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
window.controllers.appendController(BrowserController);
|
||||
|
||||
#include browser-places.js
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -5850,3 +5774,51 @@ function formatURL(aFormat, aIsPref) {
|
||||
var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter);
|
||||
return aIsPref ? formatter.formatURLPref(aFormat) : formatter.formatURL(aFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* This object encapsulates both legacy and places-based implementations
|
||||
* of the bookmark-all-tabs command. It also takes care of updating the command
|
||||
* enabled-state when tabs are created or removed.
|
||||
*/
|
||||
function BookmarkAllTabsHandler() {
|
||||
this._command = document.getElementById("Browser:BookmarkAllTabs");
|
||||
gBrowser.addEventListener("TabOpen", this, true);
|
||||
gBrowser.addEventListener("TabClose", this, true);
|
||||
this._updateCommandState();
|
||||
}
|
||||
|
||||
BookmarkAllTabsHandler.prototype = {
|
||||
QueryInterface: function BATH_QueryInterface(aIID) {
|
||||
if (aIID.equals(Ci.nsIDOMEventListener) ||
|
||||
aIID.equals(Ci.nsISupports))
|
||||
return this;
|
||||
|
||||
throw Cr.NS_NOINTERFACE;
|
||||
},
|
||||
|
||||
_updateCommandState: function BATH__updateCommandState(aTabClose) {
|
||||
var numTabs = gBrowser.tabContainer.childNodes.length;
|
||||
|
||||
// The TabClose event is fired before the tab is removed from the DOM
|
||||
if (aTabClose)
|
||||
numTabs--;
|
||||
|
||||
if (numTabs > 1)
|
||||
this._command.removeAttribute("disabled");
|
||||
else
|
||||
this._command.setAttribute("disabled", "true");
|
||||
},
|
||||
|
||||
doCommand: function BATH_doCommand() {
|
||||
#ifdef MOZ_PLACES_BOOKMARKS
|
||||
PlacesCommandHook.bookmarkCurrentPages();
|
||||
#else
|
||||
addBookmarkAs(gBrowser, true);
|
||||
#endif
|
||||
},
|
||||
|
||||
// nsIDOMEventListener
|
||||
handleEvent: function(aEvent) {
|
||||
this._updateCommandState(aEvent.type == "TabClose");
|
||||
}
|
||||
};
|
||||
|
@ -512,11 +512,7 @@
|
||||
onnewtab="BrowserOpenTab();"
|
||||
autocompletepopup="PopupAutoComplete"
|
||||
ondragdrop="nsDragAndDrop.drop(event, contentAreaDNDObserver);"
|
||||
onclick="return contentAreaClick(event, false);"
|
||||
#ifdef MOZ_PLACES_BOOKMARKS
|
||||
onselect="BrowserController.onEvent(BrowserController.EVENT_TABCHANGE);"
|
||||
#endif
|
||||
/>
|
||||
onclick="return contentAreaClick(event, false);"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
#ifdef TOOLBAR_CUSTOMIZATION_SHEET
|
||||
|
Loading…
Reference in New Issue
Block a user