diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index 0fe3a86e44583..c86b7050e91c6 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -11,7 +11,7 @@ import { LinkedList } from 'vs/base/common/linkedList'; import { ICommandAction, ICommandActionTitle, Icon, ILocalizedString } from 'vs/platform/action/common/action'; import { Categories } from 'vs/platform/action/common/actionCommonCategories'; import { CommandsRegistry, ICommandHandlerDescription, ICommandService } from 'vs/platform/commands/common/commands'; -import { ContextKeyExpr, ContextKeyExpression, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { ContextKeyExpr, ContextKeyExpression, IContextKeyService, IOverlayContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { createDecorator, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IKeybindingRule, KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; @@ -238,7 +238,7 @@ export interface IMenuService { * submenu entries. That is more expensive and must be explicitly enabled with the * `emitEventsForSubmenuChanges` flag. */ - createMenu(id: MenuId, contextKeyService: IContextKeyService, options?: IMenuCreateOptions): IMenu; + createMenu(id: MenuId, contextKeyService: IContextKeyService | IOverlayContextKeyService, options?: IMenuCreateOptions): IMenu; /** * Reset **all** menu item hidden states. diff --git a/src/vs/platform/contextkey/browser/contextKeyService.ts b/src/vs/platform/contextkey/browser/contextKeyService.ts index 17cd0275224d5..158b92151ef6b 100644 --- a/src/vs/platform/contextkey/browser/contextKeyService.ts +++ b/src/vs/platform/contextkey/browser/contextKeyService.ts @@ -14,7 +14,7 @@ import { URI } from 'vs/base/common/uri'; import { localize } from 'vs/nls'; import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration'; -import { ContextKeyExpression, ContextKeyInfo, ContextKeyValue, IContext, IContextKey, IContextKeyChangeEvent, IContextKeyService, IContextKeyServiceTarget, IReadableSet, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; +import { ContextKeyExpression, ContextKeyInfo, ContextKeyValue, IContext, IContextKey, IContextKeyChangeEvent, IContextKeyService, IContextKeyServiceTarget, IOverlayContextKeyService, IReadableSet, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; const KEYBINDING_CONTEXT_ATTR = 'data-keybinding-context'; @@ -308,7 +308,7 @@ export abstract class AbstractContextKeyService implements IContextKeyService { return new ScopedContextKeyService(this, domNode); } - createOverlay(overlay: Iterable<[string, any]> = Iterable.empty()): IContextKeyService { + createOverlay(overlay: Iterable<[string, any]> = Iterable.empty()): IOverlayContextKeyService { if (this._isDisposed) { throw new Error(`AbstractContextKeyService has been disposed`); } @@ -527,7 +527,7 @@ class OverlayContext implements IContext { } } -class OverlayContextKeyService implements IContextKeyService { +class OverlayContextKeyService implements IOverlayContextKeyService { declare _serviceBrand: undefined; private overlay: Map; @@ -575,17 +575,13 @@ class OverlayContextKeyService implements IContextKeyService { throw new Error('Not supported.'); } - createOverlay(overlay: Iterable<[string, any]> = Iterable.empty()): IContextKeyService { + createOverlay(overlay: Iterable<[string, any]> = Iterable.empty()): IOverlayContextKeyService { return new OverlayContextKeyService(this, overlay); } updateParent(): void { throw new Error('Not supported.'); } - - dispose(): void { - // noop - } } function findContextAttr(domNode: IContextKeyServiceTarget | null): number { diff --git a/src/vs/platform/contextkey/common/contextkey.ts b/src/vs/platform/contextkey/common/contextkey.ts index b59849d296bb9..b1f2b219097df 100644 --- a/src/vs/platform/contextkey/common/contextkey.ts +++ b/src/vs/platform/contextkey/common/contextkey.ts @@ -2031,6 +2031,8 @@ export interface IContextKeyChangeEvent { allKeysContainedIn(keys: IReadableSet): boolean; } +export type IOverlayContextKeyService = Omit; + export interface IContextKeyService { readonly _serviceBrand: undefined; dispose(): void; @@ -2043,7 +2045,7 @@ export interface IContextKeyService { getContextKeyValue(key: string): T | undefined; createScoped(target: IContextKeyServiceTarget): IContextKeyService; - createOverlay(overlay: Iterable<[string, any]>): IContextKeyService; + createOverlay(overlay: Iterable<[string, any]>): IOverlayContextKeyService; getContext(target: IContextKeyServiceTarget | null): IContext; updateParent(parentContextKeyService: IContextKeyService): void; diff --git a/src/vs/platform/contextview/browser/contextView.ts b/src/vs/platform/contextview/browser/contextView.ts index 505d76eabfbdd..7edebda03c7a0 100644 --- a/src/vs/platform/contextview/browser/contextView.ts +++ b/src/vs/platform/contextview/browser/contextView.ts @@ -9,7 +9,7 @@ import { IAction } from 'vs/base/common/actions'; import { Event } from 'vs/base/common/event'; import { IDisposable } from 'vs/base/common/lifecycle'; import { IMenuActionOptions, MenuId } from 'vs/platform/actions/common/actions'; -import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { IContextKeyService, IOverlayContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; export const IContextViewService = createDecorator('contextViewService'); @@ -62,7 +62,7 @@ export type IContextMenuMenuDelegate = { /** * Optional context key service which drives the given menu */ - contextKeyService?: IContextKeyService; + contextKeyService?: IContextKeyService | IOverlayContextKeyService; /** * Optional getter for extra actions. They will be prepended to the menu actions. diff --git a/src/vs/workbench/contrib/debug/browser/variablesView.ts b/src/vs/workbench/contrib/debug/browser/variablesView.ts index 9c29731dc1c63..528e5b51fe823 100644 --- a/src/vs/workbench/contrib/debug/browser/variablesView.ts +++ b/src/vs/workbench/contrib/debug/browser/variablesView.ts @@ -214,7 +214,7 @@ export class VariablesView extends ViewPane { const toDispose = new DisposableStore(); try { - const contextKeyService = toDispose.add(await getContextForVariableMenuWithDataAccess(this.contextKeyService, variable)); + const contextKeyService = await getContextForVariableMenuWithDataAccess(this.contextKeyService, variable); const menu = toDispose.add(this.menuService.createMenu(MenuId.DebugVariablesContext, contextKeyService)); const context: IVariablesContext = getVariablesContext(variable); diff --git a/src/vs/workbench/contrib/remote/browser/tunnelView.ts b/src/vs/workbench/contrib/remote/browser/tunnelView.ts index 7b67a9ccd6609..a548d74c14a63 100644 --- a/src/vs/workbench/contrib/remote/browser/tunnelView.ts +++ b/src/vs/workbench/contrib/remote/browser/tunnelView.ts @@ -790,7 +790,7 @@ export class TunnelPanel extends ViewPane { this.tunnelViewMultiSelectionContext = TunnelViewMultiSelectionContextKey.bindTo(contextKeyService); this.portChangableContextKey = PortChangableContextKey.bindTo(contextKeyService); - const overlayContextKeyService = this._register(this.contextKeyService.createOverlay([['view', TunnelPanel.ID]])); + const overlayContextKeyService = this.contextKeyService.createOverlay([['view', TunnelPanel.ID]]); const titleMenu = this._register(this.menuService.createMenu(MenuId.TunnelTitle, overlayContextKeyService)); const updateActions = () => { this.titleActions = []; diff --git a/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts b/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts index 1d524bbe645c3..e409b109a3874 100644 --- a/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts +++ b/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts @@ -22,7 +22,7 @@ import { editorErrorForeground, registerColor, transparent } from 'vs/platform/t import { ICodeEditor, IEditorMouseEvent, isCodeEditor, MouseTargetType } from 'vs/editor/browser/editorBrowser'; import { registerEditorAction, registerEditorContribution, ServicesAccessor, EditorAction, EditorContributionInstantiation } from 'vs/editor/browser/editorExtensions'; import { PeekViewWidget, getOuterEditor, peekViewBorder, peekViewTitleBackground, peekViewTitleForeground, peekViewTitleInfoForeground } from 'vs/editor/contrib/peekView/browser/peekView'; -import { IContextKeyService, IContextKey, ContextKeyExpr, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; +import { IContextKeyService, IContextKey, ContextKeyExpr, RawContextKey, IOverlayContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import { Position } from 'vs/editor/common/core/position'; @@ -201,11 +201,12 @@ class DirtyDiffWidget extends PeekViewWidget { this._disposables.add(themeService.onDidColorThemeChange(this._applyTheme, this)); this._applyTheme(themeService.getColorTheme()); + let overlayContextKeyService: IOverlayContextKeyService | IContextKeyService = contextKeyService; if (this.model.original.length > 0) { - contextKeyService = contextKeyService.createOverlay([['originalResourceScheme', this.model.original[0].uri.scheme], ['originalResourceSchemes', this.model.original.map(original => original.uri.scheme)]]); + overlayContextKeyService = contextKeyService.createOverlay([['originalResourceScheme', this.model.original[0].uri.scheme], ['originalResourceSchemes', this.model.original.map(original => original.uri.scheme)]]); } - this.menu = menuService.createMenu(MenuId.SCMChangeContext, contextKeyService); + this.menu = menuService.createMenu(MenuId.SCMChangeContext, overlayContextKeyService); this._disposables.add(this.menu); this.create(); diff --git a/src/vs/workbench/contrib/scm/browser/menus.ts b/src/vs/workbench/contrib/scm/browser/menus.ts index 3f3648102d090..9e17c3e8f225c 100644 --- a/src/vs/workbench/contrib/scm/browser/menus.ts +++ b/src/vs/workbench/contrib/scm/browser/menus.ts @@ -6,7 +6,7 @@ import 'vs/css!./media/scm'; import { Emitter } from 'vs/base/common/event'; import { IDisposable, DisposableStore, dispose } from 'vs/base/common/lifecycle'; -import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { IContextKeyService, IOverlayContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions'; import { IAction } from 'vs/base/common/actions'; import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem'; @@ -94,7 +94,7 @@ class SCMMenusItem implements IDisposable { private contextualResourceMenus: Map | undefined; constructor( - private contextKeyService: IContextKeyService, + private contextKeyService: IOverlayContextKeyService, private menuService: IMenuService ) { } @@ -144,7 +144,7 @@ class SCMMenusItem implements IDisposable { export class SCMRepositoryMenus implements ISCMRepositoryMenus, IDisposable { - private contextKeyService: IContextKeyService; + private _overlayContextKeyService: IOverlayContextKeyService; readonly titleMenu: SCMTitleMenu; private readonly resourceGroups: ISCMResourceGroup[] = []; @@ -153,7 +153,7 @@ export class SCMRepositoryMenus implements ISCMRepositoryMenus, IDisposable { private _repositoryMenu: IMenu | undefined; get repositoryMenu(): IMenu { if (!this._repositoryMenu) { - this._repositoryMenu = this.menuService.createMenu(MenuId.SCMSourceControl, this.contextKeyService); + this._repositoryMenu = this.menuService.createMenu(MenuId.SCMSourceControl, this._overlayContextKeyService); this.disposables.add(this._repositoryMenu); } @@ -168,13 +168,13 @@ export class SCMRepositoryMenus implements ISCMRepositoryMenus, IDisposable { @IInstantiationService instantiationService: IInstantiationService, @IMenuService private readonly menuService: IMenuService ) { - this.contextKeyService = contextKeyService.createOverlay([ + this._overlayContextKeyService = contextKeyService.createOverlay([ ['scmProvider', provider.contextValue], ['scmProviderRootUri', provider.rootUri?.toString()], ['scmProviderHasRootUri', !!provider.rootUri], ]); - const serviceCollection = new ServiceCollection([IContextKeyService, this.contextKeyService]); + const serviceCollection = new ServiceCollection([IContextKeyService, this._overlayContextKeyService]); instantiationService = instantiationService.createChild(serviceCollection); this.titleMenu = instantiationService.createInstance(SCMTitleMenu); @@ -198,7 +198,7 @@ export class SCMRepositoryMenus implements ISCMRepositoryMenus, IDisposable { let result = this.resourceGroupMenusItems.get(group); if (!result) { - const contextKeyService = this.contextKeyService.createOverlay([ + const contextKeyService = this._overlayContextKeyService.createOverlay([ ['scmResourceGroup', group.id], ]);