Bug 1014313 - part 1: add tabs options to tabstrip context menu, r=dao

This commit is contained in:
Gijs Kruitbosch 2014-07-02 23:23:48 +01:00
parent 267a796ba5
commit b8ef5bf613
5 changed files with 88 additions and 4 deletions

View File

@ -4299,9 +4299,28 @@ function onViewToolbarsPopupShowing(aEvent, aInsertPoint) {
toolbarItem = null;
}
// Right-clicking on an empty part of the tabstrip will exit
// the above loop with toolbarItem being the xul:document.
// That has no parentNode, and we should disable the items in
let showTabStripItems = toolbarItem && toolbarItem.id == "tabbrowser-tabs";
for (let node of popup.querySelectorAll('menuitem[contexttype="toolbaritem"]')) {
node.hidden = showTabStripItems;
}
for (let node of popup.querySelectorAll('menuitem[contexttype="tabbar"]')) {
node.hidden = !showTabStripItems;
}
if (showTabStripItems) {
PlacesCommandHook.updateBookmarkAllTabsCommand();
let haveMultipleTabs = gBrowser.visibleTabs.length > 1;
document.getElementById("toolbar-context-reloadAllTabs").disabled = !haveMultipleTabs;
document.getElementById("toolbar-context-undoCloseTab").disabled =
SessionStore.getClosedTabCount(window) == 0;
return;
}
// In some cases, we will exit the above loop with toolbarItem being the
// xul:document. That has no parentNode, and we should disable the items in
// this case.
let movable = toolbarItem && toolbarItem.parentNode &&
CustomizableUI.isWidgetRemovable(toolbarItem);

View File

@ -286,11 +286,31 @@
<menuitem oncommand="gCustomizeMode.addToPanel(document.popupNode)"
accesskey="&customizeMenu.moveToPanel.accesskey;"
label="&customizeMenu.moveToPanel.label;"
contexttype="toolbaritem"
class="customize-context-moveToPanel"/>
<menuitem oncommand="gCustomizeMode.removeFromArea(document.popupNode)"
accesskey="&customizeMenu.removeFromToolbar.accesskey;"
label="&customizeMenu.removeFromToolbar.label;"
contexttype="toolbaritem"
class="customize-context-removeFromToolbar"/>
<menuitem id="toolbar-context-reloadAllTabs"
class="toolbaritem-tabsmenu"
contexttype="tabbar"
oncommand="gBrowser.reloadAllTabs();"
label="&reloadAllTabs.label;"
accesskey="&toolbarContextMenu.reloadAllTabs.accesskey;"/>
<menuitem id="toolbar-context-bookmarkAllTabs"
class="toolbaritem-tabsmenu"
contexttype="tabbar"
command="Browser:BookmarkAllTabs"
label="&bookmarkAllTabs.label;"
accesskey="&toolbarContextMenu.bookmarkAllTabs.accesskey;"/>
<menuitem id="toolbar-context-undoCloseTab"
class="toolbaritem-tabsmenu"
contexttype="tabbar"
label="&undoCloseTab.label;"
accesskey="&toolbarContextMenu.undoCloseTab.accesskey;"
observes="History:UndoCloseTab"/>
<menuseparator/>
<menuseparator id="viewToolbarsMenuSeparator"/>
<!-- XXXgijs: we're using oncommand handler here to avoid the event being

View File

@ -35,6 +35,44 @@ add_task(function() {
yield hiddenPromise;
});
// Right-click on an empty bit of tabstrip should
// show a context menu without options to move it,
// but with tab-specific options instead.
add_task(function() {
// ensure there are tabs to reload/bookmark:
let extraTab = gBrowser.selectedTab = gBrowser.addTab();
yield promiseTabLoadEvent(extraTab, "http://example.com/");
let contextMenu = document.getElementById("toolbar-context-menu");
let shownPromise = popupShown(contextMenu);
let tabstrip = document.getElementById("tabbrowser-tabs");
let rect = tabstrip.getBoundingClientRect();
EventUtils.synthesizeMouse(tabstrip, rect.width - 2, 2, {type: "contextmenu", button: 2 });
yield shownPromise;
let closedTabsAvailable = SessionStore.getClosedTabCount(window) == 0;
info("Closed tabs: " + closedTabsAvailable);
let expectedEntries = [
["#toolbar-context-reloadAllTabs", true],
["#toolbar-context-bookmarkAllTabs", true],
["#toolbar-context-undoCloseTab", !closedTabsAvailable],
["---"]
];
if (!isOSX) {
expectedEntries.push(["#toggle_toolbar-menubar", true]);
}
expectedEntries.push(
["#toggle_PersonalToolbar", true],
["---"],
[".viewCustomizeToolbar", true]
);
checkContextMenu(contextMenu, expectedEntries);
let hiddenPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenPromise;
gBrowser.removeTab(extraTab);
});
// Right-click on an empty bit of extra toolbar should
// show a context menu with moving options disabled,
// and a toggle option for the extra toolbar

View File

@ -474,7 +474,10 @@ function promisePopupEvent(aPopup, aEventSuffix) {
// This is a simpler version of the context menu check that
// exists in contextmenu_common.js.
function checkContextMenu(aContextMenu, aExpectedEntries, aWindow=window) {
let childNodes = aContextMenu.childNodes;
let childNodes = [...aContextMenu.childNodes];
// Ignore hidden nodes:
childNodes = childNodes.filter((n) => !n.hidden);
for (let i = 0; i < childNodes.length; i++) {
let menuitem = childNodes[i];
try {

View File

@ -82,6 +82,10 @@ when there are no windows but Firefox is still running. -->
<!ENTITY personalbarCmd.accesskey "B">
<!ENTITY bookmarksToolbarItem.label "Bookmarks Toolbar Items">
<!ENTITY toolbarContextMenu.reloadAllTabs.accesskey "A">
<!ENTITY toolbarContextMenu.bookmarkAllTabs.accesskey "T">
<!ENTITY toolbarContextMenu.undoCloseTab.accesskey "U">
<!ENTITY pageSourceCmd.label "Page Source">
<!ENTITY pageSourceCmd.accesskey "o">
<!ENTITY pageSourceCmd.commandkey "u">