Skip to content

Commit 23f95b1

Browse files
authored
Merge pull request microsoft#155119 from microsoft/tyriar/155118
Add configure decorations ctx menu entry
2 parents f9bad09 + 63c044b commit 23f95b1

File tree

1 file changed

+95
-3
lines changed

1 file changed

+95
-3
lines changed

src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.ts

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { TERMINAL_COMMAND_DECORATION_DEFAULT_BACKGROUND_COLOR, TERMINAL_COMMAND_
2525
import { Color } from 'vs/base/common/color';
2626
import { IOpenerService } from 'vs/platform/opener/common/opener';
2727
import { IGenericMarkProperties } from 'vs/platform/terminal/common/terminalProcess';
28+
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
29+
import { Codicon } from 'vs/base/common/codicons';
2830

2931
const enum DecorationSelector {
3032
CommandDecoration = 'terminal-command-decoration',
@@ -65,7 +67,8 @@ export class DecorationAddon extends Disposable implements ITerminalAddon {
6567
@IHoverService private readonly _hoverService: IHoverService,
6668
@IConfigurationService private readonly _configurationService: IConfigurationService,
6769
@IThemeService private readonly _themeService: IThemeService,
68-
@IOpenerService private readonly _openerService: IOpenerService
70+
@IOpenerService private readonly _openerService: IOpenerService,
71+
@IQuickInputService private readonly _quickInputService: IQuickInputService
6972
) {
7073
super();
7174
this._register(toDisposable(() => this._dispose()));
@@ -431,13 +434,102 @@ export class DecorationAddon extends Disposable implements ITerminalAddon {
431434
if (actions.length > 0) {
432435
actions.push(new Separator());
433436
}
434-
const label = localize("terminal.learnShellIntegration", 'Learn About Shell Integration');
437+
const labelConfigure = localize("terminal.configureCommandDecorations", 'Configure Command Decorations');
435438
actions.push({
436-
class: undefined, tooltip: label, dispose: () => { }, id: 'terminal.learnShellIntegration', label, enabled: true,
439+
class: undefined, tooltip: labelConfigure, dispose: () => { }, id: 'terminal.configureCommandDecorations', label: labelConfigure, enabled: true,
440+
run: () => this._showConfigureCommandDecorationsQuickPick()
441+
});
442+
const labelAbout = localize("terminal.learnShellIntegration", 'Learn About Shell Integration');
443+
actions.push({
444+
class: undefined, tooltip: labelAbout, dispose: () => { }, id: 'terminal.learnShellIntegration', label: labelAbout, enabled: true,
437445
run: () => this._openerService.open('https://code.visualstudio.com/docs/editor/integrated-terminal#_shell-integration')
438446
});
439447
return actions;
440448
}
449+
450+
private async _showConfigureCommandDecorationsQuickPick() {
451+
const quickPick = this._quickInputService.createQuickPick();
452+
quickPick.items = [
453+
{ id: 'a', label: localize('changeDefaultIcon', 'Change default icon') },
454+
{ id: 'b', label: localize('changeSuccessIcon', 'Change success icon') },
455+
{ id: 'c', label: localize('changeErrorIcon', 'Change error icon') },
456+
{ type: 'separator' },
457+
{ id: 'd', label: localize('toggleVisibility', 'Toggle visibility') },
458+
];
459+
quickPick.canSelectMany = false;
460+
quickPick.onDidAccept(async e => {
461+
quickPick.hide();
462+
const result = quickPick.activeItems[0];
463+
let iconSetting: string | undefined;
464+
switch (result.id) {
465+
case 'a': iconSetting = TerminalSettingId.ShellIntegrationDecorationIcon; break;
466+
case 'b': iconSetting = TerminalSettingId.ShellIntegrationDecorationIconSuccess; break;
467+
case 'c': iconSetting = TerminalSettingId.ShellIntegrationDecorationIconError; break;
468+
case 'd': this._showToggleVisibilityQuickPick(); break;
469+
}
470+
if (iconSetting) {
471+
this._showChangeIconQuickPick(iconSetting);
472+
}
473+
});
474+
quickPick.show();
475+
}
476+
477+
private async _showChangeIconQuickPick(iconSetting: string) {
478+
type Item = IQuickPickItem & { icon: Codicon };
479+
const items: Item[] = [];
480+
for (const icon of Codicon.getAll()) {
481+
items.push({ label: `$(${icon.id})`, description: `${icon.id}`, icon });
482+
}
483+
const result = await this._quickInputService.pick(items, {
484+
matchOnDescription: true
485+
});
486+
if (result) {
487+
this._configurationService.updateValue(iconSetting, result.icon.id);
488+
this._showConfigureCommandDecorationsQuickPick();
489+
}
490+
}
491+
492+
private _showToggleVisibilityQuickPick() {
493+
const quickPick = this._quickInputService.createQuickPick();
494+
quickPick.hideInput = true;
495+
quickPick.hideCheckAll = true;
496+
quickPick.canSelectMany = true;
497+
quickPick.title = localize('toggleVisibility', 'Toggle visibility');
498+
const configValue = this._configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationsEnabled);
499+
const gutterIcon: IQuickPickItem = {
500+
label: localize('gutter', 'Gutter command decorations'),
501+
picked: configValue !== 'never' && configValue !== 'overviewRuler'
502+
};
503+
const overviewRulerIcon: IQuickPickItem = {
504+
label: localize('overviewRuler', 'Overview ruler command decorations'),
505+
picked: configValue !== 'never' && configValue !== 'gutter'
506+
};
507+
quickPick.items = [gutterIcon, overviewRulerIcon];
508+
const selectedItems: IQuickPickItem[] = [];
509+
if (configValue !== 'never') {
510+
if (configValue !== 'gutter') {
511+
selectedItems.push(gutterIcon);
512+
}
513+
if (configValue !== 'overviewRuler') {
514+
selectedItems.push(overviewRulerIcon);
515+
}
516+
}
517+
quickPick.selectedItems = selectedItems;
518+
quickPick.onDidChangeSelection(async e => {
519+
let newValue: 'both' | 'gutter' | 'overviewRuler' | 'never' = 'never';
520+
if (e.includes(gutterIcon)) {
521+
if (e.includes(overviewRulerIcon)) {
522+
newValue = 'both';
523+
} else {
524+
newValue = 'gutter';
525+
}
526+
} else if (e.includes(overviewRulerIcon)) {
527+
newValue = 'overviewRuler';
528+
}
529+
await this._configurationService.updateValue(TerminalSettingId.ShellIntegrationDecorationsEnabled, newValue);
530+
});
531+
quickPick.show();
532+
}
441533
}
442534
let successColor: string | Color | undefined;
443535
let errorColor: string | Color | undefined;

0 commit comments

Comments
 (0)