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

terminal: fix 'new terminal' handling #12322

Merged
merged 2 commits into from
Mar 23, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Interface ScmInlineAction removes 'commands: CommandRegistry'
- Interface ScmInlineActions removes 'commands: CommandRegistry'
- Interface ScmTreeWidget.Props removes 'commands: CommandRegistry'
- [terminal] removed `openTerminalFromProfile` method from `TerminalFrontendContribution` [#12322](https://github.com/eclipse-theia/theia/pull/12322)

## v1.35.0 - 02/23/2023

Expand Down
51 changes: 23 additions & 28 deletions packages/terminal/src/browser/terminal-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,13 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
});

commands.registerCommand(TerminalCommands.PROFILE_NEW, {
execute: () => this.openTerminalFromProfile()
execute: async () => {
const profile = await this.selectTerminalProfile(nls.localize('theia/terminal/selectProfile', 'Select a profile for the new terminal'));
if (!profile) {
return;
}
this.openTerminal(undefined, profile[1]);
}
});

commands.registerCommand(TerminalCommands.PROFILE_DEFAULT, {
Expand Down Expand Up @@ -933,40 +939,29 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
return ref instanceof TerminalWidget ? ref : undefined;
}

protected async openTerminal(options?: ApplicationShell.WidgetOptions): Promise<void> {
let profile = this.profileService.defaultProfile;

if (!profile) {
throw new Error('There are not profiles registered');
protected async openTerminal(options?: ApplicationShell.WidgetOptions, terminalProfile?: TerminalProfile): Promise<void> {
let profile = terminalProfile;
if (!terminalProfile) {
profile = this.profileService.defaultProfile;
if (!profile) {
throw new Error('There are not profiles registered');
}
}

if (profile instanceof ShellTerminalProfile) {
const cwd = await this.selectTerminalCwd();
if (!cwd) {
return;
if (this.workspaceService.workspace) {
const cwd = await this.selectTerminalCwd();
if (!cwd) {
return;
}
profile = profile.modify({ cwd });
}
profile = profile.modify({ cwd });
}

const termWidget = await profile?.start();

this.open(termWidget, { widgetOptions: options });
}

protected async openTerminalFromProfile(options?: ApplicationShell.WidgetOptions): Promise<void> {
const result = await this.selectTerminalProfile(nls.localize('theia/terminal/selectProfile', 'Select a profile for the new terminal'));
if (!result) {
return;
if (!!termWidget) {
this.open(termWidget, { widgetOptions: options });
}
let profile = result[1];
if (profile instanceof ShellTerminalProfile) {
const cwd = await this.selectTerminalCwd();
if (!cwd) {
return;
}
profile = profile.modify({ cwd });
}
const termWidget = await profile.start();
this.open(termWidget, { widgetOptions: options });
}

protected async chooseDefaultProfile(): Promise<void> {
Expand Down