From 824d1df4bdedcd038912ed0d2145f6131093311a Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Tue, 21 Jul 2020 10:54:31 +0200 Subject: [PATCH] aligned the title with the Java IDE. Signed-off-by: Akos Kitta --- .../theia/workspace/workspace-service.ts | 51 +++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/arduino-ide-extension/src/browser/theia/workspace/workspace-service.ts b/arduino-ide-extension/src/browser/theia/workspace/workspace-service.ts index 12c375d0..cce01a80 100644 --- a/arduino-ide-extension/src/browser/theia/workspace/workspace-service.ts +++ b/arduino-ide-extension/src/browser/theia/workspace/workspace-service.ts @@ -1,11 +1,16 @@ import { injectable, inject } from 'inversify'; -import { MessageService } from '@theia/core'; -import { LabelProvider } from '@theia/core/lib/browser'; +import URI from '@theia/core/lib/common/uri'; +import { EditorWidget } from '@theia/editor/lib/browser'; +import { LabelProvider } from '@theia/core/lib/browser/label-provider'; +import { MessageService } from '@theia/core/lib/common/message-service'; +import { ApplicationServer } from '@theia/core/lib/common/application-protocol'; +import { FrontendApplication } from '@theia/core/lib/browser/frontend-application'; +import { FocusTracker, Widget } from '@theia/core/lib/browser'; import { WorkspaceService as TheiaWorkspaceService } from '@theia/workspace/lib/browser/workspace-service'; +import { EditorMode } from '../../editor-mode'; import { ConfigService } from '../../../common/protocol/config-service'; import { SketchesService } from '../../../common/protocol/sketches-service'; import { ArduinoWorkspaceRootResolver } from '../../arduino-workspace-resolver'; -import { EditorMode } from '../../editor-mode'; @injectable() export class WorkspaceService extends TheiaWorkspaceService { @@ -25,7 +30,19 @@ export class WorkspaceService extends TheiaWorkspaceService { @inject(MessageService) protected readonly messageService: MessageService; + @inject(ApplicationServer) + protected readonly applicationServer: ApplicationServer; + private workspaceUri?: Promise; + private version?: string + + async onStart(application: FrontendApplication): Promise { + const info = await this.applicationServer.getApplicationInfo(); + this.version = info?.version; + application.shell.onDidChangeCurrentWidget(this.onCurrentWidgetChange.bind(this)); + const newValue = application.shell.currentWidget ? application.shell.currentWidget : null; + this.onCurrentWidgetChange({ newValue, oldValue: null }); + } protected getDefaultWorkspaceUri(): Promise { if (this.workspaceUri) { @@ -74,4 +91,32 @@ export class WorkspaceService extends TheiaWorkspaceService { return sketchFolder; } + protected onCurrentWidgetChange({ newValue }: FocusTracker.IChangedArgs): void { + if (newValue instanceof EditorWidget) { + const { uri } = newValue.editor; + if (uri.toString().endsWith('.ino')) { + this.updateTitle(); + } else { + const title = this.workspaceTitle; + const fileName = this.labelProvider.getName(uri); + document.title = this.formatTitle(title ? `${title} - ${fileName}` : fileName); + } + } else { + this.updateTitle(); + } + } + + protected formatTitle(title?: string): string { + const version = this.version ? ` ${this.version}` : ''; + const name = `${this.applicationName} ${version}`; + return title ? `${title} | ${name}` : name; + } + + protected get workspaceTitle(): string | undefined { + if (this.workspace) { + const uri = new URI(this.workspace.uri); + return this.labelProvider.getName(uri); + } + } + }