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 2d8c232a05
commit eff7e52e5a
5 changed files with 88 additions and 4 deletions

View File

@ -4299,9 +4299,28 @@ function onViewToolbarsPopupShowing(aEvent, aInsertPoint) {
toolbarItem = null; toolbarItem = null;
} }
// Right-clicking on an empty part of the tabstrip will exit let showTabStripItems = toolbarItem && toolbarItem.id == "tabbrowser-tabs";
// the above loop with toolbarItem being the xul:document. for (let node of popup.querySelectorAll('menuitem[contexttype="toolbaritem"]')) {
// That has no parentNode, and we should disable the items in 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. // this case.
let movable = toolbarItem && toolbarItem.parentNode && let movable = toolbarItem && toolbarItem.parentNode &&
CustomizableUI.isWidgetRemovable(toolbarItem); CustomizableUI.isWidgetRemovable(toolbarItem);

View File

@ -286,11 +286,31 @@
<menuitem oncommand="gCustomizeMode.addToPanel(document.popupNode)" <menuitem oncommand="gCustomizeMode.addToPanel(document.popupNode)"
accesskey="&customizeMenu.moveToPanel.accesskey;" accesskey="&customizeMenu.moveToPanel.accesskey;"
label="&customizeMenu.moveToPanel.label;" label="&customizeMenu.moveToPanel.label;"
contexttype="toolbaritem"
class="customize-context-moveToPanel"/> class="customize-context-moveToPanel"/>
<menuitem oncommand="gCustomizeMode.removeFromArea(document.popupNode)" <menuitem oncommand="gCustomizeMode.removeFromArea(document.popupNode)"
accesskey="&customizeMenu.removeFromToolbar.accesskey;" accesskey="&customizeMenu.removeFromToolbar.accesskey;"
label="&customizeMenu.removeFromToolbar.label;" label="&customizeMenu.removeFromToolbar.label;"
contexttype="toolbaritem"
class="customize-context-removeFromToolbar"/> 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/>
<menuseparator id="viewToolbarsMenuSeparator"/> <menuseparator id="viewToolbarsMenuSeparator"/>
<!-- XXXgijs: we're using oncommand handler here to avoid the event being <!-- XXXgijs: we're using oncommand handler here to avoid the event being

View File

@ -35,6 +35,44 @@ add_task(function() {
yield hiddenPromise; 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 // Right-click on an empty bit of extra toolbar should
// show a context menu with moving options disabled, // show a context menu with moving options disabled,
// and a toggle option for the extra toolbar // 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 // This is a simpler version of the context menu check that
// exists in contextmenu_common.js. // exists in contextmenu_common.js.
function checkContextMenu(aContextMenu, aExpectedEntries, aWindow=window) { 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++) { for (let i = 0; i < childNodes.length; i++) {
let menuitem = childNodes[i]; let menuitem = childNodes[i];
try { try {

View File

@ -82,6 +82,10 @@ when there are no windows but Firefox is still running. -->
<!ENTITY personalbarCmd.accesskey "B"> <!ENTITY personalbarCmd.accesskey "B">
<!ENTITY bookmarksToolbarItem.label "Bookmarks Toolbar Items"> <!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.label "Page Source">
<!ENTITY pageSourceCmd.accesskey "o"> <!ENTITY pageSourceCmd.accesskey "o">
<!ENTITY pageSourceCmd.commandkey "u"> <!ENTITY pageSourceCmd.commandkey "u">