未验证 提交 82d255a3 编写于 作者: J João Moreno

Merge branch 'joao/overlay-cks'

......@@ -222,7 +222,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
private readonly _updateDecorationsRunner: RunOnceScheduler;
private readonly _editorWorkerService: IEditorWorkerService;
protected _contextKeyService: IContextKeyService;
private readonly _contextKeyService: IContextKeyService;
private readonly _instantiationService: IInstantiationService;
private readonly _codeEditorService: ICodeEditorService;
private readonly _themeService: IThemeService;
private readonly _notificationService: INotificationService;
......@@ -248,6 +249,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
this._editorWorkerService = editorWorkerService;
this._codeEditorService = codeEditorService;
this._contextKeyService = this._register(contextKeyService.createScoped(domElement));
this._instantiationService = instantiationService.createChild(new ServiceCollection([IContextKeyService, this._contextKeyService]));
this._contextKeyService.createKey('isInDiffEditor', true);
this._themeService = themeService;
this._notificationService = notificationService;
......@@ -354,20 +356,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
this._diffComputationResult = null;
const leftContextKeyService = this._contextKeyService.createScoped();
const leftServices = new ServiceCollection();
leftServices.set(IContextKeyService, leftContextKeyService);
const leftScopedInstantiationService = instantiationService.createChild(leftServices);
const rightContextKeyService = this._contextKeyService.createScoped();
const rightServices = new ServiceCollection();
rightServices.set(IContextKeyService, rightContextKeyService);
const rightScopedInstantiationService = instantiationService.createChild(rightServices);
this._originalEditor = this._createLeftHandSideEditor(options, codeEditorWidgetOptions.originalEditor || {}, leftScopedInstantiationService, leftContextKeyService);
this._modifiedEditor = this._createRightHandSideEditor(options, codeEditorWidgetOptions.modifiedEditor || {}, rightScopedInstantiationService, rightContextKeyService);
this._originalEditor = this._createLeftHandSideEditor(options, codeEditorWidgetOptions.originalEditor || {});
this._modifiedEditor = this._createRightHandSideEditor(options, codeEditorWidgetOptions.modifiedEditor || {});
this._originalOverviewRuler = null;
this._modifiedOverviewRuler = null;
......@@ -495,8 +485,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
this._layoutOverviewRulers();
}
private _createLeftHandSideEditor(options: Readonly<editorBrowser.IDiffEditorConstructionOptions>, codeEditorWidgetOptions: ICodeEditorWidgetOptions, instantiationService: IInstantiationService, contextKeyService: IContextKeyService): CodeEditorWidget {
const editor = this._createInnerEditor(instantiationService, this._originalDomNode, this._adjustOptionsForLeftHandSide(options), codeEditorWidgetOptions);
private _createLeftHandSideEditor(options: Readonly<editorBrowser.IDiffEditorConstructionOptions>, codeEditorWidgetOptions: ICodeEditorWidgetOptions): CodeEditorWidget {
const editor = this._createInnerEditor(this._instantiationService, this._originalDomNode, this._adjustOptionsForLeftHandSide(options), codeEditorWidgetOptions);
this._register(editor.onDidScrollChange((e) => {
if (this._isHandlingScrollEvent) {
......@@ -538,7 +528,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
}
}));
const isInDiffLeftEditorKey = contextKeyService.createKey<boolean>('isInDiffLeftEditor', undefined);
const isInDiffLeftEditorKey = this._contextKeyService.createKey<boolean>('isInDiffLeftEditor', editor.hasWidgetFocus());
this._register(editor.onDidFocusEditorWidget(() => isInDiffLeftEditorKey.set(true)));
this._register(editor.onDidBlurEditorWidget(() => isInDiffLeftEditorKey.set(false)));
......@@ -557,8 +547,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
return editor;
}
private _createRightHandSideEditor(options: Readonly<editorBrowser.IDiffEditorConstructionOptions>, codeEditorWidgetOptions: ICodeEditorWidgetOptions, instantiationService: IInstantiationService, contextKeyService: IContextKeyService): CodeEditorWidget {
const editor = this._createInnerEditor(instantiationService, this._modifiedDomNode, this._adjustOptionsForRightHandSide(options), codeEditorWidgetOptions);
private _createRightHandSideEditor(options: Readonly<editorBrowser.IDiffEditorConstructionOptions>, codeEditorWidgetOptions: ICodeEditorWidgetOptions): CodeEditorWidget {
const editor = this._createInnerEditor(this._instantiationService, this._modifiedDomNode, this._adjustOptionsForRightHandSide(options), codeEditorWidgetOptions);
this._register(editor.onDidScrollChange((e) => {
if (this._isHandlingScrollEvent) {
......@@ -606,7 +596,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
}
}));
const isInDiffRightEditorKey = contextKeyService.createKey<boolean>('isInDiffRightEditor', undefined);
const isInDiffRightEditorKey = this._contextKeyService.createKey<boolean>('isInDiffRightEditor', editor.hasWidgetFocus());
this._register(editor.onDidFocusEditorWidget(() => isInDiffRightEditorKey.set(true)));
this._register(editor.onDidBlurEditorWidget(() => isInDiffRightEditorKey.set(false)));
......
......@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Emitter, PauseableEmitter } from 'vs/base/common/event';
import { Emitter, Event, PauseableEmitter } from 'vs/base/common/event';
import { Iterable } from 'vs/base/common/iterator';
import { IDisposable, DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
import { TernarySearchTree } from 'vs/base/common/map';
......@@ -287,6 +287,13 @@ export abstract class AbstractContextKeyService implements IContextKeyService {
return new ScopedContextKeyService(this, domNode);
}
createOverlay(overlay: Iterable<[string, any]> = Iterable.empty()): IContextKeyService {
if (this._isDisposed) {
throw new Error(`AbstractContextKeyService has been disposed`);
}
return new OverlayContextKeyService(this, overlay);
}
public contextMatchesRules(rules: ContextKeyExpression | undefined): boolean {
if (this._isDisposed) {
throw new Error(`AbstractContextKeyService has been disposed`);
......@@ -405,27 +412,25 @@ export class ContextKeyService extends AbstractContextKeyService implements ICon
class ScopedContextKeyService extends AbstractContextKeyService {
private _parent: AbstractContextKeyService;
private _domNode: IContextKeyServiceTarget | undefined;
private _domNode: IContextKeyServiceTarget;
private readonly _parentChangeListener = new MutableDisposable();
constructor(parent: AbstractContextKeyService, domNode?: IContextKeyServiceTarget) {
constructor(parent: AbstractContextKeyService, domNode: IContextKeyServiceTarget) {
super(parent.createChildContext());
this._parent = parent;
this._updateParentChangeListener();
if (domNode) {
this._domNode = domNode;
if (this._domNode.hasAttribute(KEYBINDING_CONTEXT_ATTR)) {
let extraInfo = '';
if ((this._domNode as HTMLElement).classList) {
extraInfo = Array.from((this._domNode as HTMLElement).classList.values()).join(', ');
}
console.error(`Element already has context attribute${extraInfo ? ': ' + extraInfo : ''}`);
this._domNode = domNode;
if (this._domNode.hasAttribute(KEYBINDING_CONTEXT_ATTR)) {
let extraInfo = '';
if ((this._domNode as HTMLElement).classList) {
extraInfo = Array.from((this._domNode as HTMLElement).classList.values()).join(', ');
}
this._domNode.setAttribute(KEYBINDING_CONTEXT_ATTR, String(this._myContextId));
console.error(`Element already has context attribute${extraInfo ? ': ' + extraInfo : ''}`);
}
this._domNode.setAttribute(KEYBINDING_CONTEXT_ATTR, String(this._myContextId));
}
private _updateParentChangeListener(): void {
......@@ -434,14 +439,15 @@ class ScopedContextKeyService extends AbstractContextKeyService {
}
public dispose(): void {
if (this._isDisposed) {
return;
}
this._onDidChangeContext.dispose();
this._isDisposed = true;
this._parent.disposeContext(this._myContextId);
this._parentChangeListener?.dispose();
if (this._domNode) {
this._domNode.removeAttribute(KEYBINDING_CONTEXT_ATTR);
this._domNode = undefined;
}
this._parentChangeListener.dispose();
this._domNode.removeAttribute(KEYBINDING_CONTEXT_ATTR);
this._isDisposed = true;
}
public getContextValuesContainer(contextId: number): Context {
......@@ -484,6 +490,76 @@ class ScopedContextKeyService extends AbstractContextKeyService {
}
}
class OverlayContext implements IContext {
constructor(private parent: IContext, private overlay: ReadonlyMap<string, any>) { }
getValue<T>(key: string): T | undefined {
return this.overlay.has(key) ? this.overlay.get(key) : this.parent.getValue(key);
}
}
class OverlayContextKeyService implements IContextKeyService {
declare _serviceBrand: undefined;
private overlay: Map<string, any>;
get contextId(): number {
return this.parent.contextId;
}
get onDidChangeContext(): Event<IContextKeyChangeEvent> {
return this.parent.onDidChangeContext;
}
constructor(private parent: AbstractContextKeyService | OverlayContextKeyService, overlay: Iterable<[string, any]>) {
this.overlay = new Map(overlay);
}
bufferChangeEvents(callback: Function): void {
this.parent.bufferChangeEvents(callback);
}
createKey<T>(): IContextKey<T> {
throw new Error('Not supported.');
}
getContext(target: IContextKeyServiceTarget | null): IContext {
return new OverlayContext(this.parent.getContext(target), this.overlay);
}
getContextValuesContainer(contextId: number): IContext {
const parentContext = this.parent.getContextValuesContainer(contextId);
return new OverlayContext(parentContext, this.overlay);
}
contextMatchesRules(rules: ContextKeyExpression | undefined): boolean {
const context = this.getContextValuesContainer(this.contextId);
const result = KeybindingResolver.contextMatchesRules(context, rules);
return result;
}
getContextKeyValue<T>(key: string): T | undefined {
return this.overlay.has(key) ? this.overlay.get(key) : this.parent.getContextKeyValue(key);
}
createScoped(): IContextKeyService {
throw new Error('Not supported.');
}
createOverlay(overlay: Iterable<[string, any]> = Iterable.empty()): IContextKeyService {
return new OverlayContextKeyService(this, overlay);
}
updateParent(): void {
throw new Error('Not supported.');
}
dispose(): void {
// noop
}
}
function findContextAttr(domNode: IContextKeyServiceTarget | null): number {
while (domNode) {
if (domNode.hasAttribute(KEYBINDING_CONTEXT_ATTR)) {
......
......@@ -1273,7 +1273,7 @@ export class RawContextKey<T> extends ContextKeyDefinedExpr {
private readonly _defaultValue: T | undefined;
constructor(key: string, defaultValue: T | undefined, description?: string) {
constructor(readonly key: string, defaultValue: T | undefined, description?: string) {
super(key);
this._defaultValue = defaultValue;
......@@ -1341,7 +1341,8 @@ export interface IContextKeyService {
contextMatchesRules(rules: ContextKeyExpression | undefined): boolean;
getContextKeyValue<T>(key: string): T | undefined;
createScoped(target?: IContextKeyServiceTarget): IContextKeyService;
createScoped(target: IContextKeyServiceTarget): IContextKeyService;
createOverlay(overlay: Iterable<[string, any]>): IContextKeyService;
getContext(target: IContextKeyServiceTarget | null): IContext;
updateParent(parentContextKeyService: IContextKeyService): void;
......
......@@ -118,6 +118,7 @@ suite('AbstractKeybindingService', () => {
contextMatchesRules: undefined!,
getContextKeyValue: undefined!,
createScoped: undefined!,
createOverlay: undefined!,
getContext: (target: IContextKeyServiceTarget): any => {
return currentContextValue;
},
......
......@@ -66,6 +66,9 @@ export class MockContextKeyService implements IContextKeyService {
public createScoped(domNode: HTMLElement): IContextKeyService {
return this;
}
public createOverlay(): IContextKeyService {
return this;
}
updateParent(_parentContextKeyService: IContextKeyService): void {
// no-op
}
......
......@@ -1123,18 +1123,18 @@ class TreeMenus extends Disposable implements IDisposable {
if (!this.contextKeyService) {
return { primary: [], secondary: [] };
}
const contextKeyService = this.contextKeyService.createScoped();
contextKeyService.createKey('view', this.id);
contextKeyService.createKey(context.key, context.value);
const contextKeyService = this.contextKeyService.createOverlay([
['view', this.id],
[context.key, context.value]
]);
const menu = this.menuService.createMenu(menuId, contextKeyService);
const primary: IAction[] = [];
const secondary: IAction[] = [];
const result = { primary, secondary };
createAndFillInContextMenuActions(menu, { shouldForwardArgs: true }, result, g => /^inline/.test(g));
menu.dispose();
contextKeyService.dispose();
return result;
}
......
......@@ -80,16 +80,12 @@ class ViewWelcomeController {
return visibleItems.map(v => v.descriptor);
}
private contextKeyService: IContextKeyService;
private disposables = new DisposableStore();
constructor(
private id: string,
@IContextKeyService contextKeyService: IContextKeyService,
@IContextKeyService private contextKeyService: IContextKeyService,
) {
this.contextKeyService = contextKeyService.createScoped();
this.disposables.add(this.contextKeyService);
contextKeyService.onDidChangeContext(this.onDidChangeContext, this, this.disposables);
Event.filter(viewsRegistry.onDidChangeViewWelcomeContent, id => id === this.id)(this.onDidChangeViewWelcomeContent, this, this.disposables);
this.onDidChangeViewWelcomeContent();
......
......@@ -859,25 +859,27 @@ export class DropDownMenuActionViewItem extends ExtensionActionViewItem {
export function getContextMenuActions(extension: IExtension | undefined | null, inExtensionEditor: boolean, instantiationService: IInstantiationService): IAction[][] {
return instantiationService.invokeFunction(accessor => {
const scopedContextKeyService = accessor.get(IContextKeyService).createScoped();
const menuService = accessor.get(IMenuService);
const extensionRecommendationsService = accessor.get(IExtensionRecommendationsService);
const extensionIgnoredRecommendationsService = accessor.get(IExtensionIgnoredRecommendationsService);
const cksOverlay: [string, any][] = [];
if (extension) {
scopedContextKeyService.createKey<string>('extension', extension.identifier.id);
scopedContextKeyService.createKey<boolean>('isBuiltinExtension', extension.isBuiltin);
scopedContextKeyService.createKey<boolean>('extensionHasConfiguration', extension.local && !!extension.local.manifest.contributes && !!extension.local.manifest.contributes.configuration);
scopedContextKeyService.createKey<boolean>('isExtensionRecommended', !!extensionRecommendationsService.getAllRecommendationsWithReason()[extension.identifier.id.toLowerCase()]);
scopedContextKeyService.createKey<boolean>('isExtensionWorkspaceRecommended', extensionRecommendationsService.getAllRecommendationsWithReason()[extension.identifier.id.toLowerCase()]?.reasonId === ExtensionRecommendationReason.Workspace);
scopedContextKeyService.createKey<boolean>('isUserIgnoredRecommendation', extensionIgnoredRecommendationsService.globalIgnoredRecommendations.some(e => e === extension.identifier.id.toLowerCase()));
scopedContextKeyService.createKey<boolean>('inExtensionEditor', inExtensionEditor);
cksOverlay.push(['extension', extension.identifier.id]);
cksOverlay.push(['isBuiltinExtension', extension.isBuiltin]);
cksOverlay.push(['extensionHasConfiguration', extension.local && !!extension.local.manifest.contributes && !!extension.local.manifest.contributes.configuration]);
cksOverlay.push(['isExtensionRecommended', !!extensionRecommendationsService.getAllRecommendationsWithReason()[extension.identifier.id.toLowerCase()]]);
cksOverlay.push(['isExtensionWorkspaceRecommended', extensionRecommendationsService.getAllRecommendationsWithReason()[extension.identifier.id.toLowerCase()]?.reasonId === ExtensionRecommendationReason.Workspace]);
cksOverlay.push(['isUserIgnoredRecommendation', extensionIgnoredRecommendationsService.globalIgnoredRecommendations.some(e => e === extension.identifier.id.toLowerCase())]);
cksOverlay.push(['inExtensionEditor', inExtensionEditor]);
if (extension.state === ExtensionState.Installed) {
scopedContextKeyService.createKey<string>('extensionStatus', 'installed');
cksOverlay.push(['extensionStatus', 'installed']);
}
}
const contextKeyService = accessor.get(IContextKeyService).createOverlay(cksOverlay);
const groups: IAction[][] = [];
const menu = menuService.createMenu(MenuId.ExtensionContext, scopedContextKeyService);
const menu = menuService.createMenu(MenuId.ExtensionContext, contextKeyService);
menu.getActions({ shouldForwardArgs: true }).forEach(([, actions]) => groups.push(actions.map(action => {
if (action instanceof SubmenuAction) {
return action;
......@@ -885,7 +887,6 @@ export function getContextMenuActions(extension: IExtension | undefined | null,
return instantiationService.createInstance(MenuItemExtensionAction, action);
})));
menu.dispose();
scopedContextKeyService.dispose();
return groups;
});
......
......@@ -463,7 +463,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
this._body.classList.add('cell-list-container');
this._dndController = this._register(new CellDragAndDropController(this, this._body));
const getScopedContextKeyService = (container?: HTMLElement) => this._list.contextKeyService.createScoped(container);
const getScopedContextKeyService = (container: HTMLElement) => this._list.contextKeyService.createScoped(container);
const renderers = [
this.instantiationService.createInstance(CodeCellRenderer, this, this._renderedEditors, this._dndController, getScopedContextKeyService),
this.instantiationService.createInstance(MarkdownCellRenderer, this, this._dndController, this._renderedEditors, getScopedContextKeyService),
......
......@@ -178,7 +178,7 @@ abstract class AbstractCellRenderer {
configurationService: IConfigurationService,
private readonly keybindingService: IKeybindingService,
private readonly notificationService: INotificationService,
protected readonly contextKeyServiceProvider: (container?: HTMLElement) => IContextKeyService,
protected readonly contextKeyServiceProvider: (container: HTMLElement) => IContextKeyService,
language: string,
protected readonly dndController: CellDragAndDropController
) {
......@@ -375,7 +375,7 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
notebookEditor: INotebookEditor,
dndController: CellDragAndDropController,
private renderedEditors: Map<ICellViewModel, ICodeEditor | undefined>,
contextKeyServiceProvider: (container?: HTMLElement) => IContextKeyService,
contextKeyServiceProvider: (container: HTMLElement) => IContextKeyService,
@IInstantiationService instantiationService: IInstantiationService,
@IConfigurationService configurationService: IConfigurationService,
@IContextMenuService contextMenuService: IContextMenuService,
......@@ -683,7 +683,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
protected notebookEditor: INotebookEditor,
private renderedEditors: Map<ICellViewModel, ICodeEditor | undefined>,
dndController: CellDragAndDropController,
contextKeyServiceProvider: (container?: HTMLElement) => IContextKeyService,
contextKeyServiceProvider: (container: HTMLElement) => IContextKeyService,
@IContextMenuService contextMenuService: IContextMenuService,
@IConfigurationService configurationService: IConfigurationService,
@IInstantiationService instantiationService: IInstantiationService,
......
......@@ -308,9 +308,10 @@ export class StatefulMarkdownCell extends Disposable {
this.templateData.editorContainer.innerText = '';
// create a special context key service that set the inCompositeEditor-contextkey
const editorContextKeyService = this.contextKeyService.createScoped();
const editorContextKeyService = this.contextKeyService.createOverlay([
[EditorContextKeys.inCompositeEditor.key, true]
]);
const editorInstaService = this.instantiationService.createChild(new ServiceCollection([IContextKeyService, editorContextKeyService]));
EditorContextKeys.inCompositeEditor.bindTo(editorContextKeyService).set(true);
this.editor = editorInstaService.createInstance(CodeEditorWidget, this.templateData.editorContainer, {
...this.editorOptions,
......
......@@ -271,10 +271,11 @@ class TunnelTreeRenderer extends Disposable implements ITreeRenderer<ITunnelGrou
templateData.iconLabel.setLabel(label, description, { title: node instanceof TunnelItem ? node.tooltip : tooltip, extraClasses: ['tunnel-view-label'] });
templateData.actionBar.context = node;
const contextKeyService = this._register(this.contextKeyService.createScoped());
contextKeyService.createKey('view', this.viewId);
contextKeyService.createKey('tunnelType', node.tunnelType);
contextKeyService.createKey('tunnelCloseable', node.closeable);
const contextKeyService = this.contextKeyService.createOverlay([
['view', this.viewId],
['tunnelType', node.tunnelType],
['tunnelCloseable', node.closeable],
]);
const disposableStore = new DisposableStore();
templateData.elementDisposable = disposableStore;
const menu = disposableStore.add(this.menuService.createMenu(MenuId.TunnelInline, contextKeyService));
......@@ -295,7 +296,6 @@ class TunnelTreeRenderer extends Disposable implements ITreeRenderer<ITunnelGrou
}
menu.dispose();
contextKeyService.dispose();
}
private renderInputBox(container: HTMLElement, editableData: IEditableData): IDisposable {
......@@ -609,10 +609,8 @@ export class TunnelPanel extends ViewPane {
this.tunnelViewSelectionContext = TunnelViewSelectionContextKey.bindTo(contextKeyService);
this.portChangableContextKey = PortChangableContextKey.bindTo(contextKeyService);
const scopedContextKeyService = this._register(this.contextKeyService.createScoped());
scopedContextKeyService.createKey('view', TunnelPanel.ID);
const titleMenu = this._register(this.menuService.createMenu(MenuId.TunnelTitle, scopedContextKeyService));
const overlayContextKeyService = this._register(this.contextKeyService.createOverlay([['view', TunnelPanel.ID]]));
const titleMenu = this._register(this.menuService.createMenu(MenuId.TunnelTitle, overlayContextKeyService));
const updateActions = () => {
this.titleActions = [];
this.titleActionsDisposable.value = createAndFillInActionBarActions(titleMenu, undefined, this.titleActions);
......
......@@ -169,7 +169,6 @@ class DirtyDiffWidget extends PeekViewWidget {
private index: number = 0;
private change: IChange | undefined;
private height: number | undefined = undefined;
private contextKeyService: IContextKeyService;
constructor(
editor: ICodeEditor,
......@@ -177,16 +176,17 @@ class DirtyDiffWidget extends PeekViewWidget {
@IThemeService private readonly themeService: IThemeService,
@IInstantiationService instantiationService: IInstantiationService,
@IMenuService menuService: IMenuService,
@IContextKeyService contextKeyService: IContextKeyService
@IContextKeyService _contextKeyService: IContextKeyService
) {
super(editor, { isResizeable: true, frameWidth: 1, keepEditorSelection: true }, instantiationService);
this._disposables.add(themeService.onDidColorThemeChange(this._applyTheme, this));
this._applyTheme(themeService.getColorTheme());
this.contextKeyService = contextKeyService.createScoped();
this.contextKeyService.createKey('originalResourceScheme', this.model.original!.uri.scheme);
this.menu = menuService.createMenu(MenuId.SCMChangeContext, this.contextKeyService);
const contextKeyService = _contextKeyService.createOverlay([
['originalResourceScheme', this.model.original!.uri.scheme]
]);
this.menu = menuService.createMenu(MenuId.SCMChangeContext, contextKeyService);
this.create();
if (editor.hasModel()) {
......
......@@ -119,15 +119,12 @@ class SCMMenusItem implements IDisposable {
let item = this.contextualResourceMenus.get(resource.contextValue);
if (!item) {
const contextKeyService = this.contextKeyService.createScoped();
contextKeyService.createKey('scmResourceState', resource.contextValue);
const contextKeyService = this.contextKeyService.createOverlay([['scmResourceState', resource.contextValue]]);
const menu = this.menuService.createMenu(MenuId.SCMResourceContext, contextKeyService);
item = {
menu, dispose() {
menu.dispose();
contextKeyService.dispose();
}
};
......@@ -148,7 +145,6 @@ class SCMMenusItem implements IDisposable {
}
this.resourceFolderMenu?.dispose();
this.contextKeyService.dispose();
}
}
......@@ -178,10 +174,11 @@ export class SCMRepositoryMenus implements ISCMRepositoryMenus, IDisposable {
@IInstantiationService instantiationService: IInstantiationService,
@IMenuService private readonly menuService: IMenuService
) {
this.contextKeyService = contextKeyService.createScoped();
this.contextKeyService.createKey<string | undefined>('scmProvider', provider.contextValue);
this.contextKeyService.createKey<string | undefined>('scmProviderRootUri', provider.rootUri?.toString());
this.contextKeyService.createKey<boolean>('scmProviderHasRootUri', !!provider.rootUri);
this.contextKeyService = contextKeyService.createOverlay([
['scmProvider', provider.contextValue],
['scmProviderRootUri', provider.rootUri?.toString()],
['scmProviderHasRootUri', !!provider.rootUri],
]);
const serviceCollection = new ServiceCollection([IContextKeyService, this.contextKeyService]);
instantiationService = instantiationService.createChild(serviceCollection);
......@@ -207,9 +204,9 @@ export class SCMRepositoryMenus implements ISCMRepositoryMenus, IDisposable {
let result = this.resourceGroupMenusItems.get(group);
if (!result) {
const contextKeyService = this.contextKeyService.createScoped();
contextKeyService.createKey('scmProvider', group.provider.contextValue);
contextKeyService.createKey('scmResourceGroup', group.id);
const contextKeyService = this.contextKeyService.createOverlay([
['scmResourceGroup', group.id],
]);
result = new SCMMenusItem(contextKeyService, this.menuService);
this.resourceGroupMenusItems.set(group, result);
......
......@@ -1240,18 +1240,18 @@ class TimelinePaneCommands extends Disposable {
}
private getActions(menuId: MenuId, context: { key: string, value?: string }): { primary: IAction[]; secondary: IAction[]; } {
const scoped = this.contextKeyService.createScoped();
scoped.createKey('view', this.pane.id);
scoped.createKey(context.key, context.value);
const contextKeyService = this.contextKeyService.createOverlay([
['view', this.pane.id],
[context.key, context.value],
]);
const menu = this.menuService.createMenu(menuId, scoped);
const menu = this.menuService.createMenu(menuId, contextKeyService);
const primary: IAction[] = [];
const secondary: IAction[] = [];
const result = { primary, secondary };
createAndFillInContextMenuActions(menu, { shouldForwardArgs: true }, result, g => /^inline/.test(g));
menu.dispose();
scoped.dispose();
return result;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册