UNPKG

@sussudio/platform

Version:

Internal APIs for VS Code's service injection the base services.

140 lines (139 loc) 4.95 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc, d; if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function') r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); }; }; import { ModifierKeyEmitter } from '@sussudio/base/browser/dom.mjs'; import { Separator } from '@sussudio/base/common/actions.mjs'; import { Emitter } from '@sussudio/base/common/event.mjs'; import { Disposable } from '@sussudio/base/common/lifecycle.mjs'; import { createAndFillInContextMenuActions } from '../../actions/browser/menuEntryActionViewItem.mjs'; import { IMenuService, MenuId } from '../../actions/common/actions.mjs'; import { IContextKeyService } from '../../contextkey/common/contextkey.mjs'; import { IKeybindingService } from '../../keybinding/common/keybinding.mjs'; import { INotificationService } from '../../notification/common/notification.mjs'; import { ITelemetryService } from '../../telemetry/common/telemetry.mjs'; import { IThemeService } from '../../theme/common/themeService.mjs'; import { ContextMenuHandler } from './contextMenuHandler'; import { IContextViewService } from './contextView'; let ContextMenuService = class ContextMenuService extends Disposable { telemetryService; notificationService; contextViewService; keybindingService; themeService; menuService; contextKeyService; _contextMenuHandler = undefined; get contextMenuHandler() { if (!this._contextMenuHandler) { this._contextMenuHandler = new ContextMenuHandler( this.contextViewService, this.telemetryService, this.notificationService, this.keybindingService, this.themeService, ); } return this._contextMenuHandler; } _onDidShowContextMenu = this._store.add(new Emitter()); onDidShowContextMenu = this._onDidShowContextMenu.event; _onDidHideContextMenu = this._store.add(new Emitter()); onDidHideContextMenu = this._onDidHideContextMenu.event; constructor( telemetryService, notificationService, contextViewService, keybindingService, themeService, menuService, contextKeyService, ) { super(); this.telemetryService = telemetryService; this.notificationService = notificationService; this.contextViewService = contextViewService; this.keybindingService = keybindingService; this.themeService = themeService; this.menuService = menuService; this.contextKeyService = contextKeyService; } configure(options) { this.contextMenuHandler.configure(options); } // ContextMenu showContextMenu(delegate) { delegate = ContextMenuMenuDelegate.transform(delegate, this.menuService, this.contextKeyService); this.contextMenuHandler.showContextMenu({ ...delegate, onHide: (didCancel) => { delegate.onHide?.(didCancel); this._onDidHideContextMenu.fire(); }, }); ModifierKeyEmitter.getInstance().resetKeyStatus(); this._onDidShowContextMenu.fire(); } }; ContextMenuService = __decorate( [ __param(0, ITelemetryService), __param(1, INotificationService), __param(2, IContextViewService), __param(3, IKeybindingService), __param(4, IThemeService), __param(5, IMenuService), __param(6, IContextKeyService), ], ContextMenuService, ); export { ContextMenuService }; export var ContextMenuMenuDelegate; (function (ContextMenuMenuDelegate) { function is(thing) { return thing && thing.menuId instanceof MenuId; } function transform(delegate, menuService, globalContextKeyService) { if (!is(delegate)) { return delegate; } const { menuId, menuActionOptions, contextKeyService } = delegate; return { ...delegate, getActions: () => { const target = []; if (menuId) { const menu = menuService.createMenu(menuId, contextKeyService ?? globalContextKeyService); createAndFillInContextMenuActions(menu, menuActionOptions, target); menu.dispose(); } if (!delegate.getActions) { return target; } else { return Separator.join(delegate.getActions(), target); } }, }; } ContextMenuMenuDelegate.transform = transform; })(ContextMenuMenuDelegate || (ContextMenuMenuDelegate = {}));