aligned the title with the Java IDE.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-07-21 10:54:31 +02:00
parent 445ffedf02
commit 824d1df4bd

View File

@ -1,11 +1,16 @@
import { injectable, inject } from 'inversify'; import { injectable, inject } from 'inversify';
import { MessageService } from '@theia/core'; import URI from '@theia/core/lib/common/uri';
import { LabelProvider } from '@theia/core/lib/browser'; 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 { WorkspaceService as TheiaWorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
import { EditorMode } from '../../editor-mode';
import { ConfigService } from '../../../common/protocol/config-service'; import { ConfigService } from '../../../common/protocol/config-service';
import { SketchesService } from '../../../common/protocol/sketches-service'; import { SketchesService } from '../../../common/protocol/sketches-service';
import { ArduinoWorkspaceRootResolver } from '../../arduino-workspace-resolver'; import { ArduinoWorkspaceRootResolver } from '../../arduino-workspace-resolver';
import { EditorMode } from '../../editor-mode';
@injectable() @injectable()
export class WorkspaceService extends TheiaWorkspaceService { export class WorkspaceService extends TheiaWorkspaceService {
@ -25,7 +30,19 @@ export class WorkspaceService extends TheiaWorkspaceService {
@inject(MessageService) @inject(MessageService)
protected readonly messageService: MessageService; protected readonly messageService: MessageService;
@inject(ApplicationServer)
protected readonly applicationServer: ApplicationServer;
private workspaceUri?: Promise<string | undefined>; private workspaceUri?: Promise<string | undefined>;
private version?: string
async onStart(application: FrontendApplication): Promise<void> {
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<string | undefined> { protected getDefaultWorkspaceUri(): Promise<string | undefined> {
if (this.workspaceUri) { if (this.workspaceUri) {
@ -74,4 +91,32 @@ export class WorkspaceService extends TheiaWorkspaceService {
return sketchFolder; return sketchFolder;
} }
protected onCurrentWidgetChange({ newValue }: FocusTracker.IChangedArgs<Widget>): 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);
}
}
} }