diff --git a/src/vs/platform/contextkey/common/contextkey.ts b/src/vs/platform/contextkey/common/contextkey.ts index 3281940fb7507..55e154645ece2 100644 --- a/src/vs/platform/contextkey/common/contextkey.ts +++ b/src/vs/platform/contextkey/common/contextkey.ts @@ -998,7 +998,6 @@ export interface IContextKeyService { onDidChangeContext: Event; bufferChangeEvents(callback: Function): void; - createKey(key: string, defaultValue: T | undefined): IContextKey; contextMatchesRules(rules: ContextKeyExpression | undefined): boolean; getContextKeyValue(key: string): T | undefined; diff --git a/src/vs/platform/list/browser/listService.ts b/src/vs/platform/list/browser/listService.ts index 586b2304f3c7b..ea3a652aa7e98 100644 --- a/src/vs/platform/list/browser/listService.ts +++ b/src/vs/platform/list/browser/listService.ts @@ -255,9 +255,11 @@ export class WorkbenchList extends List { const selection = this.getSelection(); const focus = this.getFocus(); - this.listHasSelectionOrFocus.set(selection.length > 0 || focus.length > 0); - this.listMultiSelection.set(selection.length > 1); - this.listDoubleSelection.set(selection.length === 2); + this.contextKeyService.bufferChangeEvents(() => { + this.listHasSelectionOrFocus.set(selection.length > 0 || focus.length > 0); + this.listMultiSelection.set(selection.length > 1); + this.listDoubleSelection.set(selection.length === 2); + }); })); this.disposables.add(this.onDidChangeFocus(() => { const selection = this.getSelection(); @@ -906,9 +908,11 @@ class WorkbenchTreeInternals { const selection = tree.getSelection(); const focus = tree.getFocus(); - this.hasSelectionOrFocus.set(selection.length > 0 || focus.length > 0); - this.hasMultiSelection.set(selection.length > 1); - this.hasDoubleSelection.set(selection.length === 2); + this.contextKeyService.bufferChangeEvents(() => { + this.hasSelectionOrFocus.set(selection.length > 0 || focus.length > 0); + this.hasMultiSelection.set(selection.length > 1); + this.hasDoubleSelection.set(selection.length === 2); + }); }), tree.onDidChangeFocus(() => { const selection = tree.getSelection(); diff --git a/src/vs/workbench/browser/parts/editor/titleControl.ts b/src/vs/workbench/browser/parts/editor/titleControl.ts index debadbd7e9322..c4865014080e0 100644 --- a/src/vs/workbench/browser/parts/editor/titleControl.ts +++ b/src/vs/workbench/browser/parts/editor/titleControl.ts @@ -223,9 +223,11 @@ export abstract class TitleControl extends Themable { this.editorToolBarMenuDisposables.clear(); // Update contexts - this.resourceContext.set(this.group.activeEditor ? withUndefinedAsNull(toResource(this.group.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY })) : null); - this.editorPinnedContext.set(this.group.activeEditor ? this.group.isPinned(this.group.activeEditor) : false); - this.editorStickyContext.set(this.group.activeEditor ? this.group.isSticky(this.group.activeEditor) : false); + this.contextKeyService.bufferChangeEvents(() => { + this.resourceContext.set(this.group.activeEditor ? withUndefinedAsNull(toResource(this.group.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY })) : null); + this.editorPinnedContext.set(this.group.activeEditor ? this.group.isPinned(this.group.activeEditor) : false); + this.editorStickyContext.set(this.group.activeEditor ? this.group.isSticky(this.group.activeEditor) : false); + }); // Editor actions require the editor control to be there, so we retrieve it via service const activeEditorPane = this.group.activeEditorPane; diff --git a/src/vs/workbench/common/resources.ts b/src/vs/workbench/common/resources.ts index 2a7844da48f34..18ea0bfedb449 100644 --- a/src/vs/workbench/common/resources.ts +++ b/src/vs/workbench/common/resources.ts @@ -39,19 +39,19 @@ export class ResourceContextKey extends Disposable implements IContextKey { private readonly _isFileSystemResource: IContextKey; constructor( - @IContextKeyService contextKeyService: IContextKeyService, + @IContextKeyService private readonly _contextKeyService: IContextKeyService, @IFileService private readonly _fileService: IFileService, @IModeService private readonly _modeService: IModeService ) { super(); - this._schemeKey = ResourceContextKey.Scheme.bindTo(contextKeyService); - this._filenameKey = ResourceContextKey.Filename.bindTo(contextKeyService); - this._langIdKey = ResourceContextKey.LangId.bindTo(contextKeyService); - this._resourceKey = ResourceContextKey.Resource.bindTo(contextKeyService); - this._extensionKey = ResourceContextKey.Extension.bindTo(contextKeyService); - this._hasResource = ResourceContextKey.HasResource.bindTo(contextKeyService); - this._isFileSystemResource = ResourceContextKey.IsFileSystemResource.bindTo(contextKeyService); + this._schemeKey = ResourceContextKey.Scheme.bindTo(this._contextKeyService); + this._filenameKey = ResourceContextKey.Filename.bindTo(this._contextKeyService); + this._langIdKey = ResourceContextKey.LangId.bindTo(this._contextKeyService); + this._resourceKey = ResourceContextKey.Resource.bindTo(this._contextKeyService); + this._extensionKey = ResourceContextKey.Extension.bindTo(this._contextKeyService); + this._hasResource = ResourceContextKey.HasResource.bindTo(this._contextKeyService); + this._isFileSystemResource = ResourceContextKey.IsFileSystemResource.bindTo(this._contextKeyService); this._register(_fileService.onDidChangeFileSystemProviderRegistrations(() => { const resource = this._resourceKey.get(); @@ -66,24 +66,28 @@ export class ResourceContextKey extends Disposable implements IContextKey { set(value: URI | null) { if (!ResourceContextKey._uriEquals(this._resourceKey.get(), value)) { - this._resourceKey.set(value); - this._schemeKey.set(value ? value.scheme : null); - this._filenameKey.set(value ? basename(value) : null); - this._langIdKey.set(value ? this._modeService.getModeIdByFilepathOrFirstLine(value) : null); - this._extensionKey.set(value ? extname(value) : null); - this._hasResource.set(!!value); - this._isFileSystemResource.set(value ? this._fileService.canHandleResource(value) : false); + this._contextKeyService.bufferChangeEvents(() => { + this._resourceKey.set(value); + this._schemeKey.set(value ? value.scheme : null); + this._filenameKey.set(value ? basename(value) : null); + this._langIdKey.set(value ? this._modeService.getModeIdByFilepathOrFirstLine(value) : null); + this._extensionKey.set(value ? extname(value) : null); + this._hasResource.set(!!value); + this._isFileSystemResource.set(value ? this._fileService.canHandleResource(value) : false); + }); } } reset(): void { - this._schemeKey.reset(); - this._langIdKey.reset(); - this._resourceKey.reset(); - this._langIdKey.reset(); - this._extensionKey.reset(); - this._hasResource.reset(); - this._isFileSystemResource.reset(); + this._contextKeyService.bufferChangeEvents(() => { + this._schemeKey.reset(); + this._langIdKey.reset(); + this._resourceKey.reset(); + this._langIdKey.reset(); + this._extensionKey.reset(); + this._hasResource.reset(); + this._isFileSystemResource.reset(); + }); } get(): URI | undefined { diff --git a/src/vs/workbench/services/history/browser/history.ts b/src/vs/workbench/services/history/browser/history.ts index 1c560e38b83fc..370837ef71c14 100644 --- a/src/vs/workbench/services/history/browser/history.ts +++ b/src/vs/workbench/services/history/browser/history.ts @@ -755,10 +755,12 @@ export class HistoryService extends Disposable implements IHistoryService { private readonly canReopenClosedEditorContextKey = (new RawContextKey('canReopenClosedEditor', false)).bindTo(this.contextKeyService); private updateContextKeys(): void { - this.canNavigateBackContextKey.set(this.navigationStack.length > 0 && this.navigationStackIndex > 0); - this.canNavigateForwardContextKey.set(this.navigationStack.length > 0 && this.navigationStackIndex < this.navigationStack.length - 1); - this.canNavigateToLastEditLocationContextKey.set(!!this.lastEditLocation); - this.canReopenClosedEditorContextKey.set(this.recentlyClosedEditors.length > 0); + this.contextKeyService.bufferChangeEvents(() => { + this.canNavigateBackContextKey.set(this.navigationStack.length > 0 && this.navigationStackIndex > 0); + this.canNavigateForwardContextKey.set(this.navigationStack.length > 0 && this.navigationStackIndex < this.navigationStack.length - 1); + this.canNavigateToLastEditLocationContextKey.set(!!this.lastEditLocation); + this.canReopenClosedEditorContextKey.set(this.recentlyClosedEditors.length > 0); + }); } //#endregion