Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profiles via command pallette #120141

Merged
merged 8 commits into from Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/terminal/browser/terminal.ts
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Expand Up @@ -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({
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1453,7 +1466,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);
Expand Down
33 changes: 27 additions & 6 deletions src/vs/workbench/contrib/terminal/browser/terminalService.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
}
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
} 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 {
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/terminal/common/terminal.ts
Expand Up @@ -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',
Expand Down