diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 904e3fc5fabe0..8a49db0edb71e 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -2028,31 +2028,31 @@ export class EditorModeContext extends Disposable { constructor( private readonly _editor: CodeEditorWidget, - contextKeyService: IContextKeyService, + private readonly _contextKeyService: IContextKeyService, private readonly _languageFeaturesService: ILanguageFeaturesService, ) { super(); - this._langId = EditorContextKeys.languageId.bindTo(contextKeyService); - this._hasCompletionItemProvider = EditorContextKeys.hasCompletionItemProvider.bindTo(contextKeyService); - this._hasCodeActionsProvider = EditorContextKeys.hasCodeActionsProvider.bindTo(contextKeyService); - this._hasCodeLensProvider = EditorContextKeys.hasCodeLensProvider.bindTo(contextKeyService); - this._hasDefinitionProvider = EditorContextKeys.hasDefinitionProvider.bindTo(contextKeyService); - this._hasDeclarationProvider = EditorContextKeys.hasDeclarationProvider.bindTo(contextKeyService); - this._hasImplementationProvider = EditorContextKeys.hasImplementationProvider.bindTo(contextKeyService); - this._hasTypeDefinitionProvider = EditorContextKeys.hasTypeDefinitionProvider.bindTo(contextKeyService); - this._hasHoverProvider = EditorContextKeys.hasHoverProvider.bindTo(contextKeyService); - this._hasDocumentHighlightProvider = EditorContextKeys.hasDocumentHighlightProvider.bindTo(contextKeyService); - this._hasDocumentSymbolProvider = EditorContextKeys.hasDocumentSymbolProvider.bindTo(contextKeyService); - this._hasReferenceProvider = EditorContextKeys.hasReferenceProvider.bindTo(contextKeyService); - this._hasRenameProvider = EditorContextKeys.hasRenameProvider.bindTo(contextKeyService); - this._hasSignatureHelpProvider = EditorContextKeys.hasSignatureHelpProvider.bindTo(contextKeyService); - this._hasInlayHintsProvider = EditorContextKeys.hasInlayHintsProvider.bindTo(contextKeyService); - this._hasDocumentFormattingProvider = EditorContextKeys.hasDocumentFormattingProvider.bindTo(contextKeyService); - this._hasDocumentSelectionFormattingProvider = EditorContextKeys.hasDocumentSelectionFormattingProvider.bindTo(contextKeyService); - this._hasMultipleDocumentFormattingProvider = EditorContextKeys.hasMultipleDocumentFormattingProvider.bindTo(contextKeyService); - this._hasMultipleDocumentSelectionFormattingProvider = EditorContextKeys.hasMultipleDocumentSelectionFormattingProvider.bindTo(contextKeyService); - this._isInWalkThrough = EditorContextKeys.isInWalkThroughSnippet.bindTo(contextKeyService); + this._langId = EditorContextKeys.languageId.bindTo(_contextKeyService); + this._hasCompletionItemProvider = EditorContextKeys.hasCompletionItemProvider.bindTo(_contextKeyService); + this._hasCodeActionsProvider = EditorContextKeys.hasCodeActionsProvider.bindTo(_contextKeyService); + this._hasCodeLensProvider = EditorContextKeys.hasCodeLensProvider.bindTo(_contextKeyService); + this._hasDefinitionProvider = EditorContextKeys.hasDefinitionProvider.bindTo(_contextKeyService); + this._hasDeclarationProvider = EditorContextKeys.hasDeclarationProvider.bindTo(_contextKeyService); + this._hasImplementationProvider = EditorContextKeys.hasImplementationProvider.bindTo(_contextKeyService); + this._hasTypeDefinitionProvider = EditorContextKeys.hasTypeDefinitionProvider.bindTo(_contextKeyService); + this._hasHoverProvider = EditorContextKeys.hasHoverProvider.bindTo(_contextKeyService); + this._hasDocumentHighlightProvider = EditorContextKeys.hasDocumentHighlightProvider.bindTo(_contextKeyService); + this._hasDocumentSymbolProvider = EditorContextKeys.hasDocumentSymbolProvider.bindTo(_contextKeyService); + this._hasReferenceProvider = EditorContextKeys.hasReferenceProvider.bindTo(_contextKeyService); + this._hasRenameProvider = EditorContextKeys.hasRenameProvider.bindTo(_contextKeyService); + this._hasSignatureHelpProvider = EditorContextKeys.hasSignatureHelpProvider.bindTo(_contextKeyService); + this._hasInlayHintsProvider = EditorContextKeys.hasInlayHintsProvider.bindTo(_contextKeyService); + this._hasDocumentFormattingProvider = EditorContextKeys.hasDocumentFormattingProvider.bindTo(_contextKeyService); + this._hasDocumentSelectionFormattingProvider = EditorContextKeys.hasDocumentSelectionFormattingProvider.bindTo(_contextKeyService); + this._hasMultipleDocumentFormattingProvider = EditorContextKeys.hasMultipleDocumentFormattingProvider.bindTo(_contextKeyService); + this._hasMultipleDocumentSelectionFormattingProvider = EditorContextKeys.hasMultipleDocumentSelectionFormattingProvider.bindTo(_contextKeyService); + this._isInWalkThrough = EditorContextKeys.isInWalkThroughSnippet.bindTo(_contextKeyService); const update = () => this._update(); @@ -2086,23 +2086,25 @@ export class EditorModeContext extends Disposable { } reset() { - this._langId.reset(); - this._hasCompletionItemProvider.reset(); - this._hasCodeActionsProvider.reset(); - this._hasCodeLensProvider.reset(); - this._hasDefinitionProvider.reset(); - this._hasDeclarationProvider.reset(); - this._hasImplementationProvider.reset(); - this._hasTypeDefinitionProvider.reset(); - this._hasHoverProvider.reset(); - this._hasDocumentHighlightProvider.reset(); - this._hasDocumentSymbolProvider.reset(); - this._hasReferenceProvider.reset(); - this._hasRenameProvider.reset(); - this._hasDocumentFormattingProvider.reset(); - this._hasDocumentSelectionFormattingProvider.reset(); - this._hasSignatureHelpProvider.reset(); - this._isInWalkThrough.reset(); + this._contextKeyService.bufferChangeEvents(() => { + this._langId.reset(); + this._hasCompletionItemProvider.reset(); + this._hasCodeActionsProvider.reset(); + this._hasCodeLensProvider.reset(); + this._hasDefinitionProvider.reset(); + this._hasDeclarationProvider.reset(); + this._hasImplementationProvider.reset(); + this._hasTypeDefinitionProvider.reset(); + this._hasHoverProvider.reset(); + this._hasDocumentHighlightProvider.reset(); + this._hasDocumentSymbolProvider.reset(); + this._hasReferenceProvider.reset(); + this._hasRenameProvider.reset(); + this._hasDocumentFormattingProvider.reset(); + this._hasDocumentSelectionFormattingProvider.reset(); + this._hasSignatureHelpProvider.reset(); + this._isInWalkThrough.reset(); + }); } private _update() { @@ -2111,26 +2113,28 @@ export class EditorModeContext extends Disposable { this.reset(); return; } - this._langId.set(model.getLanguageId()); - this._hasCompletionItemProvider.set(this._languageFeaturesService.completionProvider.has(model)); - this._hasCodeActionsProvider.set(this._languageFeaturesService.codeActionProvider.has(model)); - this._hasCodeLensProvider.set(this._languageFeaturesService.codeLensProvider.has(model)); - this._hasDefinitionProvider.set(this._languageFeaturesService.definitionProvider.has(model)); - this._hasDeclarationProvider.set(this._languageFeaturesService.declarationProvider.has(model)); - this._hasImplementationProvider.set(this._languageFeaturesService.implementationProvider.has(model)); - this._hasTypeDefinitionProvider.set(this._languageFeaturesService.typeDefinitionProvider.has(model)); - this._hasHoverProvider.set(this._languageFeaturesService.hoverProvider.has(model)); - this._hasDocumentHighlightProvider.set(this._languageFeaturesService.documentHighlightProvider.has(model)); - this._hasDocumentSymbolProvider.set(this._languageFeaturesService.documentSymbolProvider.has(model)); - this._hasReferenceProvider.set(this._languageFeaturesService.referenceProvider.has(model)); - this._hasRenameProvider.set(this._languageFeaturesService.renameProvider.has(model)); - this._hasSignatureHelpProvider.set(this._languageFeaturesService.signatureHelpProvider.has(model)); - this._hasInlayHintsProvider.set(this._languageFeaturesService.inlayHintsProvider.has(model)); - this._hasDocumentFormattingProvider.set(this._languageFeaturesService.documentFormattingEditProvider.has(model) || this._languageFeaturesService.documentRangeFormattingEditProvider.has(model)); - this._hasDocumentSelectionFormattingProvider.set(this._languageFeaturesService.documentRangeFormattingEditProvider.has(model)); - this._hasMultipleDocumentFormattingProvider.set(this._languageFeaturesService.documentFormattingEditProvider.all(model).length + this._languageFeaturesService.documentRangeFormattingEditProvider.all(model).length > 1); - this._hasMultipleDocumentSelectionFormattingProvider.set(this._languageFeaturesService.documentRangeFormattingEditProvider.all(model).length > 1); - this._isInWalkThrough.set(model.uri.scheme === Schemas.walkThroughSnippet); + this._contextKeyService.bufferChangeEvents(() => { + this._langId.set(model.getLanguageId()); + this._hasCompletionItemProvider.set(this._languageFeaturesService.completionProvider.has(model)); + this._hasCodeActionsProvider.set(this._languageFeaturesService.codeActionProvider.has(model)); + this._hasCodeLensProvider.set(this._languageFeaturesService.codeLensProvider.has(model)); + this._hasDefinitionProvider.set(this._languageFeaturesService.definitionProvider.has(model)); + this._hasDeclarationProvider.set(this._languageFeaturesService.declarationProvider.has(model)); + this._hasImplementationProvider.set(this._languageFeaturesService.implementationProvider.has(model)); + this._hasTypeDefinitionProvider.set(this._languageFeaturesService.typeDefinitionProvider.has(model)); + this._hasHoverProvider.set(this._languageFeaturesService.hoverProvider.has(model)); + this._hasDocumentHighlightProvider.set(this._languageFeaturesService.documentHighlightProvider.has(model)); + this._hasDocumentSymbolProvider.set(this._languageFeaturesService.documentSymbolProvider.has(model)); + this._hasReferenceProvider.set(this._languageFeaturesService.referenceProvider.has(model)); + this._hasRenameProvider.set(this._languageFeaturesService.renameProvider.has(model)); + this._hasSignatureHelpProvider.set(this._languageFeaturesService.signatureHelpProvider.has(model)); + this._hasInlayHintsProvider.set(this._languageFeaturesService.inlayHintsProvider.has(model)); + this._hasDocumentFormattingProvider.set(this._languageFeaturesService.documentFormattingEditProvider.has(model) || this._languageFeaturesService.documentRangeFormattingEditProvider.has(model)); + this._hasDocumentSelectionFormattingProvider.set(this._languageFeaturesService.documentRangeFormattingEditProvider.has(model)); + this._hasMultipleDocumentFormattingProvider.set(this._languageFeaturesService.documentFormattingEditProvider.all(model).length + this._languageFeaturesService.documentRangeFormattingEditProvider.all(model).length > 1); + this._hasMultipleDocumentSelectionFormattingProvider.set(this._languageFeaturesService.documentRangeFormattingEditProvider.all(model).length > 1); + this._isInWalkThrough.set(model.uri.scheme === Schemas.walkThroughSnippet); + }); } } diff --git a/src/vs/platform/contextkey/browser/contextKeyService.ts b/src/vs/platform/contextkey/browser/contextKeyService.ts index 83ec3cd500062..07a136ef7b97c 100644 --- a/src/vs/platform/contextkey/browser/contextKeyService.ts +++ b/src/vs/platform/contextkey/browser/contextKeyService.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Emitter, Event, MicrotaskEmitter } from 'vs/base/common/event'; +import { Emitter, Event, PauseableEmitter } from 'vs/base/common/event'; import { Iterable } from 'vs/base/common/iterator'; import { DisposableStore, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle'; import { TernarySearchTree } from 'vs/base/common/map'; @@ -270,7 +270,7 @@ export abstract class AbstractContextKeyService implements IContextKeyService { protected _isDisposed: boolean; protected _myContextId: number; - protected _onDidChangeContext = new MicrotaskEmitter({ merge: input => new CompositeContextKeyChangeEvent(input) }); + protected _onDidChangeContext = new PauseableEmitter({ merge: input => new CompositeContextKeyChangeEvent(input) }); readonly onDidChangeContext = this._onDidChangeContext.event; constructor(myContextId: number) { @@ -291,6 +291,16 @@ export abstract class AbstractContextKeyService implements IContextKeyService { return new ContextKey(this, key, defaultValue); } + + bufferChangeEvents(callback: Function): void { + this._onDidChangeContext.pause(); + try { + callback(); + } finally { + this._onDidChangeContext.resume(); + } + } + public createScoped(domNode: IContextKeyServiceTarget): IContextKeyService { if (this._isDisposed) { throw new Error(`AbstractContextKeyService has been disposed`); @@ -534,6 +544,10 @@ class OverlayContextKeyService implements IContextKeyService { this.overlay = new Map(overlay); } + bufferChangeEvents(callback: Function): void { + this.parent.bufferChangeEvents(callback); + } + createKey(): IContextKey { throw new Error('Not supported.'); } diff --git a/src/vs/platform/contextkey/common/contextkey.ts b/src/vs/platform/contextkey/common/contextkey.ts index 5c6bc41ba3078..97473d6c93fee 100644 --- a/src/vs/platform/contextkey/common/contextkey.ts +++ b/src/vs/platform/contextkey/common/contextkey.ts @@ -1619,6 +1619,7 @@ export interface IContextKeyService { dispose(): void; onDidChangeContext: Event; + bufferChangeEvents(callback: Function): void; createKey(key: string, defaultValue: T | undefined): IContextKey; contextMatchesRules(rules: ContextKeyExpression | undefined): boolean; diff --git a/src/vs/platform/contextkey/test/browser/contextkey.test.ts b/src/vs/platform/contextkey/test/browser/contextkey.test.ts index 7ab5dad199455..50309c6fe6b6c 100644 --- a/src/vs/platform/contextkey/test/browser/contextkey.test.ts +++ b/src/vs/platform/contextkey/test/browser/contextkey.test.ts @@ -103,10 +103,11 @@ suite('ContextKeyService', () => { let fired = false; const event = child.onDidChangeContext(e => fired = true); - - root.setContext('testA', 10); - root.setContext('testB', 20); - root.setContext('testD', 30); + root.bufferChangeEvents(() => { + root.setContext('testA', 10); + root.setContext('testB', 20); + root.setContext('testD', 30); + }); assert.strictEqual(fired, false, 'Should not fire event when overridden key is updated in parent'); event.dispose(); @@ -138,9 +139,11 @@ suite('ContextKeyService', () => { def.complete(undefined); }); - root.setContext('testA', 10); - root.setContext('testB', 20); - root.setContext('testC', 30); + root.bufferChangeEvents(() => { + root.setContext('testA', 10); + root.setContext('testB', 20); + root.setContext('testC', 30); + }); return def.p; }); diff --git a/src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts b/src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts index 8d4a6fc7159d2..cada490a6a09b 100644 --- a/src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts +++ b/src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts @@ -114,6 +114,7 @@ suite('AbstractKeybindingService', () => { _serviceBrand: undefined, dispose: undefined!, onDidChangeContext: undefined!, + bufferChangeEvents() { }, createKey: undefined!, contextMatchesRules: undefined!, getContextKeyValue: undefined!, diff --git a/src/vs/platform/keybinding/test/common/mockKeybindingService.ts b/src/vs/platform/keybinding/test/common/mockKeybindingService.ts index 9e098e490c3bf..7fc604326a81e 100644 --- a/src/vs/platform/keybinding/test/common/mockKeybindingService.ts +++ b/src/vs/platform/keybinding/test/common/mockKeybindingService.ts @@ -53,6 +53,7 @@ export class MockContextKeyService implements IContextKeyService { public get onDidChangeContext(): Event { return Event.None; } + public bufferChangeEvents(callback: () => void) { callback(); } public getContextKeyValue(key: string) { const value = this._keys.get(key); if (value) { diff --git a/src/vs/platform/list/browser/listService.ts b/src/vs/platform/list/browser/listService.ts index 20e40802b5f05..197fb970f66e3 100644 --- a/src/vs/platform/list/browser/listService.ts +++ b/src/vs/platform/list/browser/listService.ts @@ -284,9 +284,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(); @@ -555,9 +557,11 @@ export class WorkbenchTable extends Table { 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(); @@ -1209,9 +1213,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 dd20ef9c63029..6a15de4e4d5f2 100644 --- a/src/vs/workbench/browser/parts/editor/titleControl.ts +++ b/src/vs/workbench/browser/parts/editor/titleControl.ts @@ -241,19 +241,21 @@ export abstract class TitleControl extends Themable { this.editorToolBarMenuDisposables.clear(); // Update contexts - const activeEditor = this.group.activeEditor; + this.contextKeyService.bufferChangeEvents(() => { + const activeEditor = this.group.activeEditor; - this.resourceContext.set(withUndefinedAsNull(EditorResourceAccessor.getOriginalUri(activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }))); + this.resourceContext.set(withUndefinedAsNull(EditorResourceAccessor.getOriginalUri(activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }))); - this.editorPinnedContext.set(activeEditor ? this.group.isPinned(activeEditor) : false); - this.editorIsFirstContext.set(activeEditor ? this.group.isFirst(activeEditor) : false); - this.editorIsLastContext.set(activeEditor ? this.group.isLast(activeEditor) : false); - this.editorStickyContext.set(activeEditor ? this.group.isSticky(activeEditor) : false); + this.editorPinnedContext.set(activeEditor ? this.group.isPinned(activeEditor) : false); + this.editorIsFirstContext.set(activeEditor ? this.group.isFirst(activeEditor) : false); + this.editorIsLastContext.set(activeEditor ? this.group.isLast(activeEditor) : false); + this.editorStickyContext.set(activeEditor ? this.group.isSticky(activeEditor) : false); - this.editorCanSplitInGroupContext.set(activeEditor ? activeEditor.hasCapability(EditorInputCapabilities.CanSplitInGroup) : false); - this.sideBySideEditorContext.set(activeEditor?.typeId === SideBySideEditorInput.ID); + this.editorCanSplitInGroupContext.set(activeEditor ? activeEditor.hasCapability(EditorInputCapabilities.CanSplitInGroup) : false); + this.sideBySideEditorContext.set(activeEditor?.typeId === SideBySideEditorInput.ID); - this.groupLockedContext.set(this.group.isLocked); + this.groupLockedContext.set(this.group.isLocked); + }); // 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/browser/parts/views/treeView.ts b/src/vs/workbench/browser/parts/views/treeView.ts index c417668352a2f..4052142154c3f 100644 --- a/src/vs/workbench/browser/parts/views/treeView.ts +++ b/src/vs/workbench/browser/parts/views/treeView.ts @@ -275,9 +275,11 @@ abstract class AbstractTreeView extends Disposable implements ITreeView { // Remember when adding to this method that it isn't called until the the view is visible, meaning that // properties could be set and events could be fired before we're initialized and that this needs to be handled. - this.initializeShowCollapseAllAction(); - this.initializeCollapseAllToggle(); - this.initializeShowRefreshAction(); + this.contextKeyService.bufferChangeEvents(() => { + this.initializeShowCollapseAllAction(); + this.initializeCollapseAllToggle(); + this.initializeShowRefreshAction(); + }); this.treeViewDnd = this.instantiationService.createInstance(CustomTreeViewDragAndDrop, this.id); if (this._dragAndDropController) { diff --git a/src/vs/workbench/common/contextkeys.ts b/src/vs/workbench/common/contextkeys.ts index eccd882db7454..7739005ed0aad 100644 --- a/src/vs/workbench/common/contextkeys.ts +++ b/src/vs/workbench/common/contextkeys.ts @@ -220,28 +220,32 @@ export class ResourceContextKey { return; } this._value = value; - this._resourceKey.set(value ? value.toString() : null); - this._schemeKey.set(value ? value.scheme : null); - this._filenameKey.set(value ? basename(value) : null); - this._dirnameKey.set(value ? dirname(value).fsPath : null); - this._pathKey.set(value ? value.fsPath : null); - this._setLangId(); - this._extensionKey.set(value ? extname(value) : null); - this._hasResource.set(Boolean(value)); - this._isFileSystemResource.set(value ? this._fileService.hasProvider(value) : false); + this._contextKeyService.bufferChangeEvents(() => { + this._resourceKey.set(value ? value.toString() : null); + this._schemeKey.set(value ? value.scheme : null); + this._filenameKey.set(value ? basename(value) : null); + this._dirnameKey.set(value ? dirname(value).fsPath : null); + this._pathKey.set(value ? value.fsPath : null); + this._setLangId(); + this._extensionKey.set(value ? extname(value) : null); + this._hasResource.set(Boolean(value)); + this._isFileSystemResource.set(value ? this._fileService.hasProvider(value) : false); + }); } reset(): void { this._value = undefined; - this._resourceKey.reset(); - this._schemeKey.reset(); - this._filenameKey.reset(); - this._dirnameKey.reset(); - this._pathKey.reset(); - this._langIdKey.reset(); - this._extensionKey.reset(); - this._hasResource.reset(); - this._isFileSystemResource.reset(); + this._contextKeyService.bufferChangeEvents(() => { + this._resourceKey.reset(); + this._schemeKey.reset(); + this._filenameKey.reset(); + this._dirnameKey.reset(); + this._pathKey.reset(); + this._langIdKey.reset(); + this._extensionKey.reset(); + this._hasResource.reset(); + this._isFileSystemResource.reset(); + }); } get(): URI | undefined { diff --git a/src/vs/workbench/contrib/debug/browser/debugService.ts b/src/vs/workbench/contrib/debug/browser/debugService.ts index f08917df876f9..5d6622a3b7f67 100644 --- a/src/vs/workbench/contrib/debug/browser/debugService.ts +++ b/src/vs/workbench/contrib/debug/browser/debugService.ts @@ -94,7 +94,7 @@ export class DebugService implements IDebugService { @IDialogService private readonly dialogService: IDialogService, @IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService, @IWorkspaceContextService private readonly contextService: IWorkspaceContextService, - @IContextKeyService contextKeyService: IContextKeyService, + @IContextKeyService private readonly contextKeyService: IContextKeyService, @ILifecycleService private readonly lifecycleService: ILifecycleService, @IInstantiationService private readonly instantiationService: IInstantiationService, @IExtensionService private readonly extensionService: IExtensionService, @@ -120,14 +120,16 @@ export class DebugService implements IDebugService { this.disposables.add(this.configurationManager); this.debugStorage = this.instantiationService.createInstance(DebugStorage); - this.debugType = CONTEXT_DEBUG_TYPE.bindTo(contextKeyService); - this.debugState = CONTEXT_DEBUG_STATE.bindTo(contextKeyService); - this.inDebugMode = CONTEXT_IN_DEBUG_MODE.bindTo(contextKeyService); - this.debugUx = CONTEXT_DEBUG_UX.bindTo(contextKeyService); - this.debugUx.set(this.debugStorage.loadDebugUxState()); - this.breakpointsExist = CONTEXT_BREAKPOINTS_EXIST.bindTo(contextKeyService); - // Need to set disassemblyViewFocus here to make it in the same context as the debug event handlers - this.disassemblyViewFocus = CONTEXT_DISASSEMBLY_VIEW_FOCUS.bindTo(contextKeyService); + contextKeyService.bufferChangeEvents(() => { + this.debugType = CONTEXT_DEBUG_TYPE.bindTo(contextKeyService); + this.debugState = CONTEXT_DEBUG_STATE.bindTo(contextKeyService); + this.inDebugMode = CONTEXT_IN_DEBUG_MODE.bindTo(contextKeyService); + this.debugUx = CONTEXT_DEBUG_UX.bindTo(contextKeyService); + this.debugUx.set(this.debugStorage.loadDebugUxState()); + this.breakpointsExist = CONTEXT_BREAKPOINTS_EXIST.bindTo(contextKeyService); + // Need to set disassemblyViewFocus here to make it in the same context as the debug event handlers + this.disassemblyViewFocus = CONTEXT_DISASSEMBLY_VIEW_FOCUS.bindTo(contextKeyService); + }); this.chosenEnvironments = this.debugStorage.loadChosenEnvironments(); this.model = this.instantiationService.createInstance(DebugModel, this.debugStorage); @@ -183,11 +185,13 @@ export class DebugService implements IDebugService { this.disposables.add(this.model.onDidChangeBreakpoints(() => setBreakpointsExistContext())); this.disposables.add(editorService.onDidActiveEditorChange(() => { - if (editorService.activeEditor === DisassemblyViewInput.instance) { - this.disassemblyViewFocus.set(true); - } else { - this.disassemblyViewFocus.reset(); - } + this.contextKeyService.bufferChangeEvents(() => { + if (editorService.activeEditor === DisassemblyViewInput.instance) { + this.disassemblyViewFocus.set(true); + } else { + this.disassemblyViewFocus.reset(); + } + }); })); this.disposables.add(this.lifecycleService.onBeforeShutdown(() => { @@ -271,12 +275,14 @@ export class DebugService implements IDebugService { private onStateChange(): void { const state = this.state; if (this.previousState !== state) { - this.debugState.set(getStateLabel(state)); - this.inDebugMode.set(state !== State.Inactive); - // Only show the simple ux if debug is not yet started and if no launch.json exists - const debugUxValue = ((state !== State.Inactive && state !== State.Initializing) || (this.adapterManager.hasEnabledDebuggers() && this.configurationManager.selectedConfiguration.name)) ? 'default' : 'simple'; - this.debugUx.set(debugUxValue); - this.debugStorage.storeDebugUxState(debugUxValue); + this.contextKeyService.bufferChangeEvents(() => { + this.debugState.set(getStateLabel(state)); + this.inDebugMode.set(state !== State.Inactive); + // Only show the simple ux if debug is not yet started and if no launch.json exists + const debugUxValue = ((state !== State.Inactive && state !== State.Initializing) || (this.adapterManager.hasEnabledDebuggers() && this.configurationManager.selectedConfiguration.name)) ? 'default' : 'simple'; + this.debugUx.set(debugUxValue); + this.debugStorage.storeDebugUxState(debugUxValue); + }); this.previousState = state; this._onDidChangeState.fire(state); } diff --git a/src/vs/workbench/contrib/debug/browser/disassemblyView.ts b/src/vs/workbench/contrib/debug/browser/disassemblyView.ts index 6f54ee99e17d0..200b4cd8a348b 100644 --- a/src/vs/workbench/contrib/debug/browser/disassemblyView.ts +++ b/src/vs/workbench/contrib/debug/browser/disassemblyView.ts @@ -783,7 +783,9 @@ export class DisassemblyViewContribution implements IWorkbenchContribution { @IDebugService debugService: IDebugService, @IContextKeyService contextKeyService: IContextKeyService ) { - this._languageSupportsDisassemleRequest = CONTEXT_LANGUAGE_SUPPORTS_DISASSEMBLE_REQUEST.bindTo(contextKeyService); + contextKeyService.bufferChangeEvents(() => { + this._languageSupportsDisassemleRequest = CONTEXT_LANGUAGE_SUPPORTS_DISASSEMBLE_REQUEST.bindTo(contextKeyService); + }); const onDidActiveEditorChangeListener = () => { if (this._onDidChangeModelLanguage) { diff --git a/src/vs/workbench/contrib/debug/common/debugViewModel.ts b/src/vs/workbench/contrib/debug/common/debugViewModel.ts index f1e03de46b475..c04aecb15e199 100644 --- a/src/vs/workbench/contrib/debug/common/debugViewModel.ts +++ b/src/vs/workbench/contrib/debug/common/debugViewModel.ts @@ -36,21 +36,23 @@ export class ViewModel implements IViewModel { private disassembleRequestSupported!: IContextKey; private focusedStackFrameHasInstructionPointerReference!: IContextKey; - constructor(contextKeyService: IContextKeyService) { - this.expressionSelectedContextKey = CONTEXT_EXPRESSION_SELECTED.bindTo(contextKeyService); - this.loadedScriptsSupportedContextKey = CONTEXT_LOADED_SCRIPTS_SUPPORTED.bindTo(contextKeyService); - this.stepBackSupportedContextKey = CONTEXT_STEP_BACK_SUPPORTED.bindTo(contextKeyService); - this.focusedSessionIsAttach = CONTEXT_FOCUSED_SESSION_IS_ATTACH.bindTo(contextKeyService); - this.restartFrameSupportedContextKey = CONTEXT_RESTART_FRAME_SUPPORTED.bindTo(contextKeyService); - this.stepIntoTargetsSupported = CONTEXT_STEP_INTO_TARGETS_SUPPORTED.bindTo(contextKeyService); - this.jumpToCursorSupported = CONTEXT_JUMP_TO_CURSOR_SUPPORTED.bindTo(contextKeyService); - this.setVariableSupported = CONTEXT_SET_VARIABLE_SUPPORTED.bindTo(contextKeyService); - this.setExpressionSupported = CONTEXT_SET_EXPRESSION_SUPPORTED.bindTo(contextKeyService); - this.multiSessionDebug = CONTEXT_MULTI_SESSION_DEBUG.bindTo(contextKeyService); - this.terminateDebuggeeSupported = CONTEXT_TERMINATE_DEBUGGEE_SUPPORTED.bindTo(contextKeyService); - this.suspendDebuggeeSupported = CONTEXT_SUSPEND_DEBUGGEE_SUPPORTED.bindTo(contextKeyService); - this.disassembleRequestSupported = CONTEXT_DISASSEMBLE_REQUEST_SUPPORTED.bindTo(contextKeyService); - this.focusedStackFrameHasInstructionPointerReference = CONTEXT_FOCUSED_STACK_FRAME_HAS_INSTRUCTION_POINTER_REFERENCE.bindTo(contextKeyService); + constructor(private contextKeyService: IContextKeyService) { + contextKeyService.bufferChangeEvents(() => { + this.expressionSelectedContextKey = CONTEXT_EXPRESSION_SELECTED.bindTo(contextKeyService); + this.loadedScriptsSupportedContextKey = CONTEXT_LOADED_SCRIPTS_SUPPORTED.bindTo(contextKeyService); + this.stepBackSupportedContextKey = CONTEXT_STEP_BACK_SUPPORTED.bindTo(contextKeyService); + this.focusedSessionIsAttach = CONTEXT_FOCUSED_SESSION_IS_ATTACH.bindTo(contextKeyService); + this.restartFrameSupportedContextKey = CONTEXT_RESTART_FRAME_SUPPORTED.bindTo(contextKeyService); + this.stepIntoTargetsSupported = CONTEXT_STEP_INTO_TARGETS_SUPPORTED.bindTo(contextKeyService); + this.jumpToCursorSupported = CONTEXT_JUMP_TO_CURSOR_SUPPORTED.bindTo(contextKeyService); + this.setVariableSupported = CONTEXT_SET_VARIABLE_SUPPORTED.bindTo(contextKeyService); + this.setExpressionSupported = CONTEXT_SET_EXPRESSION_SUPPORTED.bindTo(contextKeyService); + this.multiSessionDebug = CONTEXT_MULTI_SESSION_DEBUG.bindTo(contextKeyService); + this.terminateDebuggeeSupported = CONTEXT_TERMINATE_DEBUGGEE_SUPPORTED.bindTo(contextKeyService); + this.suspendDebuggeeSupported = CONTEXT_SUSPEND_DEBUGGEE_SUPPORTED.bindTo(contextKeyService); + this.disassembleRequestSupported = CONTEXT_DISASSEMBLE_REQUEST_SUPPORTED.bindTo(contextKeyService); + this.focusedStackFrameHasInstructionPointerReference = CONTEXT_FOCUSED_STACK_FRAME_HAS_INSTRUCTION_POINTER_REFERENCE.bindTo(contextKeyService); + }); } getId(): string { @@ -77,19 +79,21 @@ export class ViewModel implements IViewModel { this._focusedThread = thread; this._focusedSession = session; - this.loadedScriptsSupportedContextKey.set(session ? !!session.capabilities.supportsLoadedSourcesRequest : false); - this.stepBackSupportedContextKey.set(session ? !!session.capabilities.supportsStepBack : false); - this.restartFrameSupportedContextKey.set(session ? !!session.capabilities.supportsRestartFrame : false); - this.stepIntoTargetsSupported.set(session ? !!session.capabilities.supportsStepInTargetsRequest : false); - this.jumpToCursorSupported.set(session ? !!session.capabilities.supportsGotoTargetsRequest : false); - this.setVariableSupported.set(session ? !!session.capabilities.supportsSetVariable : false); - this.setExpressionSupported.set(session ? !!session.capabilities.supportsSetExpression : false); - this.terminateDebuggeeSupported.set(session ? !!session.capabilities.supportTerminateDebuggee : false); - this.suspendDebuggeeSupported.set(session ? !!session.capabilities.supportSuspendDebuggee : false); - this.disassembleRequestSupported.set(!!session?.capabilities.supportsDisassembleRequest); - this.focusedStackFrameHasInstructionPointerReference.set(!!stackFrame?.instructionPointerReference); - const attach = !!session && isSessionAttach(session); - this.focusedSessionIsAttach.set(attach); + this.contextKeyService.bufferChangeEvents(() => { + this.loadedScriptsSupportedContextKey.set(session ? !!session.capabilities.supportsLoadedSourcesRequest : false); + this.stepBackSupportedContextKey.set(session ? !!session.capabilities.supportsStepBack : false); + this.restartFrameSupportedContextKey.set(session ? !!session.capabilities.supportsRestartFrame : false); + this.stepIntoTargetsSupported.set(session ? !!session.capabilities.supportsStepInTargetsRequest : false); + this.jumpToCursorSupported.set(session ? !!session.capabilities.supportsGotoTargetsRequest : false); + this.setVariableSupported.set(session ? !!session.capabilities.supportsSetVariable : false); + this.setExpressionSupported.set(session ? !!session.capabilities.supportsSetExpression : false); + this.terminateDebuggeeSupported.set(session ? !!session.capabilities.supportTerminateDebuggee : false); + this.suspendDebuggeeSupported.set(session ? !!session.capabilities.supportSuspendDebuggee : false); + this.disassembleRequestSupported.set(!!session?.capabilities.supportsDisassembleRequest); + this.focusedStackFrameHasInstructionPointerReference.set(!!stackFrame?.instructionPointerReference); + const attach = !!session && isSessionAttach(session); + this.focusedSessionIsAttach.set(attach); + }); if (shouldEmitForSession) { this._onDidFocusSession.fire(session); diff --git a/src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts b/src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts index 42ce8fd002ce7..27a701f84cb4c 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts @@ -473,7 +473,7 @@ export class ExtensionsViewPaneContainer extends ViewPaneContainer implements IE @IConfigurationService configurationService: IConfigurationService, @IStorageService storageService: IStorageService, @IWorkspaceContextService contextService: IWorkspaceContextService, - @IContextKeyService contextKeyService: IContextKeyService, + @IContextKeyService private readonly contextKeyService: IContextKeyService, @IContextMenuService contextMenuService: IContextMenuService, @IExtensionService extensionService: IExtensionService, @IViewDescriptorService viewDescriptorService: IViewDescriptorService, @@ -649,18 +649,20 @@ export class ExtensionsViewPaneContainer extends ViewPaneContainer implements IE private doSearch(refresh?: boolean): Promise { const value = this.normalizedQuery(); - const isRecommendedExtensionsQuery = ExtensionsListView.isRecommendedExtensionsQuery(value); - this.searchInstalledExtensionsContextKey.set(ExtensionsListView.isInstalledExtensionsQuery(value)); - this.searchOutdatedExtensionsContextKey.set(ExtensionsListView.isOutdatedExtensionsQuery(value)); - this.searchEnabledExtensionsContextKey.set(ExtensionsListView.isEnabledExtensionsQuery(value)); - this.searchDisabledExtensionsContextKey.set(ExtensionsListView.isDisabledExtensionsQuery(value)); - this.searchBuiltInExtensionsContextKey.set(ExtensionsListView.isSearchBuiltInExtensionsQuery(value)); - this.searchWorkspaceUnsupportedExtensionsContextKey.set(ExtensionsListView.isSearchWorkspaceUnsupportedExtensionsQuery(value)); - this.searchDeprecatedExtensionsContextKey.set(ExtensionsListView.isSearchDeprecatedExtensionsQuery(value)); - this.builtInExtensionsContextKey.set(ExtensionsListView.isBuiltInExtensionsQuery(value)); - this.recommendedExtensionsContextKey.set(isRecommendedExtensionsQuery); - this.searchMarketplaceExtensionsContextKey.set(!!value && !ExtensionsListView.isLocalExtensionsQuery(value) && !isRecommendedExtensionsQuery); - this.defaultViewsContextKey.set(!value); + this.contextKeyService.bufferChangeEvents(() => { + const isRecommendedExtensionsQuery = ExtensionsListView.isRecommendedExtensionsQuery(value); + this.searchInstalledExtensionsContextKey.set(ExtensionsListView.isInstalledExtensionsQuery(value)); + this.searchOutdatedExtensionsContextKey.set(ExtensionsListView.isOutdatedExtensionsQuery(value)); + this.searchEnabledExtensionsContextKey.set(ExtensionsListView.isEnabledExtensionsQuery(value)); + this.searchDisabledExtensionsContextKey.set(ExtensionsListView.isDisabledExtensionsQuery(value)); + this.searchBuiltInExtensionsContextKey.set(ExtensionsListView.isSearchBuiltInExtensionsQuery(value)); + this.searchWorkspaceUnsupportedExtensionsContextKey.set(ExtensionsListView.isSearchWorkspaceUnsupportedExtensionsQuery(value)); + this.searchDeprecatedExtensionsContextKey.set(ExtensionsListView.isSearchDeprecatedExtensionsQuery(value)); + this.builtInExtensionsContextKey.set(ExtensionsListView.isBuiltInExtensionsQuery(value)); + this.recommendedExtensionsContextKey.set(isRecommendedExtensionsQuery); + this.searchMarketplaceExtensionsContextKey.set(!!value && !ExtensionsListView.isLocalExtensionsQuery(value) && !isRecommendedExtensionsQuery); + this.defaultViewsContextKey.set(!value); + }); return this.progress(Promise.all(this.panes.map(view => (view).show(this.normalizedQuery(), refresh) diff --git a/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellContextKeys.ts b/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellContextKeys.ts index c2bbfcf353367..364939e345601 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellContextKeys.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellContextKeys.ts @@ -58,22 +58,24 @@ export class CellContextKeyManager extends Disposable { ) { super(); - this.cellType = NOTEBOOK_CELL_TYPE.bindTo(this._contextKeyService); - this.cellEditable = NOTEBOOK_CELL_EDITABLE.bindTo(this._contextKeyService); - this.cellFocused = NOTEBOOK_CELL_FOCUSED.bindTo(this._contextKeyService); - this.cellEditorFocused = NOTEBOOK_CELL_EDITOR_FOCUSED.bindTo(this._contextKeyService); - this.markdownEditMode = NOTEBOOK_CELL_MARKDOWN_EDIT_MODE.bindTo(this._contextKeyService); - this.cellRunState = NOTEBOOK_CELL_EXECUTION_STATE.bindTo(this._contextKeyService); - this.cellExecuting = NOTEBOOK_CELL_EXECUTING.bindTo(this._contextKeyService); - this.cellHasOutputs = NOTEBOOK_CELL_HAS_OUTPUTS.bindTo(this._contextKeyService); - this.cellContentCollapsed = NOTEBOOK_CELL_INPUT_COLLAPSED.bindTo(this._contextKeyService); - this.cellOutputCollapsed = NOTEBOOK_CELL_OUTPUT_COLLAPSED.bindTo(this._contextKeyService); - this.cellLineNumbers = NOTEBOOK_CELL_LINE_NUMBERS.bindTo(this._contextKeyService); - this.cellResource = NOTEBOOK_CELL_RESOURCE.bindTo(this._contextKeyService); - - if (element) { - this.updateForElement(element); - } + this._contextKeyService.bufferChangeEvents(() => { + this.cellType = NOTEBOOK_CELL_TYPE.bindTo(this._contextKeyService); + this.cellEditable = NOTEBOOK_CELL_EDITABLE.bindTo(this._contextKeyService); + this.cellFocused = NOTEBOOK_CELL_FOCUSED.bindTo(this._contextKeyService); + this.cellEditorFocused = NOTEBOOK_CELL_EDITOR_FOCUSED.bindTo(this._contextKeyService); + this.markdownEditMode = NOTEBOOK_CELL_MARKDOWN_EDIT_MODE.bindTo(this._contextKeyService); + this.cellRunState = NOTEBOOK_CELL_EXECUTION_STATE.bindTo(this._contextKeyService); + this.cellExecuting = NOTEBOOK_CELL_EXECUTING.bindTo(this._contextKeyService); + this.cellHasOutputs = NOTEBOOK_CELL_HAS_OUTPUTS.bindTo(this._contextKeyService); + this.cellContentCollapsed = NOTEBOOK_CELL_INPUT_COLLAPSED.bindTo(this._contextKeyService); + this.cellOutputCollapsed = NOTEBOOK_CELL_OUTPUT_COLLAPSED.bindTo(this._contextKeyService); + this.cellLineNumbers = NOTEBOOK_CELL_LINE_NUMBERS.bindTo(this._contextKeyService); + this.cellResource = NOTEBOOK_CELL_RESOURCE.bindTo(this._contextKeyService); + + if (element) { + this.updateForElement(element); + } + }); this._register(this._notebookExecutionStateService.onDidChangeCellExecution(e => { if (this.element && e.affectsCell(this.element.uri)) { @@ -104,36 +106,40 @@ export class CellContextKeyManager extends Disposable { this.cellType.set('code'); } - this.updateForFocusState(); - this.updateForExecutionState(); - this.updateForEditState(); - this.updateForCollapseState(); - this.updateForOutputs(); + this._contextKeyService.bufferChangeEvents(() => { + this.updateForFocusState(); + this.updateForExecutionState(); + this.updateForEditState(); + this.updateForCollapseState(); + this.updateForOutputs(); - this.cellLineNumbers.set(this.element!.lineNumbers); - this.cellResource.set(this.element!.uri.toString()); + this.cellLineNumbers.set(this.element!.lineNumbers); + this.cellResource.set(this.element!.uri.toString()); + }); } private onDidChangeState(e: CellViewModelStateChangeEvent) { - if (e.internalMetadataChanged) { - this.updateForExecutionState(); - } + this._contextKeyService.bufferChangeEvents(() => { + if (e.internalMetadataChanged) { + this.updateForExecutionState(); + } - if (e.editStateChanged) { - this.updateForEditState(); - } + if (e.editStateChanged) { + this.updateForEditState(); + } - if (e.focusModeChanged) { - this.updateForFocusState(); - } + if (e.focusModeChanged) { + this.updateForFocusState(); + } - if (e.cellLineNumberChanged) { - this.cellLineNumbers.set(this.element!.lineNumbers); - } + if (e.cellLineNumberChanged) { + this.cellLineNumbers.set(this.element!.lineNumbers); + } - if (e.inputCollapsedChanged || e.outputCollapsedChanged) { - this.updateForCollapseState(); - } + if (e.inputCollapsedChanged || e.outputCollapsedChanged) { + this.updateForCollapseState(); + } + }); } private updateForFocusState() { diff --git a/src/vs/workbench/contrib/outline/browser/outlinePane.ts b/src/vs/workbench/contrib/outline/browser/outlinePane.ts index ab6017b2c9363..d41777b2c546c 100644 --- a/src/vs/workbench/contrib/outline/browser/outlinePane.ts +++ b/src/vs/workbench/contrib/outline/browser/outlinePane.ts @@ -103,9 +103,11 @@ export class OutlinePane extends ViewPane { this._outlineViewState.restore(this._storageService); this._disposables.add(this._outlineViewState); - this._ctxFollowsCursor = _ctxFollowsCursor.bindTo(contextKeyService); - this._ctxFilterOnType = _ctxFilterOnType.bindTo(contextKeyService); - this._ctxSortMode = _ctxSortMode.bindTo(contextKeyService); + contextKeyService.bufferChangeEvents(() => { + this._ctxFollowsCursor = _ctxFollowsCursor.bindTo(contextKeyService); + this._ctxFilterOnType = _ctxFilterOnType.bindTo(contextKeyService); + this._ctxSortMode = _ctxSortMode.bindTo(contextKeyService); + }); const updateContext = () => { this._ctxFollowsCursor.set(this._outlineViewState.followCursor); diff --git a/src/vs/workbench/services/history/browser/historyService.ts b/src/vs/workbench/services/history/browser/historyService.ts index 2345385ecb0e4..1a907aec65f45 100644 --- a/src/vs/workbench/services/history/browser/historyService.ts +++ b/src/vs/workbench/services/history/browser/historyService.ts @@ -263,20 +263,22 @@ export class HistoryService extends Disposable implements IHistoryService { private readonly canReopenClosedEditorContextKey = (new RawContextKey('canReopenClosedEditor', false, localize('canReopenClosedEditor', "Whether it is possible to reopen the last closed editor"))).bindTo(this.contextKeyService); updateContextKeys(): void { - const activeStack = this.getStack(); + this.contextKeyService.bufferChangeEvents(() => { + const activeStack = this.getStack(); - this.canNavigateBackContextKey.set(activeStack.canGoBack(GoFilter.NONE)); - this.canNavigateForwardContextKey.set(activeStack.canGoForward(GoFilter.NONE)); + this.canNavigateBackContextKey.set(activeStack.canGoBack(GoFilter.NONE)); + this.canNavigateForwardContextKey.set(activeStack.canGoForward(GoFilter.NONE)); - this.canNavigateBackInNavigationsContextKey.set(activeStack.canGoBack(GoFilter.NAVIGATION)); - this.canNavigateForwardInNavigationsContextKey.set(activeStack.canGoForward(GoFilter.NAVIGATION)); - this.canNavigateToLastNavigationLocationContextKey.set(activeStack.canGoLast(GoFilter.NAVIGATION)); + this.canNavigateBackInNavigationsContextKey.set(activeStack.canGoBack(GoFilter.NAVIGATION)); + this.canNavigateForwardInNavigationsContextKey.set(activeStack.canGoForward(GoFilter.NAVIGATION)); + this.canNavigateToLastNavigationLocationContextKey.set(activeStack.canGoLast(GoFilter.NAVIGATION)); - this.canNavigateBackInEditsContextKey.set(activeStack.canGoBack(GoFilter.EDITS)); - this.canNavigateForwardInEditsContextKey.set(activeStack.canGoForward(GoFilter.EDITS)); - this.canNavigateToLastEditLocationContextKey.set(activeStack.canGoLast(GoFilter.EDITS)); + this.canNavigateBackInEditsContextKey.set(activeStack.canGoBack(GoFilter.EDITS)); + this.canNavigateForwardInEditsContextKey.set(activeStack.canGoForward(GoFilter.EDITS)); + this.canNavigateToLastEditLocationContextKey.set(activeStack.canGoLast(GoFilter.EDITS)); - this.canReopenClosedEditorContextKey.set(this.recentlyClosedEditors.length > 0); + this.canReopenClosedEditorContextKey.set(this.recentlyClosedEditors.length > 0); + }); } //#endregion diff --git a/src/vs/workbench/services/views/browser/viewDescriptorService.ts b/src/vs/workbench/services/views/browser/viewDescriptorService.ts index 8234914e1424a..de843eacab866 100644 --- a/src/vs/workbench/services/views/browser/viewDescriptorService.ts +++ b/src/vs/workbench/services/views/browser/viewDescriptorService.ts @@ -213,16 +213,18 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor } private onDidRegisterViews(views: { views: IViewDescriptor[]; viewContainer: ViewContainer }[]): void { - views.forEach(({ views, viewContainer }) => { - // When views are registered, we need to regroup them based on the customizations - const regroupedViews = this.regroupViews(viewContainer.id, views); - - // Once they are grouped, try registering them which occurs - // if the container has already been registered within this service - // or we can generate the container from the source view id - this.registerGroupedViews(regroupedViews); - - views.forEach(viewDescriptor => this.getOrCreateMovableViewContextKey(viewDescriptor).set(!!viewDescriptor.canMoveView)); + this.contextKeyService.bufferChangeEvents(() => { + views.forEach(({ views, viewContainer }) => { + // When views are registered, we need to regroup them based on the customizations + const regroupedViews = this.regroupViews(viewContainer.id, views); + + // Once they are grouped, try registering them which occurs + // if the container has already been registered within this service + // or we can generate the container from the source view id + this.registerGroupedViews(regroupedViews); + + views.forEach(viewDescriptor => this.getOrCreateMovableViewContextKey(viewDescriptor).set(!!viewDescriptor.canMoveView)); + }); }); } @@ -234,7 +236,9 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor // When views are registered, we need to regroup them based on the customizations const regroupedViews = this.regroupViews(viewContainer.id, views); this.deregisterGroupedViews(regroupedViews); - views.forEach(viewDescriptor => this.getOrCreateMovableViewContextKey(viewDescriptor).set(false)); + this.contextKeyService.bufferChangeEvents(() => { + views.forEach(viewDescriptor => this.getOrCreateMovableViewContextKey(viewDescriptor).set(false)); + }); } private regroupViews(containerId: string, views: IViewDescriptor[]): Map { @@ -702,7 +706,9 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor const viewsToRegister = this.getViewsByContainer(viewContainer).filter(view => this.getDefaultContainerById(view.id) !== viewContainer); if (viewsToRegister.length) { this.addViews(viewContainer, viewsToRegister); - viewsToRegister.forEach(viewDescriptor => this.getOrCreateMovableViewContextKey(viewDescriptor).set(!!viewDescriptor.canMoveView)); + this.contextKeyService.bufferChangeEvents(() => { + viewsToRegister.forEach(viewDescriptor => this.getOrCreateMovableViewContextKey(viewDescriptor).set(!!viewDescriptor.canMoveView)); + }); } } @@ -718,13 +724,17 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor } private onDidChangeActiveViews({ added, removed }: { added: ReadonlyArray; removed: ReadonlyArray }): void { - added.forEach(viewDescriptor => this.getOrCreateActiveViewContextKey(viewDescriptor).set(true)); - removed.forEach(viewDescriptor => this.getOrCreateActiveViewContextKey(viewDescriptor).set(false)); + this.contextKeyService.bufferChangeEvents(() => { + added.forEach(viewDescriptor => this.getOrCreateActiveViewContextKey(viewDescriptor).set(true)); + removed.forEach(viewDescriptor => this.getOrCreateActiveViewContextKey(viewDescriptor).set(false)); + }); } private onDidChangeVisibleViews({ added, removed }: { added: IViewDescriptor[]; removed: IViewDescriptor[] }): void { - added.forEach(viewDescriptor => this.getOrCreateVisibleViewContextKey(viewDescriptor).set(true)); - removed.forEach(viewDescriptor => this.getOrCreateVisibleViewContextKey(viewDescriptor).set(false)); + this.contextKeyService.bufferChangeEvents(() => { + added.forEach(viewDescriptor => this.getOrCreateVisibleViewContextKey(viewDescriptor).set(true)); + removed.forEach(viewDescriptor => this.getOrCreateVisibleViewContextKey(viewDescriptor).set(false)); + }); } private registerViewsVisibilityActions(viewContainerModel: ViewContainerModel): void { @@ -827,14 +837,16 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor } private addViews(container: ViewContainer, views: IViewDescriptor[], visibilityState: ViewVisibilityState = ViewVisibilityState.Default): void { - views.forEach(view => { - const isDefaultContainer = this.getDefaultContainerById(view.id) === container; - this.getOrCreateDefaultViewLocationContextKey(view).set(isDefaultContainer); - if (isDefaultContainer) { - this.viewDescriptorsCustomLocations.delete(view.id); - } else { - this.viewDescriptorsCustomLocations.set(view.id, container.id); - } + this.contextKeyService.bufferChangeEvents(() => { + views.forEach(view => { + const isDefaultContainer = this.getDefaultContainerById(view.id) === container; + this.getOrCreateDefaultViewLocationContextKey(view).set(isDefaultContainer); + if (isDefaultContainer) { + this.viewDescriptorsCustomLocations.delete(view.id); + } else { + this.viewDescriptorsCustomLocations.set(view.id, container.id); + } + }); }); this.getViewContainerModel(container).add(views.map(view => { @@ -848,11 +860,13 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor private removeViews(container: ViewContainer, views: IViewDescriptor[]): void { // Set view default location keys to false - views.forEach(view => { - if (this.viewDescriptorsCustomLocations.get(view.id) === container.id) { - this.viewDescriptorsCustomLocations.delete(view.id); - } - this.getOrCreateDefaultViewLocationContextKey(view).set(false); + this.contextKeyService.bufferChangeEvents(() => { + views.forEach(view => { + if (this.viewDescriptorsCustomLocations.get(view.id) === container.id) { + this.viewDescriptorsCustomLocations.delete(view.id); + } + this.getOrCreateDefaultViewLocationContextKey(view).set(false); + }); }); // Remove the views