Files
vscode/src/vs/workbench/contrib/codeEditor/browser/toggleRenderControlCharacter.ts
T
Matt Bierner 36a8322ae8 Convert SyncActionDescriptor to use a create function (#84878)
For #81574

See #84669 for details of the problem around strict function types. This change converts `SyncActionDescriptor` to use a static `create` function. This allows us to make the `create` function generic so that it can take the correct types for strictFunctionTypes
2019-11-14 16:49:25 -08:00

45 lines
2.2 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { Action } from 'vs/base/common/actions';
import { MenuId, MenuRegistry, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions';
export class ToggleRenderControlCharacterAction extends Action {
public static readonly ID = 'editor.action.toggleRenderControlCharacter';
public static readonly LABEL = nls.localize('toggleRenderControlCharacters', "Toggle Control Characters");
constructor(
id: string,
label: string,
@IConfigurationService private readonly _configurationService: IConfigurationService
) {
super(id, label);
}
public run(): Promise<any> {
let newRenderControlCharacters = !this._configurationService.getValue<boolean>('editor.renderControlCharacters');
return this._configurationService.updateValue('editor.renderControlCharacters', newRenderControlCharacters, ConfigurationTarget.USER);
}
}
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
registry.registerWorkbenchAction(SyncActionDescriptor.create(ToggleRenderControlCharacterAction, ToggleRenderControlCharacterAction.ID, ToggleRenderControlCharacterAction.LABEL), 'View: Toggle Control Characters', nls.localize('view', "View"));
MenuRegistry.appendMenuItem(MenuId.MenubarViewMenu, {
group: '5_editor',
command: {
id: ToggleRenderControlCharacterAction.ID,
title: nls.localize({ key: 'miToggleRenderControlCharacters', comment: ['&& denotes a mnemonic'] }, "Render &&Control Characters"),
toggled: ContextKeyExpr.equals('config.editor.renderControlCharacters', true)
},
order: 5
});