Skip to content

Commit 824d1df

Browse files
author
Akos Kitta
committed
aligned the title with the Java IDE.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent 445ffed commit 824d1df

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

arduino-ide-extension/src/browser/theia/workspace/workspace-service.ts

+48-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { injectable, inject } from 'inversify';
2-
import { MessageService } from '@theia/core';
3-
import { LabelProvider } from '@theia/core/lib/browser';
2+
import URI from '@theia/core/lib/common/uri';
3+
import { EditorWidget } from '@theia/editor/lib/browser';
4+
import { LabelProvider } from '@theia/core/lib/browser/label-provider';
5+
import { MessageService } from '@theia/core/lib/common/message-service';
6+
import { ApplicationServer } from '@theia/core/lib/common/application-protocol';
7+
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
8+
import { FocusTracker, Widget } from '@theia/core/lib/browser';
49
import { WorkspaceService as TheiaWorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
10+
import { EditorMode } from '../../editor-mode';
511
import { ConfigService } from '../../../common/protocol/config-service';
612
import { SketchesService } from '../../../common/protocol/sketches-service';
713
import { ArduinoWorkspaceRootResolver } from '../../arduino-workspace-resolver';
8-
import { EditorMode } from '../../editor-mode';
914

1015
@injectable()
1116
export class WorkspaceService extends TheiaWorkspaceService {
@@ -25,7 +30,19 @@ export class WorkspaceService extends TheiaWorkspaceService {
2530
@inject(MessageService)
2631
protected readonly messageService: MessageService;
2732

33+
@inject(ApplicationServer)
34+
protected readonly applicationServer: ApplicationServer;
35+
2836
private workspaceUri?: Promise<string | undefined>;
37+
private version?: string
38+
39+
async onStart(application: FrontendApplication): Promise<void> {
40+
const info = await this.applicationServer.getApplicationInfo();
41+
this.version = info?.version;
42+
application.shell.onDidChangeCurrentWidget(this.onCurrentWidgetChange.bind(this));
43+
const newValue = application.shell.currentWidget ? application.shell.currentWidget : null;
44+
this.onCurrentWidgetChange({ newValue, oldValue: null });
45+
}
2946

3047
protected getDefaultWorkspaceUri(): Promise<string | undefined> {
3148
if (this.workspaceUri) {
@@ -74,4 +91,32 @@ export class WorkspaceService extends TheiaWorkspaceService {
7491
return sketchFolder;
7592
}
7693

94+
protected onCurrentWidgetChange({ newValue }: FocusTracker.IChangedArgs<Widget>): void {
95+
if (newValue instanceof EditorWidget) {
96+
const { uri } = newValue.editor;
97+
if (uri.toString().endsWith('.ino')) {
98+
this.updateTitle();
99+
} else {
100+
const title = this.workspaceTitle;
101+
const fileName = this.labelProvider.getName(uri);
102+
document.title = this.formatTitle(title ? `${title} - ${fileName}` : fileName);
103+
}
104+
} else {
105+
this.updateTitle();
106+
}
107+
}
108+
109+
protected formatTitle(title?: string): string {
110+
const version = this.version ? ` ${this.version}` : '';
111+
const name = `${this.applicationName} ${version}`;
112+
return title ? `${title} | ${name}` : name;
113+
}
114+
115+
protected get workspaceTitle(): string | undefined {
116+
if (this.workspace) {
117+
const uri = new URI(this.workspace.uri);
118+
return this.labelProvider.getName(uri);
119+
}
120+
}
121+
77122
}

0 commit comments

Comments
 (0)