Skip to content

Commit 12bc26b

Browse files
committed
Implement status bar API
1 parent 976a326 commit 12bc26b

File tree

2 files changed

+109
-16
lines changed

2 files changed

+109
-16
lines changed

scripts/vscode.patch

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ index add4dfb2fc..18fc71df51 100644
355355

356356
get onDidLanguagesChange(): Event<void> { return this.channel.listen('onDidLanguagesChange'); }
357357
diff --git a/src/vs/platform/log/common/logIpc.ts b/src/vs/platform/log/common/logIpc.ts
358-
index 9f68b645b6..b422a3c809 100644
358+
index 9f68b645b6..1e224cc29a 100644
359359
--- a/src/vs/platform/log/common/logIpc.ts
360360
+++ b/src/vs/platform/log/common/logIpc.ts
361361
@@ -26,6 +26,7 @@ export class LogLevelSetterChannel implements IServerChannel {
@@ -377,13 +377,6 @@ index 9f68b645b6..b422a3c809 100644
377377
}
378378

379379
export class FollowerLogService extends DelegatedLogService implements ILogService {
380-
@@ -56,4 +61,4 @@ export class FollowerLogService extends DelegatedLogService implements ILogServi
381-
setLevel(level: LogLevel): void {
382-
this.master.setLevel(level);
383-
}
384-
-}
385-
\ No newline at end of file
386-
+}
387380
diff --git a/src/vs/platform/product/node/package.ts b/src/vs/platform/product/node/package.ts
388381
index d39c5877d6..c189d6f19f 100644
389382
--- a/src/vs/platform/product/node/package.ts
@@ -562,7 +555,7 @@ index 9fdeeeb1a1..db2dc002c3 100644
562555
}
563556

564557
diff --git a/src/vs/workbench/browser/web.main.ts b/src/vs/workbench/browser/web.main.ts
565-
index f5944ce974..a3fcc391fd 100644
558+
index f5944ce974..f2094de18b 100644
566559
--- a/src/vs/workbench/browser/web.main.ts
567560
+++ b/src/vs/workbench/browser/web.main.ts
568561
@@ -45,6 +45,7 @@ import { FileLogService } from 'vs/platform/log/common/fileLogService';
@@ -573,14 +566,14 @@ index f5944ce974..a3fcc391fd 100644
573566

574567
class CodeRendererMain extends Disposable {
575568

576-
@@ -57,6 +58,7 @@ class CodeRendererMain extends Disposable {
569+
@@ -94,6 +95,7 @@ class CodeRendererMain extends Disposable {
577570

578-
async open(): Promise<void> {
579-
const services = await this.initServices();
571+
// Startup
572+
workbench.startup();
580573
+ await initialize(services.serviceCollection);
574+
}
581575

582-
await domContentLoaded();
583-
mark('willStartWorkbench');
576+
private restoreBaseTheme(): void {
584577
@@ -204,6 +206,7 @@ class CodeRendererMain extends Disposable {
585578
const channel = connection.getChannel<IChannel>(REMOTE_FILE_SYSTEM_CHANNEL_NAME);
586579
const remoteFileSystemProvider = this._register(new RemoteExtensionsFileSystemProvider(channel, remoteAgentService.getEnvironment()));

src/api.ts

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as vscode from "vscode";
12
import { createCSSRule } from "vs/base/browser/dom";
23
import { Emitter, Event } from "vs/base/common/event";
34
import { IDisposable } from "vs/base/common/lifecycle";
@@ -13,6 +14,7 @@ import { IInstantiationService, ServiceIdentifier } from "vs/platform/instantiat
1314
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection";
1415
import { INotificationService } from "vs/platform/notification/common/notification";
1516
import { Registry } from "vs/platform/registry/common/platform";
17+
import { IStatusbarEntry, IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment } from "vs/platform/statusbar/common/statusbar";
1618
import { IStorageService } from "vs/platform/storage/common/storage";
1719
import { ITelemetryService } from "vs/platform/telemetry/common/telemetry";
1820
import { IThemeService } from "vs/platform/theme/common/themeService";
@@ -28,7 +30,6 @@ import { IEditorService } from "vs/workbench/services/editor/common/editorServic
2830
import { IExtensionService } from "vs/workbench/services/extensions/common/extensions";
2931
import { IWorkbenchLayoutService } from "vs/workbench/services/layout/browser/layoutService";
3032
import { 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

Comments
 (0)