-
Notifications
You must be signed in to change notification settings - Fork 29.4k
/
action.ts
97 lines (78 loc) · 2.79 KB
/
action.ts
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { URI, UriDto } from 'vs/base/common/uri';
import { ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';
import { ThemeIcon } from 'vs/base/common/themables';
import { Categories } from './actionCommonCategories';
import { ICommandMetadata } from 'vs/platform/commands/common/commands';
export interface ILocalizedString {
/**
* The localized value of the string.
*/
value: string;
/**
* The original (non localized value of the string)
*/
original: string;
}
export function isLocalizedString(thing: any): thing is ILocalizedString {
return thing
&& typeof thing === 'object'
&& typeof thing.original === 'string'
&& typeof thing.value === 'string';
}
export interface ICommandActionTitle extends ILocalizedString {
/**
* The title with a mnemonic designation. && precedes the mnemonic.
*/
mnemonicTitle?: string;
}
export type Icon = { dark?: URI; light?: URI } | ThemeIcon;
export interface ICommandActionToggleInfo {
/**
* The condition that marks the action as toggled.
*/
condition: ContextKeyExpression;
icon?: Icon;
tooltip?: string;
/**
* The title that goes well with a a check mark, e.g "(check) Line Numbers" vs "Toggle Line Numbers"
*/
title?: string;
/**
* Like title but with a mnemonic designation.
*/
mnemonicTitle?: string;
}
export function isICommandActionToggleInfo(thing: ContextKeyExpression | ICommandActionToggleInfo | undefined): thing is ICommandActionToggleInfo {
return thing ? (<ICommandActionToggleInfo>thing).condition !== undefined : false;
}
export interface ICommandActionSource {
readonly id: string;
readonly title: string;
}
export interface ICommandAction {
id: string;
title: string | ICommandActionTitle;
shortTitle?: string | ICommandActionTitle;
/**
* Metadata about this command, used for:
* - API commands
* - when showing keybindings that have no other UX
* - when searching for commands in the Command Palette
*/
metadata?: ICommandMetadata;
category?: keyof typeof Categories | ILocalizedString | string;
tooltip?: string | ILocalizedString;
icon?: Icon;
source?: ICommandActionSource;
precondition?: ContextKeyExpression;
/**
* The action is a toggle action. Define the context key expression that reflects its toggle-state
* or define toggle-info including an icon and a title that goes well with a checkmark.
*/
toggled?: ContextKeyExpression | ICommandActionToggleInfo;
}
export type ISerializableCommandAction = UriDto<ICommandAction>;