Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/browser/actions/helpActions.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
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 { localize, localize2 } from '../../../nls.js';
7
import product from '../../../platform/product/common/product.js';
8
import { isMacintosh, isLinux, language, isWeb } from '../../../base/common/platform.js';
9
import { ITelemetryService } from '../../../platform/telemetry/common/telemetry.js';
10
import { IOpenerService } from '../../../platform/opener/common/opener.js';
11
import { URI } from '../../../base/common/uri.js';
12
import { MenuId, Action2, registerAction2, MenuRegistry } from '../../../platform/actions/common/actions.js';
13
import { KeyChord, KeyMod, KeyCode } from '../../../base/common/keyCodes.js';
14
import { IProductService } from '../../../platform/product/common/productService.js';
15
import { ServicesAccessor } from '../../../platform/instantiation/common/instantiation.js';
16
import { KeybindingWeight } from '../../../platform/keybinding/common/keybindingsRegistry.js';
17
import { Categories } from '../../../platform/action/common/actionCommonCategories.js';
18
import { ICommandService } from '../../../platform/commands/common/commands.js';
19
import { ContextKeyExpr } from '../../../platform/contextkey/common/contextkey.js';
20
21
class KeybindingsReferenceAction extends Action2 {
22
23
static readonly ID = 'workbench.action.keybindingsReference';
24
static readonly AVAILABLE = !!(isLinux ? product.keyboardShortcutsUrlLinux : isMacintosh ? product.keyboardShortcutsUrlMac : product.keyboardShortcutsUrlWin);
25
26
constructor() {
27
super({
28
id: KeybindingsReferenceAction.ID,
29
title: {
30
...localize2('keybindingsReference', "Keyboard Shortcuts Reference"),
31
mnemonicTitle: localize({ key: 'miKeyboardShortcuts', comment: ['&& denotes a mnemonic'] }, "&&Keyboard Shortcuts Reference"),
32
},
33
category: Categories.Help,
34
f1: true,
35
keybinding: {
36
weight: KeybindingWeight.WorkbenchContrib,
37
when: null,
38
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyR)
39
},
40
menu: {
41
id: MenuId.MenubarHelpMenu,
42
group: '2_reference',
43
order: 1
44
}
45
});
46
}
47
48
run(accessor: ServicesAccessor): void {
49
const productService = accessor.get(IProductService);
50
const openerService = accessor.get(IOpenerService);
51
52
const url = isLinux ? productService.keyboardShortcutsUrlLinux : isMacintosh ? productService.keyboardShortcutsUrlMac : productService.keyboardShortcutsUrlWin;
53
if (url) {
54
openerService.open(URI.parse(url));
55
}
56
}
57
}
58
59
class OpenIntroductoryVideosUrlAction extends Action2 {
60
61
static readonly ID = 'workbench.action.openVideoTutorialsUrl';
62
static readonly AVAILABLE = !!product.introductoryVideosUrl;
63
64
constructor() {
65
super({
66
id: OpenIntroductoryVideosUrlAction.ID,
67
title: {
68
...localize2('openVideoTutorialsUrl', "Video Tutorials"),
69
mnemonicTitle: localize({ key: 'miVideoTutorials', comment: ['&& denotes a mnemonic'] }, "&&Video Tutorials"),
70
},
71
category: Categories.Help,
72
f1: true,
73
menu: {
74
id: MenuId.MenubarHelpMenu,
75
group: '2_reference',
76
order: 2
77
}
78
});
79
}
80
81
run(accessor: ServicesAccessor): void {
82
const productService = accessor.get(IProductService);
83
const openerService = accessor.get(IOpenerService);
84
85
if (productService.introductoryVideosUrl) {
86
openerService.open(URI.parse(productService.introductoryVideosUrl));
87
}
88
}
89
}
90
91
class OpenTipsAndTricksUrlAction extends Action2 {
92
93
static readonly ID = 'workbench.action.openTipsAndTricksUrl';
94
static readonly AVAILABLE = !!product.tipsAndTricksUrl;
95
96
constructor() {
97
super({
98
id: OpenTipsAndTricksUrlAction.ID,
99
title: {
100
...localize2('openTipsAndTricksUrl', "Tips and Tricks"),
101
mnemonicTitle: localize({ key: 'miTipsAndTricks', comment: ['&& denotes a mnemonic'] }, "Tips and Tri&&cks"),
102
},
103
category: Categories.Help,
104
f1: true,
105
menu: {
106
id: MenuId.MenubarHelpMenu,
107
group: '2_reference',
108
order: 3
109
}
110
});
111
}
112
113
run(accessor: ServicesAccessor): void {
114
const productService = accessor.get(IProductService);
115
const openerService = accessor.get(IOpenerService);
116
117
if (productService.tipsAndTricksUrl) {
118
openerService.open(URI.parse(productService.tipsAndTricksUrl));
119
}
120
}
121
}
122
123
class OpenDocumentationUrlAction extends Action2 {
124
125
static readonly ID = 'workbench.action.openDocumentationUrl';
126
static readonly AVAILABLE = !!(isWeb ? product.serverDocumentationUrl : product.documentationUrl);
127
128
constructor() {
129
super({
130
id: OpenDocumentationUrlAction.ID,
131
title: {
132
...localize2('openDocumentationUrl', "Documentation"),
133
mnemonicTitle: localize({ key: 'miDocumentation', comment: ['&& denotes a mnemonic'] }, "&&Documentation"),
134
},
135
category: Categories.Help,
136
f1: true,
137
menu: {
138
id: MenuId.MenubarHelpMenu,
139
group: '1_welcome',
140
order: 3
141
}
142
});
143
}
144
145
run(accessor: ServicesAccessor): void {
146
const productService = accessor.get(IProductService);
147
const openerService = accessor.get(IOpenerService);
148
const url = isWeb ? productService.serverDocumentationUrl : productService.documentationUrl;
149
150
if (url) {
151
openerService.open(URI.parse(url));
152
}
153
}
154
}
155
156
class OpenNewsletterSignupUrlAction extends Action2 {
157
158
static readonly ID = 'workbench.action.openNewsletterSignupUrl';
159
static readonly AVAILABLE = !!product.newsletterSignupUrl;
160
161
constructor() {
162
super({
163
id: OpenNewsletterSignupUrlAction.ID,
164
title: localize2('newsletterSignup', 'Signup for the VS Code Newsletter'),
165
category: Categories.Help,
166
f1: true
167
});
168
}
169
170
run(accessor: ServicesAccessor) {
171
const productService = accessor.get(IProductService);
172
const openerService = accessor.get(IOpenerService);
173
const telemetryService = accessor.get(ITelemetryService);
174
openerService.open(URI.parse(`${productService.newsletterSignupUrl}?machineId=${encodeURIComponent(telemetryService.machineId)}`));
175
}
176
}
177
178
class OpenYouTubeUrlAction extends Action2 {
179
180
static readonly ID = 'workbench.action.openYouTubeUrl';
181
static readonly AVAILABLE = !!product.youTubeUrl;
182
183
constructor() {
184
super({
185
id: OpenYouTubeUrlAction.ID,
186
title: {
187
...localize2('openYouTubeUrl', "Join Us on YouTube"),
188
mnemonicTitle: localize({ key: 'miYouTube', comment: ['&& denotes a mnemonic'] }, "&&Join Us on YouTube"),
189
},
190
category: Categories.Help,
191
f1: true,
192
menu: {
193
id: MenuId.MenubarHelpMenu,
194
group: '3_feedback',
195
order: 1
196
}
197
});
198
}
199
200
run(accessor: ServicesAccessor): void {
201
const productService = accessor.get(IProductService);
202
const openerService = accessor.get(IOpenerService);
203
204
if (productService.youTubeUrl) {
205
openerService.open(URI.parse(productService.youTubeUrl));
206
}
207
}
208
}
209
210
class OpenRequestFeatureUrlAction extends Action2 {
211
212
static readonly ID = 'workbench.action.openRequestFeatureUrl';
213
static readonly AVAILABLE = !!product.requestFeatureUrl;
214
215
constructor() {
216
super({
217
id: OpenRequestFeatureUrlAction.ID,
218
title: {
219
...localize2('openUserVoiceUrl', "Search Feature Requests"),
220
mnemonicTitle: localize({ key: 'miUserVoice', comment: ['&& denotes a mnemonic'] }, "&&Search Feature Requests"),
221
},
222
category: Categories.Help,
223
f1: true,
224
menu: {
225
id: MenuId.MenubarHelpMenu,
226
group: '3_feedback',
227
order: 2
228
}
229
});
230
}
231
232
run(accessor: ServicesAccessor): void {
233
const productService = accessor.get(IProductService);
234
const openerService = accessor.get(IOpenerService);
235
236
if (productService.requestFeatureUrl) {
237
openerService.open(URI.parse(productService.requestFeatureUrl));
238
}
239
}
240
}
241
242
class OpenLicenseUrlAction extends Action2 {
243
244
static readonly ID = 'workbench.action.openLicenseUrl';
245
static readonly AVAILABLE = !!(isWeb ? product.serverLicense : product.licenseUrl);
246
247
constructor() {
248
super({
249
id: OpenLicenseUrlAction.ID,
250
title: {
251
...localize2('openLicenseUrl', "View License"),
252
mnemonicTitle: localize({ key: 'miLicense', comment: ['&& denotes a mnemonic'] }, "View &&License"),
253
},
254
category: Categories.Help,
255
f1: true,
256
menu: {
257
id: MenuId.MenubarHelpMenu,
258
group: '4_legal',
259
order: 1
260
}
261
});
262
}
263
264
run(accessor: ServicesAccessor): void {
265
const productService = accessor.get(IProductService);
266
const openerService = accessor.get(IOpenerService);
267
const url = isWeb ? productService.serverLicenseUrl : productService.licenseUrl;
268
269
if (url) {
270
if (language) {
271
const queryArgChar = url.indexOf('?') > 0 ? '&' : '?';
272
openerService.open(URI.parse(`${url}${queryArgChar}lang=${language}`));
273
} else {
274
openerService.open(URI.parse(url));
275
}
276
}
277
}
278
}
279
280
class OpenPrivacyStatementUrlAction extends Action2 {
281
282
static readonly ID = 'workbench.action.openPrivacyStatementUrl';
283
static readonly AVAILABLE = !!product.privacyStatementUrl;
284
285
constructor() {
286
super({
287
id: OpenPrivacyStatementUrlAction.ID,
288
title: {
289
...localize2('openPrivacyStatement', "Privacy Statement"),
290
mnemonicTitle: localize({ key: 'miPrivacyStatement', comment: ['&& denotes a mnemonic'] }, "Privac&&y Statement"),
291
},
292
category: Categories.Help,
293
f1: true,
294
menu: {
295
id: MenuId.MenubarHelpMenu,
296
group: '4_legal',
297
order: 2
298
}
299
});
300
}
301
302
run(accessor: ServicesAccessor): void {
303
const productService = accessor.get(IProductService);
304
const openerService = accessor.get(IOpenerService);
305
306
if (productService.privacyStatementUrl) {
307
openerService.open(URI.parse(productService.privacyStatementUrl));
308
}
309
}
310
}
311
312
class GetStartedWithAccessibilityFeatures extends Action2 {
313
314
static readonly ID = 'workbench.action.getStartedWithAccessibilityFeatures';
315
316
constructor() {
317
super({
318
id: GetStartedWithAccessibilityFeatures.ID,
319
title: localize2('getStartedWithAccessibilityFeatures', 'Get Started with Accessibility Features'),
320
category: Categories.Help,
321
f1: true,
322
menu: {
323
id: MenuId.MenubarHelpMenu,
324
group: '1_welcome',
325
order: 6
326
}
327
});
328
}
329
run(accessor: ServicesAccessor): void {
330
const commandService = accessor.get(ICommandService);
331
commandService.executeCommand('workbench.action.openWalkthrough', 'SetupAccessibility');
332
}
333
}
334
335
class AskVSCodeCopilot extends Action2 {
336
static readonly ID = 'workbench.action.askVScode';
337
338
constructor() {
339
super({
340
id: AskVSCodeCopilot.ID,
341
title: localize2('askVScode', 'Ask @vscode'),
342
category: Categories.Help,
343
f1: true,
344
precondition: ContextKeyExpr.equals('chatSetupHidden', false)
345
});
346
}
347
348
async run(accessor: ServicesAccessor): Promise<void> {
349
const commandService = accessor.get(ICommandService);
350
commandService.executeCommand('workbench.action.chat.open', { mode: 'ask', query: '@vscode ', isPartialQuery: true });
351
}
352
}
353
354
MenuRegistry.appendMenuItem(MenuId.MenubarHelpMenu, {
355
command: {
356
id: AskVSCodeCopilot.ID,
357
title: localize2('askVScode', 'Ask @vscode'),
358
},
359
order: 7,
360
group: '1_welcome',
361
when: ContextKeyExpr.equals('chatSetupHidden', false)
362
});
363
364
// --- Actions Registration
365
366
if (KeybindingsReferenceAction.AVAILABLE) {
367
registerAction2(KeybindingsReferenceAction);
368
}
369
370
if (OpenIntroductoryVideosUrlAction.AVAILABLE) {
371
registerAction2(OpenIntroductoryVideosUrlAction);
372
}
373
374
if (OpenTipsAndTricksUrlAction.AVAILABLE) {
375
registerAction2(OpenTipsAndTricksUrlAction);
376
}
377
378
if (OpenDocumentationUrlAction.AVAILABLE) {
379
registerAction2(OpenDocumentationUrlAction);
380
}
381
382
if (OpenNewsletterSignupUrlAction.AVAILABLE) {
383
registerAction2(OpenNewsletterSignupUrlAction);
384
}
385
386
if (OpenYouTubeUrlAction.AVAILABLE) {
387
registerAction2(OpenYouTubeUrlAction);
388
}
389
390
if (OpenRequestFeatureUrlAction.AVAILABLE) {
391
registerAction2(OpenRequestFeatureUrlAction);
392
}
393
394
if (OpenLicenseUrlAction.AVAILABLE) {
395
registerAction2(OpenLicenseUrlAction);
396
}
397
398
if (OpenPrivacyStatementUrlAction.AVAILABLE) {
399
registerAction2(OpenPrivacyStatementUrlAction);
400
}
401
402
registerAction2(GetStartedWithAccessibilityFeatures);
403
404
registerAction2(AskVSCodeCopilot);
405
406