contextMenuService.ts 1.6 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

J
Johannes Rieken 已提交
7 8 9
import { ContextMenuHandler } from './contextMenuHandler';
import { IContextViewService, IContextMenuService, IContextMenuDelegate } from './contextView';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
I
isidor 已提交
10
import Event, { Emitter } from 'vs/base/common/event';
11
import { INotificationService } from 'vs/platform/notification/common/notification';
I
isidor 已提交
12

E
Erich Gamma 已提交
13 14

export class ContextMenuService implements IContextMenuService {
15
	public _serviceBrand: any;
E
Erich Gamma 已提交
16 17

	private contextMenuHandler: ContextMenuHandler;
I
isidor 已提交
18
	private _onDidContextMenu = new Emitter<void>();
E
Erich Gamma 已提交
19

20 21
	constructor(container: HTMLElement, telemetryService: ITelemetryService, notificationService: INotificationService, contextViewService: IContextViewService) {
		this.contextMenuHandler = new ContextMenuHandler(container, contextViewService, telemetryService, notificationService);
E
Erich Gamma 已提交
22 23
	}

B
Benjamin Pasero 已提交
24
	public dispose(): void {
E
Erich Gamma 已提交
25 26 27 28 29 30 31 32 33
		this.contextMenuHandler.dispose();
	}

	public setContainer(container: HTMLElement): void {
		this.contextMenuHandler.setContainer(container);
	}

	// ContextMenu

B
Benjamin Pasero 已提交
34
	public showContextMenu(delegate: IContextMenuDelegate): void {
E
Erich Gamma 已提交
35
		this.contextMenuHandler.showContextMenu(delegate);
I
isidor 已提交
36 37 38 39 40
		this._onDidContextMenu.fire();
	}

	public get onDidContextMenu(): Event<void> {
		return this._onDidContextMenu.event;
E
Erich Gamma 已提交
41
	}
I
isidor 已提交
42
}