From 954fee41a0fc860f5124231e37f248f77328b252 Mon Sep 17 00:00:00 2001 From: dankeboy36 Date: Tue, 27 Jun 2023 17:43:49 +0200 Subject: [PATCH] fix(terminal): `split-terminal` visibility Removed the toolbar contribution from the UI. Ref: eclipse-theia/theia#12626/ Signed-off-by: dankeboy36 --- .../browser/arduino-ide-frontend-module.ts | 4 ++ .../terminal-frontend-contribution.ts | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 arduino-ide-extension/src/browser/theia/terminal/terminal-frontend-contribution.ts diff --git a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts index 743296fd1..ea568d595 100644 --- a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts +++ b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts @@ -357,6 +357,8 @@ import { MonacoEditorMenuContribution as TheiaMonacoEditorMenuContribution } fro import { UpdateArduinoState } from './contributions/update-arduino-state'; import { TerminalWidgetImpl } from './theia/terminal/terminal-widget-impl'; import { TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget'; +import { TerminalFrontendContribution } from './theia/terminal/terminal-frontend-contribution'; +import { TerminalFrontendContribution as TheiaTerminalFrontendContribution } from '@theia/terminal/lib/browser/terminal-frontend-contribution' // Hack to fix copy/cut/paste issue after electron version update in Theia. // https://github.com/eclipse-theia/theia/issues/12487 @@ -1031,4 +1033,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => { // Patch terminal issues. rebind(TerminalWidget).to(TerminalWidgetImpl).inTransientScope(); + bind(TerminalFrontendContribution).toSelf().inSingletonScope(); + rebind(TheiaTerminalFrontendContribution).toService(TerminalFrontendContribution); }); diff --git a/arduino-ide-extension/src/browser/theia/terminal/terminal-frontend-contribution.ts b/arduino-ide-extension/src/browser/theia/terminal/terminal-frontend-contribution.ts new file mode 100644 index 000000000..13020175d --- /dev/null +++ b/arduino-ide-extension/src/browser/theia/terminal/terminal-frontend-contribution.ts @@ -0,0 +1,38 @@ +import { TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar'; +import { CommandRegistry } from '@theia/core/lib/common/command'; +import { Widget } from '@theia/core/shared/@phosphor/widgets'; +import { injectable } from '@theia/core/shared/inversify'; +import { TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget'; +import { + TerminalCommands, + TerminalFrontendContribution as TheiaTerminalFrontendContribution, +} from '@theia/terminal/lib/browser/terminal-frontend-contribution'; + +// Patch for https://github.com/eclipse-theia/theia/pull/12626 +@injectable() +export class TerminalFrontendContribution extends TheiaTerminalFrontendContribution { + override registerCommands(commands: CommandRegistry): void { + super.registerCommands(commands); + commands.unregisterCommand(TerminalCommands.SPLIT); + commands.registerCommand(TerminalCommands.SPLIT, { + execute: () => this.splitTerminal(), + isEnabled: (w) => this.withWidget(w, () => true), + isVisible: (w) => this.withWidget(w, () => true), + }); + } + + override registerToolbarItems(toolbar: TabBarToolbarRegistry): void { + super.registerToolbarItems(toolbar); + toolbar.unregisterItem(TerminalCommands.SPLIT.id); + } + + private withWidget( + widget: Widget | undefined, + fn: (widget: TerminalWidget) => T + ): T | false { + if (widget instanceof TerminalWidget) { + return fn(widget); + } + return false; + } +}