1
+ import * as vscode from "vscode" ;
1
2
import { createCSSRule } from "vs/base/browser/dom" ;
2
3
import { Emitter , Event } from "vs/base/common/event" ;
3
4
import { IDisposable } from "vs/base/common/lifecycle" ;
@@ -13,6 +14,7 @@ import { IInstantiationService, ServiceIdentifier } from "vs/platform/instantiat
13
14
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection" ;
14
15
import { INotificationService } from "vs/platform/notification/common/notification" ;
15
16
import { Registry } from "vs/platform/registry/common/platform" ;
17
+ import { IStatusbarEntry , IStatusbarEntryAccessor , IStatusbarService , StatusbarAlignment } from "vs/platform/statusbar/common/statusbar" ;
16
18
import { IStorageService } from "vs/platform/storage/common/storage" ;
17
19
import { ITelemetryService } from "vs/platform/telemetry/common/telemetry" ;
18
20
import { IThemeService } from "vs/platform/theme/common/themeService" ;
@@ -28,7 +30,6 @@ import { IEditorService } from "vs/workbench/services/editor/common/editorServic
28
30
import { IExtensionService } from "vs/workbench/services/extensions/common/extensions" ;
29
31
import { IWorkbenchLayoutService } from "vs/workbench/services/layout/browser/layoutService" ;
30
32
import { IViewletService } from "vs/workbench/services/viewlet/browser/viewlet" ;
31
- import * as vscode from "vscode" ;
32
33
33
34
/**
34
35
* Client-side implementation of VS Code's API.
@@ -42,6 +43,7 @@ export const vscodeApi = (serviceCollection: ServiceCollection): Partial<typeof
42
43
const notificationService = getService ( INotificationService ) ;
43
44
const fileService = getService ( IFileService ) ;
44
45
const viewsRegistry = Registry . as < IViewsRegistry > ( ViewsExtensions . ViewsRegistry ) ;
46
+ const statusbarService = getService ( IStatusbarService ) ;
45
47
46
48
// It would be nice to just export what VS Code creates but it looks to me
47
49
// that it assumes it's running in the extension host and wouldn't work here.
@@ -52,8 +54,10 @@ export const vscodeApi = (serviceCollection: ServiceCollection): Partial<typeof
52
54
EventEmitter : Emitter ,
53
55
TreeItemCollapsibleState : extHostTypes . TreeItemCollapsibleState ,
54
56
FileSystemError : extHostTypes . FileSystemError ,
55
- FileType : FileType ,
57
+ FileType,
56
58
Uri : URI ,
59
+ StatusBarAlignment,
60
+ ThemeColor,
57
61
commands : {
58
62
executeCommand : < T = any > ( commandId : string , ...args : any [ ] ) : Promise < T | undefined > => {
59
63
return commandService . executeCommand ( commandId , ...args ) ;
@@ -63,6 +67,9 @@ export const vscodeApi = (serviceCollection: ServiceCollection): Partial<typeof
63
67
} ,
64
68
} as Partial < typeof vscode . commands > ,
65
69
window : {
70
+ createStatusBarItem : ( alignment ?: vscode . StatusBarAlignment , priority ?: number ) : vscode . StatusBarItem => {
71
+ return new StatusBarEntry ( statusbarService , alignment , priority ) ;
72
+ } ,
66
73
registerTreeDataProvider : < T > ( id : string , dataProvider : vscode . TreeDataProvider < T > ) : IDisposable => {
67
74
const tree = new TreeViewDataProvider ( dataProvider ) ;
68
75
const view = viewsRegistry . getView ( id ) ;
@@ -267,3 +274,96 @@ class TreeViewDataProvider<T> implements ITreeViewDataProvider {
267
274
: `coder-tree-item-uuid/${ generateUuid ( ) } ` ;
268
275
}
269
276
}
277
+
278
+ class ThemeColor {
279
+ public id : string ;
280
+ constructor ( id : string ) {
281
+ this . id = id ;
282
+ }
283
+ }
284
+
285
+ interface IStatusBarEntry extends IStatusbarEntry {
286
+ alignment : StatusbarAlignment ;
287
+ priority ?: number ;
288
+ }
289
+
290
+ enum StatusBarAlignment {
291
+ Left = 1 ,
292
+ Right = 2
293
+ }
294
+
295
+ class StatusBarEntry implements vscode . StatusBarItem {
296
+ private static ID = 0 ;
297
+
298
+ private _id : number ;
299
+ private entry : IStatusBarEntry ;
300
+ private _visible : boolean ;
301
+ private disposed : boolean ;
302
+ private statusId : string ;
303
+ private statusName : string ;
304
+ private accessor ?: IStatusbarEntryAccessor ;
305
+ private timeout : any ;
306
+
307
+ constructor ( private readonly statusbarService : IStatusbarService , alignment ?: vscode . StatusBarAlignment , priority ?: number ) {
308
+ this . _id = StatusBarEntry . ID -- ;
309
+ this . statusId = "web-api" ;
310
+ this . statusName = "Web API" ;
311
+ this . entry = {
312
+ alignment : alignment && alignment === StatusBarAlignment . Left
313
+ ? StatusbarAlignment . LEFT : StatusbarAlignment . RIGHT ,
314
+ text : "" ,
315
+ priority,
316
+ } ;
317
+ }
318
+
319
+ public get alignment ( ) : vscode . StatusBarAlignment {
320
+ return this . entry . alignment === StatusbarAlignment . LEFT
321
+ ? StatusBarAlignment . Left : StatusBarAlignment . Right ;
322
+ }
323
+
324
+ public get id ( ) : number { return this . _id ; }
325
+ public get priority ( ) : number | undefined { return this . entry . priority ; }
326
+ public get text ( ) : string { return this . entry . text ; }
327
+ public get tooltip ( ) : string | undefined { return this . entry . tooltip ; }
328
+ public get color ( ) : string | ThemeColor | undefined { return this . entry . color ; }
329
+ public get command ( ) : string | undefined { return this . entry . command ; }
330
+
331
+ public set text ( text : string ) { this . update ( { text } ) ; }
332
+ public set tooltip ( tooltip : string | undefined ) { this . update ( { tooltip } ) ; }
333
+ public set color ( color : string | ThemeColor | undefined ) { this . update ( { color } ) ; }
334
+ public set command ( command : string | undefined ) { this . update ( { command } ) ; }
335
+
336
+ public show ( ) : void {
337
+ this . _visible = true ;
338
+ this . update ( ) ;
339
+ }
340
+
341
+ public hide ( ) : void {
342
+ clearTimeout ( this . timeout ) ;
343
+ this . _visible = false ;
344
+ if ( this . accessor ) {
345
+ this . accessor . dispose ( ) ;
346
+ this . accessor = undefined ;
347
+ }
348
+ }
349
+
350
+ private update ( values ?: Partial < IStatusBarEntry > ) : void {
351
+ this . entry = { ...this . entry , ...values } ;
352
+ if ( this . disposed || ! this . _visible ) {
353
+ return ;
354
+ }
355
+ clearTimeout ( this . timeout ) ;
356
+ this . timeout = setTimeout ( ( ) => {
357
+ if ( ! this . accessor ) {
358
+ this . accessor = this . statusbarService . addEntry ( this . entry , this . statusId , this . statusName , this . entry . alignment , this . priority ) ;
359
+ } else {
360
+ this . accessor . update ( this . entry ) ;
361
+ }
362
+ } , 0 ) ;
363
+ }
364
+
365
+ public dispose ( ) : void {
366
+ this . hide ( ) ;
367
+ this . disposed = true ;
368
+ }
369
+ }
0 commit comments