Path: blob/main/src/vs/platform/contextview/browser/contextView.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IContextMenuDelegate } from '../../../base/browser/contextmenu.js';6import { StandardMouseEvent } from '../../../base/browser/mouseEvent.js';7import { AnchorAlignment, AnchorAxisAlignment, IAnchor, IContextViewProvider } from '../../../base/browser/ui/contextview/contextview.js';8import { IAction } from '../../../base/common/actions.js';9import { Event } from '../../../base/common/event.js';10import { IDisposable } from '../../../base/common/lifecycle.js';11import { IMenuActionOptions, MenuId } from '../../actions/common/actions.js';12import { IContextKeyService } from '../../contextkey/common/contextkey.js';13import { createDecorator } from '../../instantiation/common/instantiation.js';1415export const IContextViewService = createDecorator<IContextViewService>('contextViewService');1617export interface IContextViewService extends IContextViewProvider {1819readonly _serviceBrand: undefined;2021showContextView(delegate: IContextViewDelegate, container?: HTMLElement, shadowRoot?: boolean): IOpenContextView;22hideContextView(data?: any): void;23getContextViewElement(): HTMLElement;24layout(): void;25anchorAlignment?: AnchorAlignment;26}2728export interface IContextViewDelegate {2930canRelayout?: boolean; // Default: true3132/**33* The anchor where to position the context view.34* Use a `HTMLElement` to position the view at the element,35* a `StandardMouseEvent` to position it at the mouse position36* or an `IAnchor` to position it at a specific location.37*/38getAnchor(): HTMLElement | StandardMouseEvent | IAnchor;39render(container: HTMLElement): IDisposable;40onDOMEvent?(e: any, activeElement: HTMLElement): void;41onHide?(data?: any): void;42focus?(): void;43anchorAlignment?: AnchorAlignment;44anchorAxisAlignment?: AnchorAxisAlignment;4546// context views with higher layers are rendered over contet views with lower layers47layer?: number; // Default: 048}4950export interface IOpenContextView {51close: () => void;52}5354export const IContextMenuService = createDecorator<IContextMenuService>('contextMenuService');5556export interface IContextMenuService {5758readonly _serviceBrand: undefined;5960readonly onDidShowContextMenu: Event<void>;61readonly onDidHideContextMenu: Event<void>;6263showContextMenu(delegate: IContextMenuDelegate | IContextMenuMenuDelegate): void;64}6566export type IContextMenuMenuDelegate = {67/**68* The MenuId that should be used to populate the context menu.69*/70menuId?: MenuId;71/**72* Optional options how menu actions are invoked73*/74menuActionOptions?: IMenuActionOptions;75/**76* Optional context key service which drives the given menu77*/78contextKeyService?: IContextKeyService;7980/**81* Optional getter for extra actions. They will be prepended to the menu actions.82*/83getActions?(): IAction[];84} & Omit<IContextMenuDelegate, 'getActions'>;858687