1
>
/*---------------------------------------------------------------------------------------------
actions.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { Emitter, Event } from './event.js';
7
>
import { Disposable, IDisposable } from './lifecycle.js';
8
>
import * as nls from '../../nls.js';
9
>
10
>
export interface ITelemetryData {
11
>
readonly from?: string;
12
>
readonly target?: string;
13
>
[key: string]: unknown;
14
>
}
15
>
16
>
export type WorkbenchActionExecutedClassification = {
17
>
id: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The identifier of the action that was run.' };
18
>
from: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The name of the component the action was run from.' };
19
>
detail?: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Optional details about how the action was run, e.g which keybinding was used.' };
20
>
owner: 'isidorn';
21
>
comment: 'Provides insight into actions that are executed within the workbench.';
22
>
};
23
>
24
>
export type WorkbenchActionExecutedEvent = {
25
>
id: string;
26
>
from: string;
27
>
detail?: string;
28
>
};
29
>
30
>
export interface IAction {
31
>
readonly id: string;
32
>
label: string;
33
>
tooltip: string;
34
>
class: string | undefined;
35
>
enabled: boolean;
36
>
checked?: boolean;
37
>
run(...args: unknown[]): unknown;
38
>
}
39
>
40
>
export interface IActionRunner extends IDisposable {
41
>
readonly onDidRun: Event<IRunEvent>;
42
>
readonly onWillRun: Event<IRunEvent>;
43
>
44
>
run(action: IAction, context?: unknown): unknown;
45
>
}
46
>
47
>
export interface IActionChangeEvent {
48
>
readonly label?: string;
49
>
readonly tooltip?: string;
50
>
readonly class?: string;
51
>
readonly enabled?: boolean;
52
>
readonly checked?: boolean;
53
>
}
54
>
55
>
/**
56
>
* A concrete implementation of {@link IAction}.
57
>
*
58
>
* Note that in most cases you should use the lighter-weight {@linkcode toAction} function instead.
59
>
*/
60
>
export class Action extends Disposable implements IAction {
61
>
62
>
protected _onDidChange = this._register(new Emitter<IActionChangeEvent>());
63
>
get onDidChange() { return this._onDidChange.event; }
64
>
65
>
protected readonly _id: string;
66
>
protected _label: string;
67
>
protected _tooltip: string | undefined;
68
>
protected _cssClass: string | undefined;
69
>
protected _enabled: boolean = true;
70
>
protected _checked?: boolean;
71
>
protected readonly _actionCallback?: (event?: unknown) => unknown;
72
>
73
>
constructor(id: string, label: string = '', cssClass: string = '', enabled: boolean = true, actionCallback?: (event?: unknown) => unknown) {
74
super();
75
this._id = id;