Profiles via command pallette (#120141)

* fix #120037
This commit is contained in:
Megan Rogge 2021-03-31 10:11:30 -07:00 committed by GitHub
parent 2a611bc682
commit a49d15d70d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 9 deletions

View file

@ -155,7 +155,7 @@ export interface ITerminalService {
*/
registerLinkProvider(linkProvider: ITerminalExternalLinkProvider): IDisposable;
selectDefaultProfile(): Promise<void>;
showProfileQuickPick(type: 'setDefault' | 'createInstance'): Promise<void>;
/**
* Gets the detected terminal profiles for the platform

View file

@ -129,6 +129,19 @@ export function registerTerminalActions() {
await terminalService.showPanel(true);
}
});
registerAction2(class extends Action2 {
constructor() {
super({
id: TERMINAL_COMMAND_ID.NEW_WITH_PROFILE,
title: { value: localize('workbench.action.terminal.newWithProfile', "Create New Integrated Terminal (With Profile)"), original: 'Create New Integrated Terminal (With Profile)' },
f1: true,
category
});
}
async run(accessor: ServicesAccessor) {
await accessor.get(ITerminalService).showProfileQuickPick('createInstance');
}
});
registerAction2(class extends Action2 {
constructor() {
super({
@ -1345,7 +1358,7 @@ export function registerTerminalActions() {
});
}
async run(accessor: ServicesAccessor) {
await accessor.get(ITerminalService).selectDefaultProfile();
await accessor.get(ITerminalService).showProfileQuickPick('setDefault');
}
});
registerAction2(class extends Action2 {
@ -1475,7 +1488,7 @@ export function registerTerminalActions() {
}
if (item === selectDefaultProfileTitle) {
terminalService.refreshActiveTab();
return terminalService.selectDefaultProfile();
return terminalService.showProfileQuickPick('setDefault');
}
if (item === configureTerminalSettingsTitle) {
await commandService.executeCommand(TERMINAL_COMMAND_ID.CONFIGURE_TERMINAL_SETTINGS);

View file

@ -15,7 +15,7 @@ import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configur
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IInstantiationService, optional } from 'vs/platform/instantiation/common/instantiation';
import { IPickOptions, IQuickInputButton, IQuickInputService, IQuickPickItem, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
import { IKeyMods, IPickOptions, IQuickInputButton, IQuickInputService, IQuickPickItem, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ILocalTerminalService, IShellLaunchConfig, ITerminalLaunchError, ITerminalsLayoutInfo, ITerminalsLayoutInfoById, TerminalShellType, WindowsShellType } from 'vs/platform/terminal/common/terminal';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
@ -842,12 +842,13 @@ export class TerminalService implements ITerminalService {
return isWindows ? 'windows' : (isMacintosh ? 'osx' : 'linux');
}
public async selectDefaultProfile(): Promise<void> {
public async showProfileQuickPick(type: 'setDefault' | 'createInstance'): Promise<void> {
let keyMods: IKeyMods | undefined;
const profiles = await this._detectProfiles(false);
const platformKey = await this._getPlatformKey();
const options: IPickOptions<IProfileQuickPickItem> = {
placeHolder: nls.localize('terminal.integrated.chooseWindowsShell', "Select your default terminal profile"),
placeHolder: 'createInstance' ? nls.localize('terminal.integrated.selectProfileToCreate', "Select the terminal profile to create") : nls.localize('terminal.integrated.chooseDefaultProfile', "Select your default terminal profile"),
onDidTriggerItemButton: async (context) => {
const configKey = `terminal.integrated.profiles.${platformKey}`;
const configProfiles = this._configurationService.inspect<{ [key: string]: ITerminalProfileObject }>(configKey);
@ -871,7 +872,8 @@ export class TerminalService implements ITerminalService {
args: context.item.profile.args
};
await this._configurationService.updateValue(configKey, newConfigValue, ConfigurationTarget.USER);
}
},
onKeyMods: mods => keyMods = mods
};
// Build quick pick items
@ -891,8 +893,27 @@ export class TerminalService implements ITerminalService {
if (!value) {
return;
}
await this._configurationService.updateValue(`terminal.integrated.shell.${platformKey}`, value.profile.path, ConfigurationTarget.USER);
await this._configurationService.updateValue(`terminal.integrated.shellArgs.${platformKey}`, value.profile.args, ConfigurationTarget.USER);
if (type === 'createInstance') {
const launchConfig = { executable: value.profile.path, args: value.profile.args, name: value.profile.overrideName ? value.profile.profileName : undefined };
let instance;
const activeInstance = this.getActiveInstance();
if (keyMods?.alt && activeInstance) {
// create split, only valid if there's an active instance
if (activeInstance) {
instance = this.splitInstance(activeInstance, launchConfig);
}
} else {
instance = this.createTerminal(launchConfig);
}
if (instance) {
this.showPanel(true);
this.setActiveInstance(instance);
}
} else {
// setDefault
await this._configurationService.updateValue(`terminal.integrated.shell.${platformKey}`, value.profile.path, ConfigurationTarget.USER);
await this._configurationService.updateValue(`terminal.integrated.shellArgs.${platformKey}`, value.profile.args, ConfigurationTarget.USER);
}
}
private _createProfileQuickPickItem(profile: ITerminalProfile): IProfileQuickPickItem {

View file

@ -400,6 +400,7 @@ export const enum TERMINAL_COMMAND_ID {
NEW_WITH_CWD = 'workbench.action.terminal.newWithCwd',
NEW_LOCAL = 'workbench.action.terminal.newLocal',
NEW_IN_ACTIVE_WORKSPACE = 'workbench.action.terminal.newInActiveWorkspace',
NEW_WITH_PROFILE = 'workbench.action.terminal.newWithProfile',
SPLIT = 'workbench.action.terminal.split',
SPLIT_IN_ACTIVE_WORKSPACE = 'workbench.action.terminal.splitInActiveWorkspace',
RELAUNCH = 'workbench.action.terminal.relaunch',