-
Notifications
You must be signed in to change notification settings - Fork 27.9k
/
terminalActions.ts
762 lines (627 loc) · 23.5 KB
/
terminalActions.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
/*---------------------------------------------------------------------------------------------
* 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 * as os from 'os';
import { Action, IAction } from 'vs/base/common/actions';
import { EndOfLinePreference } from 'vs/editor/common/editorCommon';
import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService';
import { ITerminalService, TERMINAL_PANEL_ID } from 'vs/workbench/parts/terminal/common/terminal';
import { SelectActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
import { TPromise } from 'vs/base/common/winjs.base';
import { TogglePanelAction } from 'vs/workbench/browser/panel';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { attachSelectBoxStyler } from 'vs/platform/theme/common/styler';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
import { ActionBarContributor } from 'vs/workbench/browser/actions';
import { TerminalEntry } from 'vs/workbench/parts/terminal/browser/terminalQuickOpen';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
export const TERMINAL_PICKER_PREFIX = 'term ';
export class ToggleTerminalAction extends TogglePanelAction {
public static ID = 'workbench.action.terminal.toggleTerminal';
public static LABEL = nls.localize('workbench.action.terminal.toggleTerminal', "Toggle Integrated Terminal");
constructor(
id: string, label: string,
@IPanelService panelService: IPanelService,
@IPartService partService: IPartService,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label, TERMINAL_PANEL_ID, panelService, partService);
}
public run(event?: any): TPromise<any> {
if (this.terminalService.terminalInstances.length === 0) {
// If there is not yet an instance attempt to create it here so that we can suggest a
// new shell on Windows (and not do so when the panel is restored on reload).
this.terminalService.createInstance(undefined, true);
}
return super.run();
}
}
export class KillTerminalAction extends Action {
public static ID = 'workbench.action.terminal.kill';
public static LABEL = nls.localize('workbench.action.terminal.kill', "Kill the Active Terminal Instance");
public static PANEL_LABEL = nls.localize('workbench.action.terminal.kill.short', "Kill Terminal");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
this.class = 'terminal-action kill';
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
this.terminalService.getActiveInstance().dispose();
if (this.terminalService.terminalInstances.length > 0) {
this.terminalService.showPanel(true);
}
}
return TPromise.as(void 0);
}
}
export class QuickKillTerminalAction extends Action {
public static ID = 'workbench.action.terminal.quickKill';
public static LABEL = nls.localize('workbench.action.terminal.quickKill', "Kill Terminal Instance");
constructor(
id: string, label: string,
private terminalEntry: TerminalEntry,
@ITerminalService private terminalService: ITerminalService,
@IQuickOpenService private quickOpenService: IQuickOpenService
) {
super(id, label);
this.class = 'terminal-action kill';
}
public run(event?: any): TPromise<any> {
const terminalIndex = parseInt(this.terminalEntry.getLabel().split(':')[0]) - 1;
const terminal = this.terminalService.getInstanceFromIndex(terminalIndex);
if (terminal) {
terminal.dispose();
}
if (this.terminalService.terminalInstances.length > 0 && this.terminalService.activeTerminalInstanceIndex !== terminalIndex) {
this.terminalService.setActiveInstanceByIndex(Math.min(terminalIndex, this.terminalService.terminalInstances.length - 1));
}
return TPromise.timeout(50).then(result => this.quickOpenService.show(TERMINAL_PICKER_PREFIX, null));
}
}
/**
* Copies the terminal selection. Note that since the command palette takes focus from the terminal,
* this cannot be triggered through the command palette.
*/
export class CopyTerminalSelectionAction extends Action {
public static ID = 'workbench.action.terminal.copySelection';
public static LABEL = nls.localize('workbench.action.terminal.copySelection', "Copy Selection");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.copySelection();
}
return TPromise.as(void 0);
}
}
export class SelectAllTerminalAction extends Action {
public static ID = 'workbench.action.terminal.selectAll';
public static LABEL = nls.localize('workbench.action.terminal.selectAll', "Select All");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.selectAll();
}
return TPromise.as(void 0);
}
}
export class DeleteWordLeftTerminalAction extends Action {
public static ID = 'workbench.action.terminal.deleteWordLeft';
public static LABEL = nls.localize('workbench.action.terminal.deleteWordLeft', "Delete Word Left");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
// Send ctrl+W
terminalInstance.sendText(String.fromCharCode('W'.charCodeAt(0) - 64), false);
}
return TPromise.as(void 0);
}
}
export class DeleteWordRightTerminalAction extends Action {
public static ID = 'workbench.action.terminal.deleteWordRight';
public static LABEL = nls.localize('workbench.action.terminal.deleteWordRight', "Delete Word Right");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
// Send alt+D
terminalInstance.sendText('\x1bD', false);
}
return TPromise.as(void 0);
}
}
export class CreateNewTerminalAction extends Action {
public static ID = 'workbench.action.terminal.new';
public static LABEL = nls.localize('workbench.action.terminal.new', "Create New Integrated Terminal");
public static PANEL_LABEL = nls.localize('workbench.action.terminal.new.short', "New Terminal");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
this.class = 'terminal-action new';
}
public run(event?: any): TPromise<any> {
const instance = this.terminalService.createInstance(undefined, true);
if (!instance) {
return TPromise.as(void 0);
}
this.terminalService.setActiveInstance(instance);
return this.terminalService.showPanel(true);
}
}
export class FocusActiveTerminalAction extends Action {
public static ID = 'workbench.action.terminal.focus';
public static LABEL = nls.localize('workbench.action.terminal.focus', "Focus Terminal");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
const instance = this.terminalService.getActiveOrCreateInstance(true);
if (!instance) {
return TPromise.as(void 0);
}
this.terminalService.setActiveInstance(instance);
return this.terminalService.showPanel(true);
}
}
export class FocusNextTerminalAction extends Action {
public static ID = 'workbench.action.terminal.focusNext';
public static LABEL = nls.localize('workbench.action.terminal.focusNext', "Focus Next Terminal");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
this.terminalService.setActiveInstanceToNext();
return this.terminalService.showPanel(true);
}
}
export class FocusTerminalAtIndexAction extends Action {
private static ID_PREFIX = 'workbench.action.terminal.focusAtIndex';
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
this.terminalService.setActiveInstanceByIndex(this.getTerminalNumber() - 1);
return this.terminalService.showPanel(true);
}
public static getId(n: number): string {
return FocusTerminalAtIndexAction.ID_PREFIX + n;
}
public static getLabel(n: number): string {
return nls.localize('workbench.action.terminal.focusAtIndex', 'Focus Terminal {0}', n);
}
private getTerminalNumber(): number {
return parseInt(this.id.substr(FocusTerminalAtIndexAction.ID_PREFIX.length));
}
}
export class FocusPreviousTerminalAction extends Action {
public static ID = 'workbench.action.terminal.focusPrevious';
public static LABEL = nls.localize('workbench.action.terminal.focusPrevious', "Focus Previous Terminal");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
this.terminalService.setActiveInstanceToPrevious();
return this.terminalService.showPanel(true);
}
}
export class TerminalPasteAction extends Action {
public static ID = 'workbench.action.terminal.paste';
public static LABEL = nls.localize('workbench.action.terminal.paste', "Paste into Active Terminal");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
const instance = this.terminalService.getActiveOrCreateInstance();
if (instance) {
instance.paste();
}
return TPromise.as(void 0);
}
}
export class SelectDefaultShellWindowsTerminalAction extends Action {
public static ID = 'workbench.action.terminal.selectDefaultShell';
public static LABEL = nls.localize('workbench.action.terminal.DefaultShell', "Select Default Shell");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
return this.terminalService.selectDefaultWindowsShell();
}
}
export class RunSelectedTextInTerminalAction extends Action {
public static ID = 'workbench.action.terminal.runSelectedText';
public static LABEL = nls.localize('workbench.action.terminal.runSelectedText', "Run Selected Text In Active Terminal");
constructor(
id: string, label: string,
@ICodeEditorService private codeEditorService: ICodeEditorService,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
const instance = this.terminalService.getActiveOrCreateInstance();
if (!instance) {
return TPromise.as(void 0);
}
let editor = this.codeEditorService.getFocusedCodeEditor();
if (!editor) {
return TPromise.as(void 0);
}
let selection = editor.getSelection();
let text: string;
if (selection.isEmpty()) {
text = editor.getModel().getLineContent(selection.selectionStartLineNumber).trim();
} else {
let endOfLinePreference = os.EOL === '\n' ? EndOfLinePreference.LF : EndOfLinePreference.CRLF;
text = editor.getModel().getValueInRange(selection, endOfLinePreference);
}
instance.sendText(text, true);
return this.terminalService.showPanel();
}
}
export class RunActiveFileInTerminalAction extends Action {
public static ID = 'workbench.action.terminal.runActiveFile';
public static LABEL = nls.localize('workbench.action.terminal.runActiveFile', "Run Active File In Active Terminal");
constructor(
id: string, label: string,
@ICodeEditorService private codeEditorService: ICodeEditorService,
@ITerminalService private terminalService: ITerminalService,
@IMessageService private messageService: IMessageService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
const instance = this.terminalService.getActiveOrCreateInstance();
if (!instance) {
return TPromise.as(void 0);
}
const editor = this.codeEditorService.getFocusedCodeEditor();
if (!editor) {
return TPromise.as(void 0);
}
const uri = editor.getModel().uri;
if (uri.scheme !== 'file') {
this.messageService.show(Severity.Warning, nls.localize('workbench.action.terminal.runActiveFile.noFile', 'Only files on disk can be run in the terminal'));
return TPromise.as(void 0);
}
instance.sendText(uri.fsPath, true);
return this.terminalService.showPanel();
}
}
export class SwitchTerminalInstanceAction extends Action {
public static ID = 'workbench.action.terminal.switchTerminalInstance';
public static LABEL = nls.localize('workbench.action.terminal.switchTerminalInstance', "Switch Terminal Instance");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(SwitchTerminalInstanceAction.ID, SwitchTerminalInstanceAction.LABEL);
this.class = 'terminal-action switch-terminal-instance';
}
public run(item?: string): TPromise<any> {
if (!item || !item.split) {
return TPromise.as(null);
}
const selectedTerminalIndex = parseInt(item.split(':')[0], 10) - 1;
this.terminalService.setActiveInstanceByIndex(selectedTerminalIndex);
return this.terminalService.showPanel(true);
}
}
export class SwitchTerminalInstanceActionItem extends SelectActionItem {
constructor(
action: IAction,
@ITerminalService private terminalService: ITerminalService,
@IThemeService themeService: IThemeService
) {
super(null, action, terminalService.getInstanceLabels(), terminalService.activeTerminalInstanceIndex);
this.toDispose.push(terminalService.onInstancesChanged(this._updateItems, this));
this.toDispose.push(terminalService.onActiveInstanceChanged(this._updateItems, this));
this.toDispose.push(terminalService.onInstanceTitleChanged(this._updateItems, this));
this.toDispose.push(attachSelectBoxStyler(this.selectBox, themeService));
}
private _updateItems(): void {
this.setOptions(this.terminalService.getInstanceLabels(), this.terminalService.activeTerminalInstanceIndex);
}
}
export class ScrollDownTerminalAction extends Action {
public static ID = 'workbench.action.terminal.scrollDown';
public static LABEL = nls.localize('workbench.action.terminal.scrollDown', "Scroll Down (Line)");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.scrollDownLine();
}
return TPromise.as(void 0);
}
}
export class ScrollDownPageTerminalAction extends Action {
public static ID = 'workbench.action.terminal.scrollDownPage';
public static LABEL = nls.localize('workbench.action.terminal.scrollDownPage', "Scroll Down (Page)");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.scrollDownPage();
}
return TPromise.as(void 0);
}
}
export class ScrollToBottomTerminalAction extends Action {
public static ID = 'workbench.action.terminal.scrollToBottom';
public static LABEL = nls.localize('workbench.action.terminal.scrollToBottom', "Scroll to Bottom");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.scrollToBottom();
}
return TPromise.as(void 0);
}
}
export class ScrollUpTerminalAction extends Action {
public static ID = 'workbench.action.terminal.scrollUp';
public static LABEL = nls.localize('workbench.action.terminal.scrollUp', "Scroll Up (Line)");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.scrollUpLine();
}
return TPromise.as(void 0);
}
}
export class ScrollUpPageTerminalAction extends Action {
public static ID = 'workbench.action.terminal.scrollUpPage';
public static LABEL = nls.localize('workbench.action.terminal.scrollUpPage', "Scroll Up (Page)");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.scrollUpPage();
}
return TPromise.as(void 0);
}
}
export class ScrollToTopTerminalAction extends Action {
public static ID = 'workbench.action.terminal.scrollToTop';
public static LABEL = nls.localize('workbench.action.terminal.scrollToTop', "Scroll to Top");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.scrollToTop();
}
return TPromise.as(void 0);
}
}
export class ClearTerminalAction extends Action {
public static ID = 'workbench.action.terminal.clear';
public static LABEL = nls.localize('workbench.action.terminal.clear', "Clear");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
let terminalInstance = this.terminalService.getActiveInstance();
if (terminalInstance) {
terminalInstance.clear();
}
return TPromise.as(void 0);
}
}
export class AllowWorkspaceShellTerminalCommand extends Action {
public static ID = 'workbench.action.terminal.allowWorkspaceShell';
public static LABEL = nls.localize('workbench.action.terminal.allowWorkspaceShell', "Allow Workspace Shell Configuration");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
this.terminalService.setWorkspaceShellAllowed(true);
return TPromise.as(void 0);
}
}
export class DisallowWorkspaceShellTerminalCommand extends Action {
public static ID = 'workbench.action.terminal.disallowWorkspaceShell';
public static LABEL = nls.localize('workbench.action.terminal.disallowWorkspaceShell', "Disallow Workspace Shell Configuration");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
this.terminalService.setWorkspaceShellAllowed(false);
return TPromise.as(void 0);
}
}
export class RenameTerminalAction extends Action {
public static ID = 'workbench.action.terminal.rename';
public static LABEL = nls.localize('workbench.action.terminal.rename', "Rename");
constructor(
id: string, label: string,
@IQuickOpenService protected quickOpenService: IQuickOpenService,
@ITerminalService protected terminalService: ITerminalService
) {
super(id, label);
}
public run(terminal?: TerminalEntry): TPromise<any> {
const terminalInstance = terminal ? this.terminalService.getInstanceFromIndex(parseInt(terminal.getLabel().split(':')[0], 10) - 1) : this.terminalService.getActiveInstance();
if (!terminalInstance) {
return TPromise.as(void 0);
}
return this.quickOpenService.input({
value: terminalInstance.title,
prompt: nls.localize('workbench.action.terminal.rename.prompt', "Enter terminal name"),
}).then(name => {
if (name) {
terminalInstance.setTitle(name, false);
}
});
}
}
export class FocusTerminalFindWidgetAction extends Action {
public static ID = 'workbench.action.terminal.focusFindWidget';
public static LABEL = nls.localize('workbench.action.terminal.focusFindWidget', "Focus Find Widget");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(): TPromise<any> {
return this.terminalService.focusFindWidget();
}
}
export class HideTerminalFindWidgetAction extends Action {
public static ID = 'workbench.action.terminal.hideFindWidget';
public static LABEL = nls.localize('workbench.action.terminal.hideFindWidget', "Hide Find Widget");
constructor(
id: string, label: string,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(): TPromise<any> {
return TPromise.as(this.terminalService.hideFindWidget());
}
}
export class QuickOpenActionTermContributor extends ActionBarContributor {
constructor(
@ITerminalService private terminalService: ITerminalService,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IInstantiationService private instantiationService: IInstantiationService
) {
super();
}
public getActions(context: any): IAction[] {
let actions: Action[] = [];
if (context.element instanceof TerminalEntry) {
actions.push(this.instantiationService.createInstance(RenameTerminalQuickOpenAction, RenameTerminalQuickOpenAction.ID, RenameTerminalQuickOpenAction.LABEL, context.element));
actions.push(this.instantiationService.createInstance(QuickKillTerminalAction, QuickKillTerminalAction.ID, QuickKillTerminalAction.LABEL, context.element));
}
return actions;
}
public hasActions(context: any): boolean {
return true;
}
}
export class QuickOpenTermAction extends Action {
public static ID = 'workbench.action.quickOpenTerm';
public static LABEL = nls.localize('quickOpenTerm', "Terminal: Switch Active Terminal");
constructor(
id: string,
label: string,
@IQuickOpenService private quickOpenService: IQuickOpenService
) {
super(id, label);
}
public run(): TPromise<void> {
return this.quickOpenService.show(TERMINAL_PICKER_PREFIX, null);
}
}
export class RenameTerminalQuickOpenAction extends RenameTerminalAction {
constructor(
id: string, label: string,
private terminal: TerminalEntry,
@IQuickOpenService quickOpenService: IQuickOpenService,
@ITerminalService terminalService: ITerminalService,
@IInstantiationService private instantiationService: IInstantiationService
) {
super(id, label, quickOpenService, terminalService);
this.class = 'quick-open-terminal-configure';
}
public run(): TPromise<any> {
super.run(this.terminal)
// This timeout is needed to make sure the previous quickOpen has time to close before we show the next one
.then(() => TPromise.timeout(50))
.then(result => this.quickOpenService.show(TERMINAL_PICKER_PREFIX, null));
return TPromise.as(null);
}
}