5
5
6
6
import { IAction , IActionRunner , ActionRunner , WorkbenchActionExecutedEvent , WorkbenchActionExecutedClassification , Separator , SubmenuAction } from 'vs/base/common/actions' ;
7
7
import * as dom from 'vs/base/browser/dom' ;
8
- import { IContextMenuService , IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
8
+ import { IContextMenuMenuDelegate , IContextMenuService , IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
9
9
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
10
10
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
11
11
import { getZoomFactor } from 'vs/base/browser/browser' ;
12
12
import { unmnemonicLabel } from 'vs/base/common/labels' ;
13
13
import { INotificationService } from 'vs/platform/notification/common/notification' ;
14
14
import { IContextMenuDelegate , IContextMenuEvent } from 'vs/base/browser/contextmenu' ;
15
15
import { once } from 'vs/base/common/functional' ;
16
- import { Disposable } from 'vs/base/common/lifecycle' ;
17
16
import { IContextMenuItem } from 'vs/base/parts/contextmenu/common/contextmenu' ;
18
17
import { popup } from 'vs/base/parts/contextmenu/electron-sandbox/contextmenu' ;
19
18
import { getTitleBarStyle } from 'vs/platform/window/common/window' ;
20
19
import { isMacintosh , isWindows } from 'vs/base/common/platform' ;
21
20
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
22
- import { ContextMenuService as HTMLContextMenuService } from 'vs/platform/contextview/browser/contextMenuService' ;
21
+ import { ContextMenuMenuDelegate , ContextMenuService as HTMLContextMenuService } from 'vs/platform/contextview/browser/contextMenuService' ;
23
22
import { IThemeService } from 'vs/platform/theme/common/themeService' ;
24
23
import { registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
25
24
import { stripIcons } from 'vs/base/common/iconLabels' ;
26
25
import { coalesce } from 'vs/base/common/arrays' ;
27
26
import { Event , Emitter } from 'vs/base/common/event' ;
28
27
import { AnchorAlignment , AnchorAxisAlignment } from 'vs/base/browser/ui/contextview/contextview' ;
28
+ import { IMenuService } from 'vs/platform/actions/common/actions' ;
29
+ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
30
+ import { Disposable } from 'vs/base/common/lifecycle' ;
29
31
30
- export class ContextMenuService extends Disposable implements IContextMenuService {
32
+ export class ContextMenuService implements IContextMenuService {
31
33
32
34
declare readonly _serviceBrand : undefined ;
33
35
34
- private impl : IContextMenuService ;
36
+ private impl : HTMLContextMenuService | NativeContextMenuService ;
35
37
36
38
get onDidShowContextMenu ( ) : Event < void > { return this . impl . onDidShowContextMenu ; }
37
39
get onDidHideContextMenu ( ) : Event < void > { return this . impl . onDidHideContextMenu ; }
@@ -42,22 +44,27 @@ export class ContextMenuService extends Disposable implements IContextMenuServic
42
44
@IKeybindingService keybindingService : IKeybindingService ,
43
45
@IConfigurationService configurationService : IConfigurationService ,
44
46
@IContextViewService contextViewService : IContextViewService ,
45
- @IThemeService themeService : IThemeService
47
+ @IThemeService themeService : IThemeService ,
48
+ @IMenuService menuService : IMenuService ,
49
+ @IContextKeyService contextKeyService : IContextKeyService ,
46
50
) {
47
- super ( ) ;
48
51
49
52
// Custom context menu: Linux/Windows if custom title is enabled
50
53
if ( ! isMacintosh && getTitleBarStyle ( configurationService ) === 'custom' ) {
51
- this . impl = new HTMLContextMenuService ( telemetryService , notificationService , contextViewService , keybindingService , themeService ) ;
54
+ this . impl = new HTMLContextMenuService ( telemetryService , notificationService , contextViewService , keybindingService , themeService , menuService , contextKeyService ) ;
52
55
}
53
56
54
57
// Native context menu: otherwise
55
58
else {
56
- this . impl = new NativeContextMenuService ( notificationService , telemetryService , keybindingService ) ;
59
+ this . impl = new NativeContextMenuService ( notificationService , telemetryService , keybindingService , menuService , contextKeyService ) ;
57
60
}
58
61
}
59
62
60
- showContextMenu ( delegate : IContextMenuDelegate ) : void {
63
+ dispose ( ) : void {
64
+ this . impl . dispose ( ) ;
65
+ }
66
+
67
+ showContextMenu ( delegate : IContextMenuDelegate | IContextMenuMenuDelegate ) : void {
61
68
this . impl . showContextMenu ( delegate ) ;
62
69
}
63
70
}
@@ -66,21 +73,26 @@ class NativeContextMenuService extends Disposable implements IContextMenuService
66
73
67
74
declare readonly _serviceBrand : undefined ;
68
75
69
- private readonly _onDidShowContextMenu = new Emitter < void > ( ) ;
76
+ private readonly _onDidShowContextMenu = this . _store . add ( new Emitter < void > ( ) ) ;
70
77
readonly onDidShowContextMenu = this . _onDidShowContextMenu . event ;
71
78
72
- private readonly _onDidHideContextMenu = new Emitter < void > ( ) ;
79
+ private readonly _onDidHideContextMenu = this . _store . add ( new Emitter < void > ( ) ) ;
73
80
readonly onDidHideContextMenu = this . _onDidHideContextMenu . event ;
74
81
75
82
constructor (
76
83
@INotificationService private readonly notificationService : INotificationService ,
77
84
@ITelemetryService private readonly telemetryService : ITelemetryService ,
78
- @IKeybindingService private readonly keybindingService : IKeybindingService
85
+ @IKeybindingService private readonly keybindingService : IKeybindingService ,
86
+ @IMenuService private readonly menuService : IMenuService ,
87
+ @IContextKeyService private readonly contextKeyService : IContextKeyService ,
79
88
) {
80
89
super ( ) ;
81
90
}
82
91
83
- showContextMenu ( delegate : IContextMenuDelegate ) : void {
92
+ showContextMenu ( delegate : IContextMenuDelegate | IContextMenuMenuDelegate ) : void {
93
+
94
+ delegate = ContextMenuMenuDelegate . transform ( delegate , this . menuService , this . contextKeyService ) ;
95
+
84
96
const actions = delegate . getActions ( ) ;
85
97
if ( actions . length ) {
86
98
const onHide = once ( ( ) => {
0 commit comments