#114901 revert partially

- do not scope view pane container context to its domnode
- only use target while creating the menu actions
This commit is contained in:
Sandeep Somavarapu 2021-02-09 08:49:53 +01:00
parent 65505d8bec
commit 714fd96f61
3 changed files with 51 additions and 27 deletions

View file

@ -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);

View file

@ -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();

View file

@ -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<PanelRegistry>(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)) {