|
5 | 5 |
|
6 | 6 | import { StatusBarAlignment as ExtHostStatusBarAlignment, Disposable, ThemeColor, asStatusBarItemIdentifier } from './extHostTypes';
|
7 | 7 | import type * as vscode from 'vscode';
|
8 |
| -import { MainContext, MainThreadStatusBarShape, IMainContext, ICommandDto } from './extHost.protocol'; |
| 8 | +import { MainContext, MainThreadStatusBarShape, IMainContext, ICommandDto, ExtHostStatusBarShape, StatusBarItemDto } from './extHost.protocol'; |
9 | 9 | import { localize } from 'vs/nls';
|
10 | 10 | import { CommandsConverter } from 'vs/workbench/api/common/extHostCommands';
|
11 | 11 | import { DisposableStore } from 'vs/base/common/lifecycle';
|
@@ -54,22 +54,25 @@ export class ExtHostStatusBarEntry implements vscode.StatusBarItem {
|
54 | 54 | private _timeoutHandle: any;
|
55 | 55 | private _accessibilityInformation?: vscode.AccessibilityInformation;
|
56 | 56 |
|
57 |
| - constructor(proxy: MainThreadStatusBarShape, commands: CommandsConverter, extension: IExtensionDescription, id?: string, alignment?: ExtHostStatusBarAlignment, priority?: number); |
58 |
| - constructor(proxy: MainThreadStatusBarShape, commands: CommandsConverter, extension: IExtensionDescription | undefined, id: string, alignment?: ExtHostStatusBarAlignment, priority?: number); |
59 |
| - constructor(proxy: MainThreadStatusBarShape, commands: CommandsConverter, extension?: IExtensionDescription, id?: string, alignment: ExtHostStatusBarAlignment = ExtHostStatusBarAlignment.Left, priority?: number) { |
| 57 | + constructor(proxy: MainThreadStatusBarShape, commands: CommandsConverter, staticItems: ReadonlyMap<string, StatusBarItemDto>, extension: IExtensionDescription, id?: string, alignment?: ExtHostStatusBarAlignment, priority?: number); |
| 58 | + constructor(proxy: MainThreadStatusBarShape, commands: CommandsConverter, staticItems: ReadonlyMap<string, StatusBarItemDto>, extension: IExtensionDescription | undefined, id: string, alignment?: ExtHostStatusBarAlignment, priority?: number); |
| 59 | + constructor(proxy: MainThreadStatusBarShape, commands: CommandsConverter, staticItems: ReadonlyMap<string, StatusBarItemDto>, extension?: IExtensionDescription, id?: string, alignment: ExtHostStatusBarAlignment = ExtHostStatusBarAlignment.Left, priority?: number) { |
60 | 60 | this.#proxy = proxy;
|
61 | 61 | this.#commands = commands;
|
62 | 62 |
|
63 | 63 | if (id && extension) {
|
64 | 64 | this._entryId = asStatusBarItemIdentifier(extension.identifier, id);
|
65 |
| - proxy.$hasEntry(this._entryId).then(exits => { |
66 |
| - if (exits && this._visible === undefined) { |
67 |
| - // mark new item as visible if it already exists |
68 |
| - // this can only happen when an item was contributed by an extension |
69 |
| - this._visible = true; |
70 |
| - this.update(); |
71 |
| - } |
72 |
| - }); |
| 65 | + // if new item already exists mark it as visible and copy properties |
| 66 | + // this can only happen when an item was contributed by an extension |
| 67 | + const item = staticItems.get(this._entryId); |
| 68 | + if (item) { |
| 69 | + this._visible = true; |
| 70 | + this._alignment = item.alignLeft ? ExtHostStatusBarAlignment.Left : ExtHostStatusBarAlignment.Right; |
| 71 | + this._priority = item.priority; |
| 72 | + this.name = item.name; |
| 73 | + this.text = item.text; |
| 74 | + this.command = item.command; |
| 75 | + } |
73 | 76 | } else {
|
74 | 77 | this._entryId = String(ExtHostStatusBarEntry.ID_GEN++);
|
75 | 78 | }
|
@@ -208,7 +211,7 @@ export class ExtHostStatusBarEntry implements vscode.StatusBarItem {
|
208 | 211 | public hide(): void {
|
209 | 212 | clearTimeout(this._timeoutHandle);
|
210 | 213 | this._visible = false;
|
211 |
| - this.#proxy.$dispose(this._entryId); |
| 214 | + this.#proxy.$disposeEntry(this._entryId); |
212 | 215 | }
|
213 | 216 |
|
214 | 217 | private update(): void {
|
@@ -307,22 +310,29 @@ class StatusBarMessage {
|
307 | 310 | }
|
308 | 311 | }
|
309 | 312 |
|
310 |
| -export class ExtHostStatusBar { |
| 313 | +export class ExtHostStatusBar implements ExtHostStatusBarShape { |
311 | 314 |
|
312 | 315 | private readonly _proxy: MainThreadStatusBarShape;
|
313 | 316 | private readonly _commands: CommandsConverter;
|
314 | 317 | private readonly _statusMessage: StatusBarMessage;
|
| 318 | + private readonly _existingItems = new Map<string, StatusBarItemDto>(); |
315 | 319 |
|
316 | 320 | constructor(mainContext: IMainContext, commands: CommandsConverter) {
|
317 | 321 | this._proxy = mainContext.getProxy(MainContext.MainThreadStatusBar);
|
318 | 322 | this._commands = commands;
|
319 | 323 | this._statusMessage = new StatusBarMessage(this);
|
320 | 324 | }
|
321 | 325 |
|
| 326 | + $acceptStaticEntries(added: StatusBarItemDto[]): void { |
| 327 | + for (const item of added) { |
| 328 | + this._existingItems.set(item.entryId, item); |
| 329 | + } |
| 330 | + } |
| 331 | + |
322 | 332 | createStatusBarEntry(extension: IExtensionDescription | undefined, id: string, alignment?: ExtHostStatusBarAlignment, priority?: number): vscode.StatusBarItem;
|
323 | 333 | createStatusBarEntry(extension: IExtensionDescription, id?: string, alignment?: ExtHostStatusBarAlignment, priority?: number): vscode.StatusBarItem;
|
324 | 334 | createStatusBarEntry(extension: IExtensionDescription, id: string, alignment?: ExtHostStatusBarAlignment, priority?: number): vscode.StatusBarItem {
|
325 |
| - return new ExtHostStatusBarEntry(this._proxy, this._commands, extension, id, alignment, priority); |
| 335 | + return new ExtHostStatusBarEntry(this._proxy, this._commands, this._existingItems, extension, id, alignment, priority); |
326 | 336 | }
|
327 | 337 |
|
328 | 338 | setStatusBarMessage(text: string, timeoutOrThenable?: number | Thenable<any>): Disposable {
|
|
0 commit comments