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

J
Johannes Rieken 已提交
6
import { ContextMenuHandler } from './contextMenuHandler';
7
import { IContextViewService, IContextMenuService } from './contextView';
J
Johannes Rieken 已提交
8
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
M
Matt Bierner 已提交
9
import { Event, Emitter } from 'vs/base/common/event';
10
import { INotificationService } from 'vs/platform/notification/common/notification';
11
import { IContextMenuDelegate } from 'vs/base/browser/contextmenu';
12
import { IThemeService } from 'vs/platform/theme/common/themeService';
B
Benjamin Pasero 已提交
13 14
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { Disposable } from 'vs/base/common/lifecycle';
15
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
I
isidor 已提交
16

B
Benjamin Pasero 已提交
17 18
export class ContextMenuService extends Disposable implements IContextMenuService {
	_serviceBrand: any;
E
Erich Gamma 已提交
19

B
Benjamin Pasero 已提交
20 21
	private _onDidContextMenu = this._register(new Emitter<void>());
	get onDidContextMenu(): Event<void> { return this._onDidContextMenu.event; }
E
Erich Gamma 已提交
22 23 24

	private contextMenuHandler: ContextMenuHandler;

B
Benjamin Pasero 已提交
25
	constructor(
26
		@ILayoutService layoutService: ILayoutService,
B
Benjamin Pasero 已提交
27 28 29
		@ITelemetryService telemetryService: ITelemetryService,
		@INotificationService notificationService: INotificationService,
		@IContextViewService contextViewService: IContextViewService,
30 31
		@IKeybindingService keybindingService: IKeybindingService,
		@IThemeService themeService: IThemeService
B
Benjamin Pasero 已提交
32 33 34
	) {
		super();

35
		this.contextMenuHandler = this._register(new ContextMenuHandler(layoutService.container, contextViewService, telemetryService, notificationService, keybindingService, themeService));
E
Erich Gamma 已提交
36 37
	}

B
Benjamin Pasero 已提交
38
	dispose(): void {
E
Erich Gamma 已提交
39 40 41
		this.contextMenuHandler.dispose();
	}

B
Benjamin Pasero 已提交
42
	setContainer(container: HTMLElement): void {
E
Erich Gamma 已提交
43 44 45 46 47
		this.contextMenuHandler.setContainer(container);
	}

	// ContextMenu

B
Benjamin Pasero 已提交
48
	showContextMenu(delegate: IContextMenuDelegate): void {
E
Erich Gamma 已提交
49
		this.contextMenuHandler.showContextMenu(delegate);
I
isidor 已提交
50 51 52
		this._onDidContextMenu.fire();
	}
}