@@ -38,6 +38,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis
38
38
import { localize } from 'vs/nls' ;
39
39
import { CONTEXT_ACCESSIBILITY_MODE_ENABLED } from 'vs/platform/accessibility/common/accessibility' ;
40
40
import { IOpenerService } from 'vs/platform/opener/common/opener' ;
41
+ import { ITerminalContributionService } from 'vs/workbench/contrib/terminal/common/terminalExtensionPoints' ;
41
42
42
43
async function getCwdForSplit ( configHelper : ITerminalConfigHelper , instance : ITerminalInstance , folders ?: IWorkspaceFolder [ ] , commandService ?: ICommandService ) : Promise < string | URI | undefined > {
43
44
switch ( configHelper . config . splitCwd ) {
@@ -304,14 +305,18 @@ export class SelectDefaultShellWindowsTerminalAction extends Action {
304
305
}
305
306
}
306
307
308
+ const terminalIndexRe = / ^ ( [ 0 - 9 ] + ) : / ;
309
+
307
310
export class SwitchTerminalAction extends Action {
308
311
309
312
public static readonly ID = TERMINAL_COMMAND_ID . SWITCH_TERMINAL ;
310
313
public static readonly LABEL = localize ( 'workbench.action.terminal.switchTerminal' , "Switch Terminal" ) ;
311
314
312
315
constructor (
313
316
id : string , label : string ,
314
- @ITerminalService private readonly _terminalService : ITerminalService
317
+ @ITerminalService private readonly _terminalService : ITerminalService ,
318
+ @ITerminalContributionService private readonly _contributions : ITerminalContributionService ,
319
+ @ICommandService private readonly _commands : ICommandService ,
315
320
) {
316
321
super ( id , label , 'terminal-action switch-terminal' ) ;
317
322
}
@@ -328,9 +333,20 @@ export class SwitchTerminalAction extends Action {
328
333
this . _terminalService . refreshActiveTab ( ) ;
329
334
return this . _terminalService . selectDefaultShell ( ) ;
330
335
}
331
- const selectedTabIndex = parseInt ( item . split ( ':' ) [ 0 ] , 10 ) - 1 ;
332
- this . _terminalService . setActiveTabByIndex ( selectedTabIndex ) ;
333
- return this . _terminalService . showPanel ( true ) ;
336
+
337
+ const indexMatches = terminalIndexRe . exec ( item ) ;
338
+ if ( indexMatches ) {
339
+ this . _terminalService . setActiveTabByIndex ( Number ( indexMatches [ 1 ] ) - 1 ) ;
340
+ return this . _terminalService . showPanel ( true ) ;
341
+ }
342
+
343
+ const customType = this . _contributions . terminalTypes . find ( t => t . title === item ) ;
344
+ if ( customType ) {
345
+ return this . _commands . executeCommand ( customType . command ) ;
346
+ }
347
+
348
+ console . warn ( `Unmatched terminal item: "${ item } "` ) ;
349
+ return Promise . resolve ( ) ;
334
350
}
335
351
}
336
352
@@ -342,9 +358,10 @@ export class SwitchTerminalActionViewItem extends SelectActionViewItem {
342
358
action : IAction ,
343
359
@ITerminalService private readonly _terminalService : ITerminalService ,
344
360
@IThemeService private readonly _themeService : IThemeService ,
345
- @IContextViewService contextViewService : IContextViewService
361
+ @ITerminalContributionService private readonly _contributions : ITerminalContributionService ,
362
+ @IContextViewService contextViewService : IContextViewService ,
346
363
) {
347
- super ( null , action , getTerminalSelectOpenItems ( _terminalService ) , _terminalService . activeTabIndex , contextViewService , { ariaLabel : localize ( 'terminals' , 'Open Terminals.' ) , optionsAsChildren : true } ) ;
364
+ super ( null , action , getTerminalSelectOpenItems ( _terminalService , _contributions ) , _terminalService . activeTabIndex , contextViewService , { ariaLabel : localize ( 'terminals' , 'Open Terminals.' ) , optionsAsChildren : true } ) ;
348
365
349
366
this . _register ( _terminalService . onInstancesChanged ( this . _updateItems , this ) ) ;
350
367
this . _register ( _terminalService . onActiveTabChanged ( this . _updateItems , this ) ) ;
@@ -362,13 +379,18 @@ export class SwitchTerminalActionViewItem extends SelectActionViewItem {
362
379
}
363
380
364
381
private _updateItems ( ) : void {
365
- this . setOptions ( getTerminalSelectOpenItems ( this . _terminalService ) , this . _terminalService . activeTabIndex ) ;
382
+ this . setOptions ( getTerminalSelectOpenItems ( this . _terminalService , this . _contributions ) , this . _terminalService . activeTabIndex ) ;
366
383
}
367
384
}
368
385
369
- function getTerminalSelectOpenItems ( terminalService : ITerminalService ) : ISelectOptionItem [ ] {
386
+ function getTerminalSelectOpenItems ( terminalService : ITerminalService , contributions : ITerminalContributionService ) : ISelectOptionItem [ ] {
370
387
const items = terminalService . getTabLabels ( ) . map ( label => < ISelectOptionItem > { text : label } ) ;
371
388
items . push ( { text : SwitchTerminalActionViewItem . SEPARATOR , isDisabled : true } ) ;
389
+
390
+ for ( const contributed of contributions . terminalTypes ) {
391
+ items . push ( { text : contributed . title } ) ;
392
+ }
393
+
372
394
items . push ( { text : SelectDefaultShellWindowsTerminalAction . LABEL } ) ;
373
395
return items ;
374
396
}
0 commit comments