mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-31 11:58:20 +01:00
Dispose status bar items on EH restart, but only those that were defined by extensions, not those defined statically (#186479)
nit: Static items that have been "refined" by extensions will keep the refined state on restart re https://github.com/microsoft/vscode/issues/186315
This commit is contained in:
@@ -6,11 +6,11 @@
|
||||
import { MainThreadStatusBarShape, MainContext, ExtHostContext, StatusBarItemDto } from '../common/extHost.protocol';
|
||||
import { ThemeColor } from 'vs/base/common/themables';
|
||||
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
|
||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { Command } from 'vs/editor/common/languages';
|
||||
import { IAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility';
|
||||
import { IMarkdownString } from 'vs/base/common/htmlContent';
|
||||
import { IExtensionStatusBarItemService } from 'vs/workbench/api/browser/statusBarExtensionPoint';
|
||||
import { IExtensionStatusBarItemService, StatusBarUpdateKind } from 'vs/workbench/api/browser/statusBarExtensionPoint';
|
||||
import { IStatusbarEntry, StatusbarAlignment } from 'vs/workbench/services/statusbar/browser/statusbar';
|
||||
|
||||
@extHostNamedCustomer(MainContext.MainThreadStatusBar)
|
||||
@@ -57,7 +57,10 @@ export class MainThreadStatusBar implements MainThreadStatusBarShape {
|
||||
}
|
||||
|
||||
$setEntry(entryId: string, id: string, extensionId: string | undefined, name: string, text: string, tooltip: IMarkdownString | string | undefined, command: Command | undefined, color: string | ThemeColor | undefined, backgroundColor: string | ThemeColor | undefined, alignLeft: boolean, priority: number | undefined, accessibilityInformation: IAccessibilityInformation | undefined): void {
|
||||
this.statusbarService.setOrUpdateEntry(entryId, id, extensionId, name, text, tooltip, command, color, backgroundColor, alignLeft, priority, accessibilityInformation);
|
||||
const kind = this.statusbarService.setOrUpdateEntry(entryId, id, extensionId, name, text, tooltip, command, color, backgroundColor, alignLeft, priority, accessibilityInformation);
|
||||
if (kind === StatusBarUpdateKind.DidDefine) {
|
||||
this._store.add(toDisposable(() => this.statusbarService.unsetEntry(entryId)));
|
||||
}
|
||||
}
|
||||
|
||||
$disposeEntry(entryId: string) {
|
||||
|
||||
@@ -38,12 +38,17 @@ export type ExtensionStatusBarEntry = [string, {
|
||||
priority: number;
|
||||
}];
|
||||
|
||||
export const enum StatusBarUpdateKind {
|
||||
DidDefine,
|
||||
DidUpdate
|
||||
}
|
||||
|
||||
export interface IExtensionStatusBarItemService {
|
||||
readonly _serviceBrand: undefined;
|
||||
|
||||
onDidChange: Event<IExtensionStatusBarItemChangeEvent>;
|
||||
|
||||
setOrUpdateEntry(id: string, statusId: string, extensionId: string | undefined, name: string, text: string, tooltip: IMarkdownString | string | undefined, command: Command | undefined, color: string | ThemeColor | undefined, backgroundColor: string | ThemeColor | undefined, alignLeft: boolean, priority: number | undefined, accessibilityInformation: IAccessibilityInformation | undefined): void;
|
||||
setOrUpdateEntry(id: string, statusId: string, extensionId: string | undefined, name: string, text: string, tooltip: IMarkdownString | string | undefined, command: Command | undefined, color: string | ThemeColor | undefined, backgroundColor: string | ThemeColor | undefined, alignLeft: boolean, priority: number | undefined, accessibilityInformation: IAccessibilityInformation | undefined): StatusBarUpdateKind;
|
||||
|
||||
unsetEntry(id: string): void;
|
||||
|
||||
@@ -72,7 +77,7 @@ class ExtensionStatusBarItemService implements IExtensionStatusBarItemService {
|
||||
id: string, extensionId: string | undefined, name: string, text: string, tooltip: IMarkdownString | string | undefined,
|
||||
command: Command | undefined, color: string | ThemeColor | undefined, backgroundColor: string | ThemeColor | undefined,
|
||||
alignLeft: boolean, priority: number | undefined, accessibilityInformation: IAccessibilityInformation | undefined
|
||||
): void {
|
||||
): StatusBarUpdateKind {
|
||||
// if there are icons in the text use the tooltip for the aria label
|
||||
let ariaLabel: string;
|
||||
let role: string | undefined = undefined;
|
||||
@@ -129,16 +134,19 @@ class ExtensionStatusBarItemService implements IExtensionStatusBarItemService {
|
||||
});
|
||||
|
||||
this._onDidChange.fire({ added: [entryId, { entry, alignment, priority }] });
|
||||
return StatusBarUpdateKind.DidDefine;
|
||||
|
||||
} else {
|
||||
// Otherwise update
|
||||
existingEntry.accessor.update(entry);
|
||||
existingEntry.entry = entry;
|
||||
return StatusBarUpdateKind.DidUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
unsetEntry(entryId: string): void {
|
||||
this._entries.get(entryId)?.disposable.dispose();
|
||||
this._entries.delete(entryId);
|
||||
}
|
||||
|
||||
getEntries(): Iterable<[string, { entry: IStatusbarEntry; alignment: MainThreadStatusBarAlignment; priority: number }]> {
|
||||
@@ -267,7 +275,7 @@ export class StatusBarItemsExtensionPoint {
|
||||
|
||||
const fullItemId = asStatusBarItemIdentifier(entry.description.identifier, candidate.id);
|
||||
|
||||
statusBarItemsService.setOrUpdateEntry(
|
||||
const kind = statusBarItemsService.setOrUpdateEntry(
|
||||
fullItemId,
|
||||
fullItemId,
|
||||
ExtensionIdentifier.toKey(entry.description.identifier),
|
||||
@@ -281,7 +289,9 @@ export class StatusBarItemsExtensionPoint {
|
||||
candidate.accessibilityInformation
|
||||
);
|
||||
|
||||
contributions.add(toDisposable(() => statusBarItemsService.unsetEntry(fullItemId)));
|
||||
if (kind === StatusBarUpdateKind.DidDefine) {
|
||||
contributions.add(toDisposable(() => statusBarItemsService.unsetEntry(fullItemId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user