зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1359855 - Fix support of per tool key shortcuts in toolboxes opened in a window. r=jdescottes
MozReview-Commit-ID: kP07KzpzxI --HG-- extra : rebase_source : 4135af713a11f1f96f00be92cd88b707627c22cd
This commit is contained in:
Родитель
80498fc6b9
Коммит
fd1ca6efba
|
@ -184,6 +184,7 @@ DevToolsStartup.prototype = {
|
|||
this.handleDebuggerServerFlag(cmdLine, debuggerServerFlag);
|
||||
}
|
||||
|
||||
// Only top level Firefox Windows fire a browser-delayed-startup-finished event
|
||||
let onWindowReady = window => {
|
||||
this.hookWindow(window);
|
||||
|
||||
|
@ -512,6 +513,15 @@ DevToolsStartup.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
// Used by tests and the toolbox to register the same key shortcuts in toolboxes loaded
|
||||
// in a window window.
|
||||
get KeyShortcuts() {
|
||||
return KeyShortcuts;
|
||||
},
|
||||
get wrappedJSObject() {
|
||||
return this;
|
||||
},
|
||||
|
||||
/* eslint-disable max-len */
|
||||
helpInfo: " --jsconsole Open the Browser Console.\n" +
|
||||
" --jsdebugger Open the Browser Toolbox.\n" +
|
||||
|
|
|
@ -5,28 +5,33 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var Startup = Cc["@mozilla.org/devtools/startup-clh;1"].getService(Ci.nsISupports)
|
||||
.wrappedJSObject;
|
||||
var {Toolbox} = require("devtools/client/framework/toolbox");
|
||||
|
||||
var toolbox, toolIDs, idIndex, modifiedPrefs = [];
|
||||
var toolbox, toolIDs, toolShortcuts = [], idIndex, modifiedPrefs = [];
|
||||
|
||||
function test() {
|
||||
addTab("about:blank").then(function () {
|
||||
toolIDs = [];
|
||||
for (let [id, definition] of gDevTools._tools) {
|
||||
if (definition.key) {
|
||||
toolIDs.push(id);
|
||||
let shortcut = Startup.KeyShortcuts.filter(s => s.toolId == id)[0];
|
||||
if (!shortcut) {
|
||||
continue;
|
||||
}
|
||||
toolIDs.push(id);
|
||||
toolShortcuts.push(shortcut);
|
||||
|
||||
// Enable disabled tools
|
||||
let pref = definition.visibilityswitch, prefValue;
|
||||
try {
|
||||
prefValue = Services.prefs.getBoolPref(pref);
|
||||
} catch (e) {
|
||||
continue;
|
||||
}
|
||||
if (!prefValue) {
|
||||
modifiedPrefs.push(pref);
|
||||
Services.prefs.setBoolPref(pref, true);
|
||||
}
|
||||
// Enable disabled tools
|
||||
let pref = definition.visibilityswitch, prefValue;
|
||||
try {
|
||||
prefValue = Services.prefs.getBoolPref(pref);
|
||||
} catch (e) {
|
||||
continue;
|
||||
}
|
||||
if (!prefValue) {
|
||||
modifiedPrefs.push(pref);
|
||||
Services.prefs.setBoolPref(pref, true);
|
||||
}
|
||||
}
|
||||
let target = TargetFactory.forTab(gBrowser.selectedTab);
|
||||
|
@ -49,8 +54,9 @@ function testShortcuts(aToolbox, aIndex) {
|
|||
|
||||
toolbox.once("select", selectCB);
|
||||
|
||||
let key = gDevTools._tools.get(toolIDs[aIndex]).key;
|
||||
let toolModifiers = gDevTools._tools.get(toolIDs[aIndex]).modifiers;
|
||||
let shortcut = toolShortcuts[aIndex];
|
||||
let key = shortcut.shortcut;
|
||||
let toolModifiers = shortcut.modifiers;
|
||||
let modifiers = {
|
||||
accelKey: toolModifiers.includes("accel"),
|
||||
altKey: toolModifiers.includes("alt"),
|
||||
|
|
|
@ -14,7 +14,7 @@ const HOST_HISTOGRAM = "DEVTOOLS_TOOLBOX_HOST";
|
|||
const SCREENSIZE_HISTOGRAM = "DEVTOOLS_SCREEN_RESOLUTION_ENUMERATED_PER_USER";
|
||||
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
||||
|
||||
var {Ci, Cu} = require("chrome");
|
||||
var {Ci, Cu, Cc} = require("chrome");
|
||||
var promise = require("promise");
|
||||
var defer = require("devtools/shared/defer");
|
||||
var Services = require("Services");
|
||||
|
@ -27,6 +27,8 @@ var Menu = require("devtools/client/framework/menu");
|
|||
var MenuItem = require("devtools/client/framework/menu-item");
|
||||
var { DOMHelpers } = require("resource://devtools/client/shared/DOMHelpers.jsm");
|
||||
const { KeyCodes } = require("devtools/client/shared/keycodes");
|
||||
var Startup = Cc["@mozilla.org/devtools/startup-clh;1"].getService(Ci.nsISupports)
|
||||
.wrappedJSObject;
|
||||
|
||||
const { BrowserLoader } =
|
||||
Cu.import("resource://devtools/client/shared/browser-loader.js", {});
|
||||
|
@ -857,24 +859,25 @@ Toolbox.prototype = {
|
|||
|
||||
let doc = this.win.parent.document;
|
||||
|
||||
for (let [id, toolDefinition] of gDevTools.getToolDefinitionMap()) {
|
||||
// Prevent multiple entries for the same tool.
|
||||
if (!toolDefinition.key || doc.getElementById("key_" + id)) {
|
||||
for (let item of Startup.KeyShortcuts) {
|
||||
// KeyShortcuts contain tool-specific and global key shortcuts,
|
||||
// here we only need to copy shortcut specific to each tool.
|
||||
if (!item.toolId) {
|
||||
continue;
|
||||
}
|
||||
let { toolId, shortcut, modifiers } = item;
|
||||
|
||||
let toolId = id;
|
||||
let key = doc.createElement("key");
|
||||
|
||||
key.id = "key_" + toolId;
|
||||
|
||||
if (toolDefinition.key.startsWith("VK_")) {
|
||||
key.setAttribute("keycode", toolDefinition.key);
|
||||
if (shortcut.startsWith("VK_")) {
|
||||
key.setAttribute("keycode", shortcut);
|
||||
} else {
|
||||
key.setAttribute("key", toolDefinition.key);
|
||||
key.setAttribute("key", shortcut);
|
||||
}
|
||||
|
||||
key.setAttribute("modifiers", toolDefinition.modifiers);
|
||||
key.setAttribute("modifiers", modifiers);
|
||||
// needed. See bug 371900
|
||||
key.setAttribute("oncommand", "void(0);");
|
||||
key.addEventListener("command", () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче