From cc979620ab3e7f2d45d9e2aa0a62e7d279b5907f Mon Sep 17 00:00:00 2001 From: vince-fugnitto Date: Fri, 17 Mar 2023 09:30:48 -0400 Subject: [PATCH] terminal: fix 'new terminal' handling 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 --- CHANGELOG.md | 1 + .../browser/terminal-frontend-contribution.ts | 51 +++++++++---------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79b9a65d6d840..804a5f7288d10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/terminal/src/browser/terminal-frontend-contribution.ts b/packages/terminal/src/browser/terminal-frontend-contribution.ts index 1b1b4555442ac..a390eda82c8a4 100644 --- a/packages/terminal/src/browser/terminal-frontend-contribution.ts +++ b/packages/terminal/src/browser/terminal-frontend-contribution.ts @@ -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, { @@ -933,40 +939,29 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu return ref instanceof TerminalWidget ? ref : undefined; } - protected async openTerminal(options?: ApplicationShell.WidgetOptions): Promise { - let profile = this.profileService.defaultProfile; - - if (!profile) { - throw new Error('There are not profiles registered'); + protected async openTerminal(options?: ApplicationShell.WidgetOptions, terminalProfile?: TerminalProfile): Promise { + 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 { - 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 {