From 714fd96f61a8a02f26e9acdf93edb24d506ca4f7 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Tue, 9 Feb 2021 08:49:53 +0100 Subject: [PATCH] #114901 revert partially - do not scope view pane container context to its domnode - only use target while creating the menu actions --- .../workbench/browser/parts/views/viewPane.ts | 32 ++++++++++++++----- .../browser/parts/views/viewPaneContainer.ts | 27 +++++++++++++--- .../browser/parts/views/viewsService.ts | 19 +++-------- 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/src/vs/workbench/browser/parts/views/viewPane.ts b/src/vs/workbench/browser/parts/views/viewPane.ts index 04545f944c4..e6ba12a5794 100644 --- a/src/vs/workbench/browser/parts/views/viewPane.ts +++ b/src/vs/workbench/browser/parts/views/viewPane.ts @@ -21,11 +21,11 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IThemeService, ThemeIcon } from 'vs/platform/theme/common/themeService'; import { IPaneOptions, Pane, IPaneStyles } from 'vs/base/browser/ui/splitview/paneview'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; -import { Extensions as ViewContainerExtensions, IView, IViewDescriptorService, ViewContainerLocation, IViewsRegistry, IViewContentDescriptor, defaultViewIcon, IViewsService } from 'vs/workbench/common/views'; +import { Extensions as ViewContainerExtensions, IView, IViewDescriptorService, ViewContainerLocation, IViewsRegistry, IViewContentDescriptor, defaultViewIcon, IViewsService, ViewContainerLocationToString } from 'vs/workbench/common/views'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { assertIsDefined } from 'vs/base/common/types'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; -import { MenuId, Action2, IAction2Options } from 'vs/platform/actions/common/actions'; +import { MenuId, Action2, IAction2Options, IMenuService } from 'vs/platform/actions/common/actions'; import { createActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem'; import { parseLinkedText } from 'vs/base/common/linkedText'; import { IOpenerService } from 'vs/platform/opener/common/opener'; @@ -41,7 +41,6 @@ import { URI } from 'vs/base/common/uri'; import { registerIcon } from 'vs/platform/theme/common/iconRegistry'; import { Codicon } from 'vs/base/common/codicons'; import { CompositeMenuActions } from 'vs/workbench/browser/menuActions'; -import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; export interface IViewPaneOptions extends IPaneOptions { id: string; @@ -141,6 +140,26 @@ class ViewWelcomeController { } } +class ViewMenuActions extends CompositeMenuActions { + constructor( + element: HTMLElement, + viewId: string, + menuId: MenuId, + contextMenuId: MenuId, + @IContextKeyService contextKeyService: IContextKeyService, + @IMenuService menuService: IMenuService, + @IViewDescriptorService viewDescriptorService: IViewDescriptorService, + ) { + const scopedContextKeyService = contextKeyService.createScoped(element); + scopedContextKeyService.createKey('view', viewId); + const viewLocationKey = scopedContextKeyService.createKey('viewLocation', ViewContainerLocationToString(viewDescriptorService.getViewLocationById(viewId)!)); + super(menuId, contextMenuId, { shouldForwardArgs: true }, scopedContextKeyService, menuService); + this._register(scopedContextKeyService); + this._register(Event.filter(viewDescriptorService.onDidChangeLocation, e => e.views.some(view => view.id === viewId))(() => viewLocationKey.set(ViewContainerLocationToString(viewDescriptorService.getViewLocationById(viewId)!)))); + } + +} + export abstract class ViewPane extends Pane implements IView { private static readonly AlwaysShowActionsConfig = 'workbench.view.alwaysShowHeaderActions'; @@ -173,7 +192,7 @@ export abstract class ViewPane extends Pane implements IView { return this._titleDescription; } - private readonly menuActions: CompositeMenuActions; + private readonly menuActions: ViewMenuActions; private progressBar!: ProgressBar; private progressIndicator!: IProgressIndicator; @@ -209,10 +228,7 @@ export abstract class ViewPane extends Pane implements IView { this._titleDescription = options.titleDescription; this.showActionsAlways = !!options.showActionsAlways; - const scopedContextKeyService = this._register(contextKeyService.createScoped(this.element)); - scopedContextKeyService.createKey('view', this.id); - const scopedInstantiationService = instantiationService.createChild(new ServiceCollection([IContextKeyService, scopedContextKeyService])); - this.menuActions = this._register(scopedInstantiationService.createInstance(CompositeMenuActions, options.titleMenuId || MenuId.ViewTitle, MenuId.ViewTitleContext, { shouldForwardArgs: true })); + this.menuActions = this._register(this.instantiationService.createInstance(ViewMenuActions, this.element, this.id, options.titleMenuId || MenuId.ViewTitle, MenuId.ViewTitleContext)); this._register(this.menuActions.onDidChange(() => this.updateActions())); this.viewWelcomeController = new ViewWelcomeController(this.id, contextKeyService); diff --git a/src/vs/workbench/browser/parts/views/viewPaneContainer.ts b/src/vs/workbench/browser/parts/views/viewPaneContainer.ts index a6d4892875c..ababf9c2bbb 100644 --- a/src/vs/workbench/browser/parts/views/viewPaneContainer.ts +++ b/src/vs/workbench/browser/parts/views/viewPaneContainer.ts @@ -28,7 +28,7 @@ import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewl import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { Component } from 'vs/workbench/common/component'; -import { registerAction2, Action2, IAction2Options, MenuId, MenuRegistry, ISubmenuItem, SubmenuItemAction } from 'vs/platform/actions/common/actions'; +import { registerAction2, Action2, IAction2Options, MenuId, MenuRegistry, ISubmenuItem, SubmenuItemAction, IMenuService } from 'vs/platform/actions/common/actions'; import { CompositeDragAndDropObserver, DragAndDropObserver, toggleDropEffect } from 'vs/workbench/browser/dnd'; import { Orientation } from 'vs/base/browser/ui/sash/sash'; import { RunOnceScheduler } from 'vs/base/common/async'; @@ -293,6 +293,23 @@ class ViewPaneDropOverlay extends Themable { } } +class ViewContainerMenuActions extends CompositeMenuActions { + constructor( + element: HTMLElement, + viewContainer: ViewContainer, + @IViewDescriptorService viewDescriptorService: IViewDescriptorService, + @IContextKeyService contextKeyService: IContextKeyService, + @IMenuService menuService: IMenuService, + ) { + const scopedContextKeyService = contextKeyService.createScoped(element); + scopedContextKeyService.createKey('viewContainer', viewContainer.id); + const viewContainerLocationKey = scopedContextKeyService.createKey('viewContainerLocation', ViewContainerLocationToString(viewDescriptorService.getViewContainerLocation(viewContainer)!)); + super(MenuId.ViewContainerTitle, MenuId.ViewContainerTitleContext, { shouldForwardArgs: true }, scopedContextKeyService, menuService); + this._register(scopedContextKeyService); + this._register(Event.filter(viewDescriptorService.onDidChangeContainerLocation, e => e.viewContainer === viewContainer)(() => viewContainerLocationKey.set(ViewContainerLocationToString(viewDescriptorService.getViewContainerLocation(viewContainer)!)))); + } +} + export class ViewPaneContainer extends Component implements IViewPaneContainer { readonly viewContainer: ViewContainer; @@ -349,7 +366,7 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer { return this.paneItems.length; } - private readonly menuActions: CompositeMenuActions; + private menuActions!: ViewContainerMenuActions; constructor( id: string, @@ -379,9 +396,6 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer { this.visibleViewsCountFromCache = this.storageService.getNumber(this.visibleViewsStorageId, StorageScope.WORKSPACE, undefined); this._register(toDisposable(() => this.viewDisposables = dispose(this.viewDisposables))); this.viewContainerModel = this.viewDescriptorService.getViewContainerModel(container); - - this.menuActions = this._register(this.instantiationService.createInstance(CompositeMenuActions, MenuId.ViewContainerTitle, MenuId.ViewContainerTitleContext, { shouldForwardArgs: true })); - this._register(this.menuActions.onDidChange(() => this.updateTitleArea())); } create(parent: HTMLElement): void { @@ -391,6 +405,9 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer { this._register(this.paneview.onDidDrop(({ from, to }) => this.movePane(from as ViewPane, to as ViewPane))); this._register(addDisposableListener(parent, EventType.CONTEXT_MENU, (e: MouseEvent) => this.showContextMenu(new StandardMouseEvent(e)))); + this.menuActions = this._register(this.instantiationService.createInstance(ViewContainerMenuActions, this.paneview.element, this.viewContainer)); + this._register(this.menuActions.onDidChange(() => this.updateTitleArea())); + let overlay: ViewPaneDropOverlay | undefined; const getOverlayBounds: () => BoundingRect = () => { const fullSize = parent.getBoundingClientRect(); diff --git a/src/vs/workbench/browser/parts/views/viewsService.ts b/src/vs/workbench/browser/parts/views/viewsService.ts index ad98045d32f..d96efffddaa 100644 --- a/src/vs/workbench/browser/parts/views/viewsService.ts +++ b/src/vs/workbench/browser/parts/views/viewsService.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Disposable, IDisposable, toDisposable, DisposableStore } from 'vs/base/common/lifecycle'; -import { IViewDescriptorService, ViewContainer, IViewDescriptor, IView, ViewContainerLocation, IViewsService, IViewPaneContainer, getVisbileViewContextKey, getEnabledViewContainerContextKey, FocusedViewContext, ViewContainerLocationToString } from 'vs/workbench/common/views'; +import { IViewDescriptorService, ViewContainer, IViewDescriptor, IView, ViewContainerLocation, IViewsService, IViewPaneContainer, getVisbileViewContextKey, getEnabledViewContainerContextKey, FocusedViewContext } from 'vs/workbench/common/views'; import { Registry } from 'vs/platform/registry/common/platform'; import { IStorageService } from 'vs/platform/storage/common/storage'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; @@ -33,7 +33,6 @@ import { IProgressIndicator } from 'vs/platform/progress/common/progress'; import { CATEGORIES } from 'vs/workbench/common/actions'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { FilterViewPaneContainer } from 'vs/workbench/browser/parts/views/viewsViewlet'; -import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; export class ViewsService extends Disposable implements IViewsService { @@ -569,14 +568,8 @@ export class ViewsService extends Disposable implements IViewsService { } } - private createViewPaneContainer(element: HTMLElement, viewContainer: ViewContainer, viewContainerLocation: ViewContainerLocation, disposables: DisposableStore, contextKeyService: IContextKeyService, instantiationService: IInstantiationService): ViewPaneContainer { - const scopedContextKeyService = this._register(contextKeyService.createScoped(element)); - scopedContextKeyService.createKey('viewContainer', viewContainer.id); - scopedContextKeyService.createKey('viewContainerLocation', ViewContainerLocationToString(viewContainerLocation)); - scopedContextKeyService.createKey('viewLocation', ViewContainerLocationToString(viewContainerLocation)); - - const scopedInstantiationService = instantiationService.createChild(new ServiceCollection([IContextKeyService, scopedContextKeyService])); - const viewPaneContainer: ViewPaneContainer = (scopedInstantiationService as any).createInstance(viewContainer.ctorDescriptor!.ctor, ...(viewContainer.ctorDescriptor!.staticArguments || [])); + private createViewPaneContainer(element: HTMLElement, viewContainer: ViewContainer, viewContainerLocation: ViewContainerLocation, disposables: DisposableStore, instantiationService: IInstantiationService): ViewPaneContainer { + const viewPaneContainer: ViewPaneContainer = (instantiationService as any).createInstance(viewContainer.ctorDescriptor!.ctor, ...(viewContainer.ctorDescriptor!.staticArguments || [])); this.viewPaneContainers.set(viewPaneContainer.getId(), viewPaneContainer); disposables.add(toDisposable(() => this.viewPaneContainers.delete(viewPaneContainer.getId()))); @@ -604,7 +597,6 @@ export class ViewsService extends Disposable implements IViewsService { @IContextMenuService contextMenuService: IContextMenuService, @IExtensionService extensionService: IExtensionService, @IWorkspaceContextService contextService: IWorkspaceContextService, - @IContextKeyService private readonly contextKeyService: IContextKeyService, ) { super(viewContainer.id, telemetryService, storageService, instantiationService, themeService, contextMenuService, extensionService, contextService); } @@ -613,7 +605,7 @@ export class ViewsService extends Disposable implements IViewsService { const viewPaneContainerDisposables = this._register(new DisposableStore()); // Use composite's instantiation service to get the editor progress service for any editors instantiated within the composite - return that.createViewPaneContainer(element, viewContainer, ViewContainerLocation.Panel, viewPaneContainerDisposables, this.contextKeyService, this.instantiationService); + return that.createViewPaneContainer(element, viewContainer, ViewContainerLocation.Panel, viewPaneContainerDisposables, this.instantiationService); } } Registry.as(PanelExtensions.Panels).registerPanel(PanelDescriptor.create( @@ -643,7 +635,6 @@ export class ViewsService extends Disposable implements IViewsService { @IThemeService themeService: IThemeService, @IContextMenuService contextMenuService: IContextMenuService, @IExtensionService extensionService: IExtensionService, - @IContextKeyService private readonly contextKeyService: IContextKeyService, ) { super(viewContainer.id, telemetryService, storageService, instantiationService, themeService, contextMenuService, extensionService, contextService, layoutService, configurationService); } @@ -652,7 +643,7 @@ export class ViewsService extends Disposable implements IViewsService { const viewPaneContainerDisposables = this._register(new DisposableStore()); // Use composite's instantiation service to get the editor progress service for any editors instantiated within the composite - const viewPaneContainer = that.createViewPaneContainer(element, viewContainer, ViewContainerLocation.Sidebar, viewPaneContainerDisposables, this.contextKeyService, this.instantiationService); + const viewPaneContainer = that.createViewPaneContainer(element, viewContainer, ViewContainerLocation.Sidebar, viewPaneContainerDisposables, this.instantiationService); // Only updateTitleArea for non-filter views: microsoft/vscode-remote-release#3676 if (!(viewPaneContainer instanceof FilterViewPaneContainer)) {