[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 <andoli@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
This commit is contained in:
Andres Olivares
2021-01-26 13:13:08 +00:00
committed by Commit Bot
parent 28eaf8cbb2
commit 844c58d405
4 changed files with 92 additions and 53 deletions
+17
View File
@@ -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<!ConsoleViewMessage, number>} */
+70
View File
@@ -21,6 +21,13 @@ async function loadConsoleModule(): Promise<typeof Console> {
return loadedConsoleModule;
}
function maybeRetrieveContextTypes<T = unknown>(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();
},
});
-51
View File
@@ -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",
+5 -2
View File
@@ -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.
*/