1
1
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' ;
4
9
import { WorkspaceService as TheiaWorkspaceService } from '@theia/workspace/lib/browser/workspace-service' ;
10
+ import { EditorMode } from '../../editor-mode' ;
5
11
import { ConfigService } from '../../../common/protocol/config-service' ;
6
12
import { SketchesService } from '../../../common/protocol/sketches-service' ;
7
13
import { ArduinoWorkspaceRootResolver } from '../../arduino-workspace-resolver' ;
8
- import { EditorMode } from '../../editor-mode' ;
9
14
10
15
@injectable ( )
11
16
export class WorkspaceService extends TheiaWorkspaceService {
@@ -25,7 +30,19 @@ export class WorkspaceService extends TheiaWorkspaceService {
25
30
@inject ( MessageService )
26
31
protected readonly messageService : MessageService ;
27
32
33
+ @inject ( ApplicationServer )
34
+ protected readonly applicationServer : ApplicationServer ;
35
+
28
36
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
+ }
29
46
30
47
protected getDefaultWorkspaceUri ( ) : Promise < string | undefined > {
31
48
if ( this . workspaceUri ) {
@@ -74,4 +91,32 @@ export class WorkspaceService extends TheiaWorkspaceService {
74
91
return sketchFolder ;
75
92
}
76
93
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
+
77
122
}
0 commit comments