From 844c58d405c5e8da635bcb66ab09cd24bb2fe3da Mon Sep 17 00:00:00 2001 From: Andres Olivares Date: Tue, 26 Jan 2021 13:09:07 +0000 Subject: [PATCH] [module.json extensions] console actions Bug: 1134103 Change-Id: I6b03d3202df9bc5dc9b46b33dd95a93b2b5c777b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2648907 Commit-Queue: Andres Olivares Reviewed-by: Tim van der Lippe --- front_end/console/ConsoleView.js | 17 ++++++++ front_end/console/console-meta.ts | 70 ++++++++++++++++++++++++++++++ front_end/console/module.json | 51 ---------------------- front_end/ui/ActionRegistration.ts | 7 ++- 4 files changed, 92 insertions(+), 53 deletions(-) diff --git a/front_end/console/ConsoleView.js b/front_end/console/ConsoleView.js index f456c46061..5ce5b518ed 100644 --- a/front_end/console/ConsoleView.js +++ b/front_end/console/ConsoleView.js @@ -1671,6 +1671,9 @@ export class ConsoleGroup { } } +/** @type {!ActionDelegate} */ +let actionDelegateInstance; + /** * @implements {UI.ActionRegistration.ActionDelegate} */ @@ -1700,6 +1703,20 @@ export class ActionDelegate { } return false; } + + /** + * @param {{forceNew: ?boolean}=} opts + * @return {!ActionDelegate} + } + */ + static instance(opts = {forceNew: null}) { + const {forceNew} = opts; + if (!actionDelegateInstance || forceNew) { + actionDelegateInstance = new ActionDelegate(); + } + + return actionDelegateInstance; + } } /** @type {!WeakMap} */ diff --git a/front_end/console/console-meta.ts b/front_end/console/console-meta.ts index ee2931a3c9..f40745a553 100644 --- a/front_end/console/console-meta.ts +++ b/front_end/console/console-meta.ts @@ -21,6 +21,13 @@ async function loadConsoleModule(): Promise { return loadedConsoleModule; } +function maybeRetrieveContextTypes(getClassCallBack: (consoleModule: typeof Console) => T[]): T[] { + if (loadedConsoleModule === undefined) { + return []; + } + return getClassCallBack(loadedConsoleModule); +} + UI.ViewManager.registerViewExtension({ location: UI.ViewManager.ViewLocationValues.PANEL, id: 'console', @@ -45,3 +52,66 @@ UI.ViewManager.registerViewExtension({ return Console.ConsolePanel.WrapperView.instance(); }, }); + +UI.ActionRegistration.registerActionExtension({ + actionId: 'console.show', + category: UI.ActionRegistration.ActionCategory.CONSOLE, + title: (): Platform.UIString.LocalizedString => ls`Show Console`, + async loadActionDelegate() { + const Console = await loadConsoleModule(); + return Console.ConsoleView.ActionDelegate.instance(); + }, + bindings: [ + { + shortcut: 'Ctrl+`', + keybindSets: [ + UI.ActionRegistration.KeybindSet.DEVTOOLS_DEFAULT, + UI.ActionRegistration.KeybindSet.VS_CODE, + ], + }, + ], +}); + +UI.ActionRegistration.registerActionExtension({ + actionId: 'console.clear', + category: UI.ActionRegistration.ActionCategory.CONSOLE, + title: (): Platform.UIString.LocalizedString => ls`Clear console`, + iconClass: UI.ActionRegistration.IconClass.LARGEICON_CLEAR, + async loadActionDelegate() { + const Console = await loadConsoleModule(); + return Console.ConsoleView.ActionDelegate.instance(); + }, + contextTypes() { + return maybeRetrieveContextTypes(Console => [Console.ConsoleView.ConsoleView]); + }, + bindings: [ + { + shortcut: 'Ctrl+L', + }, + { + shortcut: 'Meta+K', + platform: UI.ActionRegistration.Platforms.Mac, + }, + ], +}); + +UI.ActionRegistration.registerActionExtension({ + actionId: 'console.clear.history', + category: UI.ActionRegistration.ActionCategory.CONSOLE, + title: (): Platform.UIString.LocalizedString => ls`Clear console history`, + async loadActionDelegate() { + const Console = await loadConsoleModule(); + return Console.ConsoleView.ActionDelegate.instance(); + }, +}); + +UI.ActionRegistration.registerActionExtension({ + actionId: 'console.create-pin', + category: UI.ActionRegistration.ActionCategory.CONSOLE, + title: (): Platform.UIString.LocalizedString => ls`Create live expression`, + iconClass: UI.ActionRegistration.IconClass.LARGEICON_VISIBILITY, + async loadActionDelegate() { + const Console = await loadConsoleModule(); + return Console.ConsoleView.ActionDelegate.instance(); + }, +}); diff --git a/front_end/console/module.json b/front_end/console/module.json index a8cb82eec3..ad37c9e6dc 100644 --- a/front_end/console/module.json +++ b/front_end/console/module.json @@ -7,57 +7,6 @@ ], "className": "Console.ConsolePanel.ConsoleRevealer" }, - { - "type": "action", - "actionId": "console.show", - "category": "Console", - "title": "Show Console", - "className": "Console.ConsoleView.ActionDelegate", - "bindings": [ - { - "shortcut": "Ctrl+`", - "keybindSets": [ - "devToolsDefault", - "vsCode" - ] - } - ] - }, - { - "type": "action", - "category": "Console", - "contextTypes": [ - "Console.ConsoleView" - ], - "actionId": "console.clear", - "title": "Clear console", - "iconClass": "largeicon-clear", - "className": "Console.ConsoleView.ActionDelegate", - "bindings": [ - { - "shortcut": "Ctrl+L" - }, - { - "platform": "mac", - "shortcut": "Meta+K" - } - ] - }, - { - "type": "action", - "category": "Console", - "actionId": "console.clear.history", - "title": "Clear console history", - "className": "Console.ConsoleView.ActionDelegate" - }, - { - "type": "action", - "category": "Console", - "actionId": "console.create-pin", - "iconClass": "largeicon-visibility", - "className": "Console.ConsoleView.ActionDelegate", - "title": "Create live expression" - }, { "type": "setting", "category": "Console", diff --git a/front_end/ui/ActionRegistration.ts b/front_end/ui/ActionRegistration.ts index d9da7f7b94..136026bc18 100644 --- a/front_end/ui/ActionRegistration.ts +++ b/front_end/ui/ActionRegistration.ts @@ -316,6 +316,7 @@ export const ActionCategory = { NETWORK: ls`Network`, MEMORY: ls`Memory`, JAVASCRIPT_PROFILER: ls`JavaScript Profiler`, + CONSOLE: ls`Console`, }; type ActionCategory = typeof ActionCategory[keyof typeof ActionCategory]; @@ -325,6 +326,8 @@ export const enum IconClass { LARGEICON_START_RECORDING = 'largeicon-start-recording', LARGEICON_STOP_RECORDING = 'largeicon-stop-recording', LARGEICON_REFRESH = 'largeicon-refresh', + LARGEICON_CLEAR = 'largeicon-clear', + LARGEICON_VISIBILITY = 'largeicon-visibility', } export const enum KeybindSet { @@ -363,11 +366,11 @@ export interface ActionRegistration { /** * The type of the icon used to trigger the action. */ - iconClass?: string; + iconClass?: IconClass; /** * Whether the style of the icon toggles on interaction. */ - toggledIconClass?: string; + toggledIconClass?: IconClass; /** * Whether the class 'toolbar-toggle-with-red-color' is toggled on the icon on interaction. */