1+ import * as vscode from "vscode" ;
12import { createCSSRule } from "vs/base/browser/dom" ;
23import { Emitter , Event } from "vs/base/common/event" ;
34import { IDisposable } from "vs/base/common/lifecycle" ;
@@ -13,6 +14,7 @@ import { IInstantiationService, ServiceIdentifier } from "vs/platform/instantiat
1314import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection" ;
1415import { INotificationService } from "vs/platform/notification/common/notification" ;
1516import { Registry } from "vs/platform/registry/common/platform" ;
17+ import { IStatusbarEntry , IStatusbarEntryAccessor , IStatusbarService , StatusbarAlignment } from "vs/platform/statusbar/common/statusbar" ;
1618import { IStorageService } from "vs/platform/storage/common/storage" ;
1719import { ITelemetryService } from "vs/platform/telemetry/common/telemetry" ;
1820import { IThemeService } from "vs/platform/theme/common/themeService" ;
@@ -28,7 +30,6 @@ import { IEditorService } from "vs/workbench/services/editor/common/editorServic
2830import { IExtensionService } from "vs/workbench/services/extensions/common/extensions" ;
2931import { IWorkbenchLayoutService } from "vs/workbench/services/layout/browser/layoutService" ;
3032import { IViewletService } from "vs/workbench/services/viewlet/browser/viewlet" ;
31- import * as vscode from "vscode" ;
3233
3334/**
3435 * Client-side implementation of VS Code's API.
@@ -42,6 +43,7 @@ export const vscodeApi = (serviceCollection: ServiceCollection): Partial<typeof
4243 const notificationService = getService ( INotificationService ) ;
4344 const fileService = getService ( IFileService ) ;
4445 const viewsRegistry = Registry . as < IViewsRegistry > ( ViewsExtensions . ViewsRegistry ) ;
46+ const statusbarService = getService ( IStatusbarService ) ;
4547
4648 // It would be nice to just export what VS Code creates but it looks to me
4749 // 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
5254 EventEmitter : Emitter ,
5355 TreeItemCollapsibleState : extHostTypes . TreeItemCollapsibleState ,
5456 FileSystemError : extHostTypes . FileSystemError ,
55- FileType : FileType ,
57+ FileType,
5658 Uri : URI ,
59+ StatusBarAlignment,
60+ ThemeColor,
5761 commands : {
5862 executeCommand : < T = any > ( commandId : string , ...args : any [ ] ) : Promise < T | undefined > => {
5963 return commandService . executeCommand ( commandId , ...args ) ;
@@ -63,6 +67,9 @@ export const vscodeApi = (serviceCollection: ServiceCollection): Partial<typeof
6367 } ,
6468 } as Partial < typeof vscode . commands > ,
6569 window : {
70+ createStatusBarItem : ( alignment ?: vscode . StatusBarAlignment , priority ?: number ) : vscode . StatusBarItem => {
71+ return new StatusBarEntry ( statusbarService , alignment , priority ) ;
72+ } ,
6673 registerTreeDataProvider : < T > ( id : string , dataProvider : vscode . TreeDataProvider < T > ) : IDisposable => {
6774 const tree = new TreeViewDataProvider ( dataProvider ) ;
6875 const view = viewsRegistry . getView ( id ) ;
@@ -267,3 +274,96 @@ class TreeViewDataProvider<T> implements ITreeViewDataProvider {
267274 : `coder-tree-item-uuid/${ generateUuid ( ) } ` ;
268275 }
269276}
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