Converting remaining webview commands to use Action2

For #89348
This commit is contained in:
Matt Bierner 2020-02-05 18:26:04 -08:00
parent 8847219dd7
commit 9a74df8b7c
3 changed files with 49 additions and 42 deletions

View file

@ -22,7 +22,6 @@ export class ShowWebViewEditorFindWidgetAction extends Action2 {
super({
id: ShowWebViewEditorFindWidgetAction.ID,
title: ShowWebViewEditorFindWidgetAction.LABEL,
precondition: contextKeyExpr,
keybinding: {
when: contextKeyExpr,
primary: KeyMod.CtrlCmd | KeyCode.KEY_F,
@ -41,13 +40,11 @@ export class HideWebViewEditorFindCommand extends Action2 {
public static readonly LABEL = nls.localize('editor.action.webvieweditor.hideFind', "Stop find");
constructor(contextKeyExpr: ContextKeyExpr) {
const precondition = ContextKeyExpr.and(contextKeyExpr, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE);
super({
id: HideWebViewEditorFindCommand.ID,
title: HideWebViewEditorFindCommand.LABEL,
precondition: precondition,
keybinding: {
when: precondition,
when: ContextKeyExpr.and(contextKeyExpr, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE),
primary: KeyCode.Escape,
weight: KeybindingWeight.EditorContrib
}
@ -64,13 +61,11 @@ export class WebViewEditorFindNextCommand extends Action2 {
public static readonly LABEL = nls.localize('editor.action.webvieweditor.findNext', 'Find next');
constructor(contextKeyExpr: ContextKeyExpr) {
const precondition = ContextKeyExpr.and(contextKeyExpr, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED);
super({
id: WebViewEditorFindNextCommand.ID,
title: WebViewEditorFindNextCommand.LABEL,
precondition: precondition,
keybinding: {
when: precondition,
when: ContextKeyExpr.and(contextKeyExpr, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED),
primary: KeyCode.Enter,
weight: KeybindingWeight.EditorContrib
}
@ -87,13 +82,11 @@ export class WebViewEditorFindPreviousCommand extends Action2 {
public static readonly LABEL = nls.localize('editor.action.webvieweditor.findPrevious', 'Find previous');
constructor(contextKeyExpr: ContextKeyExpr) {
const precondition = ContextKeyExpr.and(contextKeyExpr, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED);
super({
id: WebViewEditorFindPreviousCommand.ID,
title: WebViewEditorFindPreviousCommand.LABEL,
precondition: precondition,
keybinding: {
when: precondition,
when: ContextKeyExpr.and(contextKeyExpr, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED),
primary: KeyMod.Shift | KeyCode.Enter,
weight: KeybindingWeight.EditorContrib
}

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { isMacintosh } from 'vs/base/common/platform';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { SyncActionDescriptor, registerAction2 } from 'vs/platform/actions/common/actions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { Registry } from 'vs/platform/registry/common/platform';
@ -26,15 +26,15 @@ actionRegistry.registerWorkbenchAction(
function registerWebViewCommands(editorId: string): void {
const contextKeyExpr = ContextKeyExpr.and(ContextKeyExpr.equals('activeEditor', editorId), ContextKeyExpr.not('editorFocus') /* https://github.com/Microsoft/vscode/issues/58668 */)!;
new webviewCommands.SelectAllWebviewEditorCommand(contextKeyExpr).register();
registerAction2(class extends webviewCommands.SelectAllWebviewEditorCommand { constructor() { super(contextKeyExpr); } });
// These commands are only needed on MacOS where we have to disable the menu bar commands
if (isMacintosh) {
new webviewCommands.CopyWebviewEditorCommand(contextKeyExpr).register();
new webviewCommands.PasteWebviewEditorCommand(contextKeyExpr).register();
new webviewCommands.CutWebviewEditorCommand(contextKeyExpr).register();
new webviewCommands.UndoWebviewEditorCommand(contextKeyExpr).register();
new webviewCommands.RedoWebviewEditorCommand(contextKeyExpr).register();
registerAction2(class extends webviewCommands.CopyWebviewEditorCommand { constructor() { super(contextKeyExpr); } });
registerAction2(class extends webviewCommands.PasteWebviewEditorCommand { constructor() { super(contextKeyExpr); } });
registerAction2(class extends webviewCommands.CutWebviewEditorCommand { constructor() { super(contextKeyExpr); } });
registerAction2(class extends webviewCommands.UndoWebviewEditorCommand { constructor() { super(contextKeyExpr); } });
registerAction2(class extends webviewCommands.RedoWebviewEditorCommand { constructor() { super(contextKeyExpr); } });
}
}

View file

@ -6,8 +6,9 @@
import { WebviewTag } from 'electron';
import { Action } from 'vs/base/common/actions';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { Command, ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import * as nls from 'vs/nls';
import { Action2 } from 'vs/platform/actions/common/actions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
@ -37,109 +38,122 @@ export class OpenWebviewDeveloperToolsAction extends Action {
}
}
export class SelectAllWebviewEditorCommand extends Command {
export class SelectAllWebviewEditorCommand extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.selectAll';
public static readonly LABEL = nls.localize('editor.action.webvieweditor.selectAll', 'Select all');
constructor(contextKeyExpr: ContextKeyExpr) {
const precondition = ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey));
super({
id: SelectAllWebviewEditorCommand.ID,
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
kbOpts: {
title: SelectAllWebviewEditorCommand.LABEL,
keybinding: {
when: precondition,
primary: KeyMod.CtrlCmd | KeyCode.KEY_A,
weight: KeybindingWeight.EditorContrib
}
});
}
public runCommand(accessor: ServicesAccessor, args: any): void {
public run(accessor: ServicesAccessor, args: any): void {
withActiveWebviewBasedWebview(accessor, webview => webview.selectAll());
}
}
export class CopyWebviewEditorCommand extends Command {
export class CopyWebviewEditorCommand extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.copy';
public static readonly LABEL = nls.localize('editor.action.webvieweditor.copy', "Copy2");
constructor(contextKeyExpr: ContextKeyExpr) {
super({
id: CopyWebviewEditorCommand.ID,
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
kbOpts: {
title: CopyWebviewEditorCommand.LABEL,
keybinding: {
when: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
primary: KeyMod.CtrlCmd | KeyCode.KEY_C,
weight: KeybindingWeight.EditorContrib
}
});
}
public runCommand(accessor: ServicesAccessor, _args: any): void {
public run(accessor: ServicesAccessor): void {
withActiveWebviewBasedWebview(accessor, webview => webview.copy());
}
}
export class PasteWebviewEditorCommand extends Command {
export class PasteWebviewEditorCommand extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.paste';
public static readonly LABEL = nls.localize('editor.action.webvieweditor.paste', 'Paste');
constructor(contextKeyExpr: ContextKeyExpr) {
super({
id: PasteWebviewEditorCommand.ID,
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
kbOpts: {
title: PasteWebviewEditorCommand.LABEL,
keybinding: {
when: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
primary: KeyMod.CtrlCmd | KeyCode.KEY_V,
weight: KeybindingWeight.EditorContrib
}
});
}
public runCommand(accessor: ServicesAccessor, _args: any): void {
public run(accessor: ServicesAccessor): void {
withActiveWebviewBasedWebview(accessor, webview => webview.paste());
}
}
export class CutWebviewEditorCommand extends Command {
export class CutWebviewEditorCommand extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.cut';
public static readonly LABEL = nls.localize('editor.action.webvieweditor.cut', 'Cut');
constructor(contextKeyExpr: ContextKeyExpr) {
super({
id: CutWebviewEditorCommand.ID,
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
kbOpts: {
title: CutWebviewEditorCommand.LABEL,
keybinding: {
when: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey)),
primary: KeyMod.CtrlCmd | KeyCode.KEY_X,
weight: KeybindingWeight.EditorContrib
}
});
}
public runCommand(accessor: ServicesAccessor, _args: any): void {
public run(accessor: ServicesAccessor): void {
withActiveWebviewBasedWebview(accessor, webview => webview.cut());
}
}
export class UndoWebviewEditorCommand extends Command {
export class UndoWebviewEditorCommand extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.undo';
public static readonly LABEL = nls.localize('editor.action.webvieweditor.undo', "Undo");
constructor(contextKeyExpr: ContextKeyExpr) {
super({
id: UndoWebviewEditorCommand.ID,
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey), ContextKeyExpr.not(webviewHasOwnEditFunctionsContextKey)),
kbOpts: {
title: UndoWebviewEditorCommand.LABEL,
keybinding: {
when: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey), ContextKeyExpr.not(webviewHasOwnEditFunctionsContextKey)),
primary: KeyMod.CtrlCmd | KeyCode.KEY_Z,
weight: KeybindingWeight.EditorContrib
}
});
}
public runCommand(accessor: ServicesAccessor, args: any): void {
public run(accessor: ServicesAccessor, args: any): void {
withActiveWebviewBasedWebview(accessor, webview => webview.undo());
}
}
export class RedoWebviewEditorCommand extends Command {
export class RedoWebviewEditorCommand extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.redo';
public static readonly LABEL = nls.localize('editor.action.webvieweditor.redo', "Redo");
constructor(contextKeyExpr: ContextKeyExpr) {
super({
id: RedoWebviewEditorCommand.ID,
precondition: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey), ContextKeyExpr.not(webviewHasOwnEditFunctionsContextKey)),
kbOpts: {
title: RedoWebviewEditorCommand.LABEL,
keybinding: {
when: ContextKeyExpr.and(contextKeyExpr, ContextKeyExpr.not(InputFocusedContextKey), ContextKeyExpr.not(webviewHasOwnEditFunctionsContextKey)),
primary: KeyMod.CtrlCmd | KeyCode.KEY_Y,
secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z],
mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z },
@ -148,7 +162,7 @@ export class RedoWebviewEditorCommand extends Command {
});
}
public runCommand(accessor: ServicesAccessor, args: any): void {
public run(accessor: ServicesAccessor, args: any): void {
withActiveWebviewBasedWebview(accessor, webview => webview.redo());
}
}