| Index: Source/devtools/front_end/KeyboardShortcut.js
|
| diff --git a/Source/devtools/front_end/KeyboardShortcut.js b/Source/devtools/front_end/KeyboardShortcut.js
|
| index 17897f032fe821b685b7456a4d4ffd452a67e3c1..70cc22eab22a60c8094ce60f89b21b16539c4327 100644
|
| --- a/Source/devtools/front_end/KeyboardShortcut.js
|
| +++ b/Source/devtools/front_end/KeyboardShortcut.js
|
| @@ -273,33 +273,47 @@ WebInspector.KeyboardShortcut._modifiersToString = function(modifiers)
|
|
|
| /**
|
| * @param {!KeyboardEvent} event
|
| + * @param {string} context
|
| */
|
| -WebInspector.KeyboardShortcut.handleShortcut = function(event)
|
| +WebInspector.KeyboardShortcut.handleShortcut = function(event, context)
|
| {
|
| var key = WebInspector.KeyboardShortcut.makeKeyFromEvent(event);
|
| - var extensions = WebInspector.KeyboardShortcut._keysToActionExtensions[key];
|
| - if (!extensions)
|
| + var entries = WebInspector.KeyboardShortcut._keyToAction[key];
|
| + if (!entries)
|
| return;
|
|
|
| - function handler(extension)
|
| - {
|
| - var result = extension.instance().handleAction(event);
|
| - if (result)
|
| - event.consume(true);
|
| - delete WebInspector.KeyboardShortcut._pendingActionTimer;
|
| - return result;
|
| - }
|
| -
|
| - for (var i = 0; i < extensions.length; ++i) {
|
| + for (var i = 0; i < entries.length; ++i) {
|
| + var entry = entries[i];
|
| + if (entry.context && entry.context !== context)
|
| + continue;
|
| var ident = event.keyIdentifier;
|
| if (/^F\d+|Control|Shift|Alt|Meta|Win|U\+001B$/.test(ident) || event.ctrlKey || event.altKey || event.metaKey) {
|
| - if (handler(extensions[i]))
|
| + if (handler(entry.actionId))
|
| return;
|
| } else {
|
| - WebInspector.KeyboardShortcut._pendingActionTimer = setTimeout(handler.bind(null, extensions[i]), 0);
|
| + WebInspector.KeyboardShortcut._pendingActionTimer = setTimeout(handler.bind(null, entry.actionId), 0);
|
| break;
|
| }
|
| }
|
| +
|
| + function actionRegistry()
|
| + {
|
| + if (!WebInspector.KeyboardShortcut._actionRegistry)
|
| + WebInspector.KeyboardShortcut._actionRegistry = WebInspector.moduleManager.instance(WebInspector.ActionRegistryAPI);
|
| + return WebInspector.KeyboardShortcut._actionRegistry;
|
| + }
|
| +
|
| + /**
|
| + * @param {string} actionId
|
| + */
|
| + function handler(actionId)
|
| + {
|
| + var result = actionRegistry().execute(actionId, event);
|
| + if (result)
|
| + event.consume(true);
|
| + delete WebInspector.KeyboardShortcut._pendingActionTimer;
|
| + return result;
|
| + }
|
| }
|
|
|
| WebInspector.KeyboardShortcut.SelectAll = WebInspector.KeyboardShortcut.makeKey("a", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta);
|
| @@ -316,40 +330,57 @@ WebInspector.KeyboardShortcut._onKeyPress = function(event)
|
| }
|
| }
|
|
|
| -WebInspector.KeyboardShortcut.registerActions = function()
|
| +WebInspector.KeyboardShortcut.registerBindings = function()
|
| {
|
| document.addEventListener("keypress", WebInspector.KeyboardShortcut._onKeyPress, true);
|
| - WebInspector.KeyboardShortcut._keysToActionExtensions = {};
|
| - var extensions = WebInspector.moduleManager.extensions(WebInspector.ActionDelegate);
|
| - extensions.forEach(registerBindings);
|
| + WebInspector.KeyboardShortcut._keyToAction = {};
|
| + var extensions = WebInspector.moduleManager.extensions("action-bindings");
|
| + extensions.forEach(registerExtension);
|
| +
|
| + for (var key in WebInspector.KeyboardShortcut._keyToAction)
|
| + WebInspector.KeyboardShortcut._keyToAction[key].sort(comparator);
|
| +
|
| + /**
|
| + * @param {{context: (string|undefined), actionId: string}} left
|
| + * @param {{context: (string|undefined), actionId: string}} right
|
| + */
|
| + function comparator(left, right)
|
| + {
|
| + if (left.context)
|
| + return right.context ? 0 : -1;
|
| + else
|
| + return right.context ? 1 : 0;
|
| + }
|
|
|
| /**
|
| * @param {!WebInspector.ModuleManager.Extension} extension
|
| */
|
| - function registerBindings(extension)
|
| + function registerExtension(extension)
|
| {
|
| var bindings = extension.descriptor().bindings;
|
| for (var i = 0; bindings && i < bindings.length; ++i) {
|
| if (!platformMatches(bindings[i].platform))
|
| continue;
|
| var shortcuts = bindings[i].shortcut.split(/\s+/);
|
| - shortcuts.forEach(registerShortcut.bind(null, extension));
|
| + shortcuts.forEach(registerShortcut.bind(null, bindings[i]["actionId"], bindings[i].context));
|
| }
|
| }
|
|
|
| /**
|
| - * @param {!WebInspector.ModuleManager.Extension} extension
|
| + * @param {string} actionId
|
| + * @param {string|undefined} context
|
| * @param {string} shortcut
|
| */
|
| - function registerShortcut(extension, shortcut)
|
| + function registerShortcut(actionId, context, shortcut)
|
| {
|
| var key = WebInspector.KeyboardShortcut.makeKeyFromBindingShortcut(shortcut);
|
| if (!key)
|
| return;
|
| - if (WebInspector.KeyboardShortcut._keysToActionExtensions[key])
|
| - WebInspector.KeyboardShortcut._keysToActionExtensions[key].push(extension);
|
| + var entry = { context: context, actionId: actionId };
|
| + if (WebInspector.KeyboardShortcut._keyToAction[key])
|
| + WebInspector.KeyboardShortcut._keyToAction[key].push(entry);
|
| else
|
| - WebInspector.KeyboardShortcut._keysToActionExtensions[key] = [extension];
|
| + WebInspector.KeyboardShortcut._keyToAction[key] = [entry];
|
| }
|
|
|
| /**
|
|
|