forked from irinazheltisheva/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditorAction.ts
More file actions
46 lines (38 loc) · 1.4 KB
/
Copy patheditorAction.ts
File metadata and controls
46 lines (38 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IEditorAction } from 'vs/editor/common/editorCommon';
import { IContextKeyService, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';
export class InternalEditorAction implements IEditorAction {
public readonly id: string;
public readonly label: string;
public readonly alias: string;
private readonly _precondition: ContextKeyExpression | undefined;
private readonly _run: () => Promise<void>;
private readonly _contextKeyService: IContextKeyService;
constructor(
id: string,
label: string,
alias: string,
precondition: ContextKeyExpression | undefined,
run: () => Promise<void>,
contextKeyService: IContextKeyService
) {
this.id = id;
this.label = label;
this.alias = alias;
this._precondition = precondition;
this._run = run;
this._contextKeyService = contextKeyService;
}
public isSupported(): boolean {
return this._contextKeyService.contextMatchesRules(this._precondition);
}
public run(): Promise<void> {
if (!this.isSupported()) {
return Promise.resolve(undefined);
}
return this._run();
}
}