Bug 879293 - Allow alt+click to select only one category of messages in the console; r=msucan

This commit is contained in:
Gabriel Luong 2013-11-12 14:20:14 +02:00
parent f22658bad0
commit 41412e6be8
3 changed files with 114 additions and 17 deletions

View File

@ -22,6 +22,13 @@ function testFilterButtons(aHud) {
testMenuFilterButton("css");
testMenuFilterButton("js");
testMenuFilterButton("logging");
testMenuFilterButton("security");
testIsolateFilterButton("net");
testIsolateFilterButton("css");
testIsolateFilterButton("js");
testIsolateFilterButton("logging");
testIsolateFilterButton("security");
finishTest();
}
@ -72,15 +79,7 @@ function testMenuFilterButton(aCategory) {
"checked after turning off its first menu item");
// Turn all the filters off by clicking the main part of the button.
let anonymousNodes = hud.ui.document.getAnonymousNodes(button);
let subbutton;
for (let i = 0; i < anonymousNodes.length; i++) {
let node = anonymousNodes[i];
if (node.classList.contains("toolbarbutton-menubutton-button")) {
subbutton = node;
break;
}
}
let subbutton = getMainButton(button);
ok(subbutton, "we have the subbutton for category " + aCategory);
clickButton(subbutton);
@ -129,10 +128,81 @@ function testMenuFilterButton(aCategory) {
clickButton(subbutton);
}
function testIsolateFilterButton(aCategory) {
let selector = ".webconsole-filter-button[category=\"" + aCategory + "\"]";
let targetButton = hudBox.querySelector(selector);
ok(targetButton, "we have the \"" + aCategory + "\" button");
// Get the main part of the filter button.
let subbutton = getMainButton(targetButton);
ok(subbutton, "we have the subbutton for category " + aCategory);
// Turn on all the filters by alt clicking the main part of the button.
altClickButton(subbutton);
ok(isChecked(targetButton), "the button for category " + aCategory +
" is checked after isolating for filter");
// Check if all the filters for the target button are on.
let menuItems = targetButton.querySelectorAll("menuitem");
Array.forEach(menuItems, (item) => {
let prefKey = item.getAttribute("prefKey");
ok(isChecked(item), "menu item " + prefKey + " for category " +
aCategory + " is checked after isolating for " + aCategory);
ok(hud.ui.filterPrefs[prefKey], prefKey + " messages are " +
"turned on after isolating for " + aCategory);
});
// Ensure all other filter buttons are toggled off and their
// associated filters are turned off
let buttons = hudBox.querySelectorAll(".webconsole-filter-button[category]");
Array.forEach(buttons, (filterButton) => {
if (filterButton !== targetButton) {
let category = filterButton.getAttribute("category");
ok(!isChecked(filterButton), "the button for category " +
category + " is unchecked after isolating for " + aCategory);
menuItems = filterButton.querySelectorAll("menuitem");
Array.forEach(menuItems, (item) => {
let prefKey = item.getAttribute("prefKey");
ok(!isChecked(item), "menu item " + prefKey + " for category " +
aCategory + " is unchecked after isolating for " + aCategory);
ok(!hud.ui.filterPrefs[prefKey], prefKey + " messages are " +
"turned off after isolating for " + aCategory);
});
// Turn all the filters on again by clicking the button.
let mainButton = getMainButton(filterButton);
clickButton(mainButton);
}
});
}
/**
* Return the main part of the target filter button.
*/
function getMainButton(aTargetButton) {
let anonymousNodes = hud.ui.document.getAnonymousNodes(aTargetButton);
let subbutton;
for (let i = 0; i < anonymousNodes.length; i++) {
let node = anonymousNodes[i];
if (node.classList.contains("toolbarbutton-menubutton-button")) {
subbutton = node;
break;
}
}
return subbutton;
}
function clickButton(aNode) {
EventUtils.sendMouseEvent({ type: "click" }, aNode);
}
function altClickButton(aNode) {
EventUtils.sendMouseEvent({ type: "click", altKey: true }, aNode);
}
function chooseMenuItem(aNode) {
let event = document.createEvent("XULCommandEvent");
event.initCommandEvent("command", true, true, window, 0, false, false, false,

View File

@ -801,18 +801,26 @@ WebConsoleFrame.prototype = {
break;
}
// Toggle on the targeted filter button, and if the user alt clicked,
// toggle off all other filter buttons and their associated filters.
let state = target.getAttribute("checked") !== "true";
if (aEvent.getModifierState("Alt")) {
let buttons = this.document
.querySelectorAll(".webconsole-filter-button");
Array.forEach(buttons, (button) => {
if (button !== target) {
button.setAttribute("checked", false);
this._setMenuState(button, false);
}
});
state = true;
}
target.setAttribute("checked", state);
// This is a filter button with a drop-down, and the user clicked the
// main part of the button. Go through all the severities and toggle
// their associated filters.
let menuItems = target.querySelectorAll("menuitem");
for (let i = 0; i < menuItems.length; i++) {
menuItems[i].setAttribute("checked", state);
let prefKey = menuItems[i].getAttribute("prefKey");
this.setFilterState(prefKey, state);
}
this._setMenuState(target, state);
break;
}
@ -851,6 +859,25 @@ WebConsoleFrame.prototype = {
}
},
/**
* Set the menu attributes for a specific toggle button.
*
* @private
* @param XULElement aTarget
* Button with drop down items to be toggled.
* @param boolean aState
* True if the menu item is being toggled on, and false otherwise.
*/
_setMenuState: function WCF__setMenuState(aTarget, aState)
{
let menuItems = aTarget.querySelectorAll("menuitem");
Array.forEach(menuItems, (item) => {
item.setAttribute("checked", aState);
let prefKey = item.getAttribute("prefKey");
this.setFilterState(prefKey, aState);
});
},
/**
* Set the filter state for a specific toggle button.
*

View File

@ -48,8 +48,8 @@ function goUpdateConsoleCommands() {
<command id="cmd_close" oncommand="goDoCommand('cmd_close');" disabled="true"/>
</commandset>
<keyset id="consoleKeys">
<key id="key_fullZoomReduce" key="&fullZoomReduceCmd.commandkey;" command="cmd_fullZoomReduce" modifiers="accel"/>
<key key="&fullZoomReduceCmd.commandkey2;" command="cmd_fullZoomReduce" modifiers="accel"/>
<key id="key_fullZoomReduce" key="&fullZoomReduceCmd.commandkey;" command="cmd_fullZoomReduce" modifiers="accel"/>
<key key="&fullZoomReduceCmd.commandkey2;" command="cmd_fullZoomReduce" modifiers="accel"/>
<key id="key_fullZoomEnlarge" key="&fullZoomEnlargeCmd.commandkey;" command="cmd_fullZoomEnlarge" modifiers="accel"/>
<key key="&fullZoomEnlargeCmd.commandkey2;" command="cmd_fullZoomEnlarge" modifiers="accel"/>
<key key="&fullZoomEnlargeCmd.commandkey3;" command="cmd_fullZoomEnlarge" modifiers="accel"/>