66import { IAction , IActionRunner , ActionRunner } from 'vs/base/common/actions' ;
77import { Separator } from 'vs/base/browser/ui/actionbar/actionbar' ;
88import * as dom from 'vs/base/browser/dom' ;
9- import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
9+ import { IContextMenuService , IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
1010import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
1111import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
1212import { webFrame } from 'electron' ;
@@ -18,11 +18,53 @@ import { once } from 'vs/base/common/functional';
1818import { Disposable } from 'vs/base/common/lifecycle' ;
1919import { IContextMenuItem } from 'vs/base/parts/contextmenu/common/contextmenu' ;
2020import { popup } from 'vs/base/parts/contextmenu/electron-browser/contextmenu' ;
21+ import { getTitleBarStyle } from 'vs/platform/windows/common/windows' ;
22+ import { isMacintosh } from 'vs/base/common/platform' ;
23+ import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
24+ import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
25+ import { ContextMenuService as HTMLContextMenuService } from 'vs/platform/contextview/browser/contextMenuService' ;
26+ import { IThemeService } from 'vs/platform/theme/common/themeService' ;
27+ import { registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
2128
2229export class ContextMenuService extends Disposable implements IContextMenuService {
2330
2431 _serviceBrand : any ;
2532
33+ get onDidContextMenu ( ) : Event < void > { return this . impl . onDidContextMenu ; }
34+
35+ private impl : IContextMenuService ;
36+
37+ constructor (
38+ @INotificationService notificationService : INotificationService ,
39+ @ITelemetryService telemetryService : ITelemetryService ,
40+ @IKeybindingService keybindingService : IKeybindingService ,
41+ @IConfigurationService configurationService : IConfigurationService ,
42+ @IEnvironmentService environmentService : IEnvironmentService ,
43+ @IContextViewService contextViewService : IContextViewService ,
44+ @IThemeService themeService : IThemeService
45+ ) {
46+ super ( ) ;
47+
48+ // Custom context menu: Linux/Windows if custom title is enabled
49+ if ( ! isMacintosh && getTitleBarStyle ( configurationService , environmentService ) === 'custom' ) {
50+ this . impl = new HTMLContextMenuService ( null , telemetryService , notificationService , contextViewService , keybindingService , themeService ) ;
51+ }
52+
53+ // Native context menu: otherwise
54+ else {
55+ this . impl = new NativeContextMenuService ( notificationService , telemetryService , keybindingService ) ;
56+ }
57+ }
58+
59+ showContextMenu ( delegate : IContextMenuDelegate ) : void {
60+ this . impl . showContextMenu ( delegate ) ;
61+ }
62+ }
63+
64+ class NativeContextMenuService extends Disposable implements IContextMenuService {
65+
66+ _serviceBrand : any ;
67+
2668 private _onDidContextMenu = this . _register ( new Emitter < void > ( ) ) ;
2769 get onDidContextMenu ( ) : Event < void > { return this . _onDidContextMenu . event ; }
2870
@@ -145,3 +187,5 @@ export class ContextMenuService extends Disposable implements IContextMenuServic
145187 res . then ( undefined , e => this . notificationService . error ( e ) ) ;
146188 }
147189}
190+
191+ registerSingleton ( IContextMenuService , ContextMenuService , true ) ;
0 commit comments