Skip to content

Commit

Permalink
terminal: fix 'new terminal' handling
Browse files Browse the repository at this point in the history
The commit fixes a regression with `new terminal` and `new terminal
(with profile)` which did not open successfully when no workspace root
was present. The code fixes the issue and also refactors the logic to
remove unnecessary duplication.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Mar 23, 2023
1 parent dacd392 commit cc97962
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
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

0 comments on commit cc97962

Please sign in to comment.