5
5
6
6
import { addDisposableListener , getWindow } from 'vs/base/browser/dom' ;
7
7
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent' ;
8
- import { IToolBarOptions , ToolBar } from 'vs/base/browser/ui/toolbar/toolbar' ;
8
+ import { IToolBarOptions , ToggleMenuAction , ToolBar } from 'vs/base/browser/ui/toolbar/toolbar' ;
9
9
import { IAction , Separator , SubmenuAction , toAction , WorkbenchActionExecutedClassification , WorkbenchActionExecutedEvent } from 'vs/base/common/actions' ;
10
10
import { coalesceInPlace } from 'vs/base/common/arrays' ;
11
11
import { intersection } from 'vs/base/common/collections' ;
@@ -16,6 +16,8 @@ import { DisposableStore } from 'vs/base/common/lifecycle';
16
16
import { localize } from 'vs/nls' ;
17
17
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem' ;
18
18
import { IMenuActionOptions , IMenuService , MenuId , MenuItemAction , SubmenuItemAction } from 'vs/platform/actions/common/actions' ;
19
+ import { createConfigureKeybindingAction } from 'vs/platform/actions/common/menuService' ;
20
+ import { ICommandService } from 'vs/platform/commands/common/commands' ;
19
21
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
20
22
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
21
23
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
@@ -90,12 +92,13 @@ export class WorkbenchToolBar extends ToolBar {
90
92
@IMenuService private readonly _menuService : IMenuService ,
91
93
@IContextKeyService private readonly _contextKeyService : IContextKeyService ,
92
94
@IContextMenuService private readonly _contextMenuService : IContextMenuService ,
93
- @IKeybindingService keybindingService : IKeybindingService ,
95
+ @IKeybindingService private readonly _keybindingService : IKeybindingService ,
96
+ @ICommandService private readonly _commandService : ICommandService ,
94
97
@ITelemetryService telemetryService : ITelemetryService ,
95
98
) {
96
99
super ( container , _contextMenuService , {
97
100
// defaults
98
- getKeyBinding : ( action ) => keybindingService . lookupKeybinding ( action . id ) ?? undefined ,
101
+ getKeyBinding : ( action ) => _keybindingService . lookupKeybinding ( action . id ) ?? undefined ,
99
102
// options (override defaults)
100
103
..._options ,
101
104
// mandatory (overide options)
@@ -181,8 +184,8 @@ export class WorkbenchToolBar extends ToolBar {
181
184
coalesceInPlace ( extraSecondary ) ;
182
185
super . setActions ( primary , Separator . join ( extraSecondary , secondary ) ) ;
183
186
184
- // add context menu for toggle actions
185
- if ( toggleActions . length > 0 ) {
187
+ // add context menu for toggle and configure keybinding actions
188
+ if ( toggleActions . length > 0 || primary . length > 0 ) {
186
189
this . _sessionDisposables . add ( addDisposableListener ( this . getElement ( ) , 'contextmenu' , e => {
187
190
const event = new StandardMouseEvent ( getWindow ( this . getElement ( ) ) , e ) ;
188
191
@@ -193,47 +196,53 @@ export class WorkbenchToolBar extends ToolBar {
193
196
event . preventDefault ( ) ;
194
197
event . stopPropagation ( ) ;
195
198
196
- let noHide = false ;
197
-
198
- // last item cannot be hidden when using ignore strategy
199
- if ( toggleActionsCheckedCount === 1 && this . _options ?. hiddenItemStrategy === HiddenItemStrategy . Ignore ) {
200
- noHide = true ;
201
- for ( let i = 0 ; i < toggleActions . length ; i ++ ) {
202
- if ( toggleActions [ i ] . checked ) {
203
- toggleActions [ i ] = toAction ( {
204
- id : action . id ,
205
- label : action . label ,
206
- checked : true ,
207
- enabled : false ,
208
- run ( ) { }
209
- } ) ;
210
- break ; // there is only one
211
- }
212
- }
213
- }
214
-
215
199
const primaryActions = [ ] ;
216
200
201
+ // -- Configure Keybinding Action --
217
202
if ( action instanceof MenuItemAction && action . menuKeybinding ) {
218
203
primaryActions . push ( action . menuKeybinding ) ;
204
+ } else if ( ! ( action instanceof SubmenuItemAction || action instanceof ToggleMenuAction ) ) {
205
+ primaryActions . push ( createConfigureKeybindingAction ( action . id , undefined , this . _commandService , this . _keybindingService ) ) ;
219
206
}
220
207
221
- // add "hide foo" actions
222
- if ( ! noHide && ( action instanceof MenuItemAction || action instanceof SubmenuItemAction ) ) {
223
- if ( ! action . hideActions ) {
224
- // no context menu for MenuItemAction instances that support no hiding
225
- // those are fake actions and need to be cleaned up
226
- return ;
208
+ // -- Hide Actions --
209
+ if ( toggleActions . length > 0 ) {
210
+ let noHide = false ;
211
+
212
+ // last item cannot be hidden when using ignore strategy
213
+ if ( toggleActionsCheckedCount === 1 && this . _options ?. hiddenItemStrategy === HiddenItemStrategy . Ignore ) {
214
+ noHide = true ;
215
+ for ( let i = 0 ; i < toggleActions . length ; i ++ ) {
216
+ if ( toggleActions [ i ] . checked ) {
217
+ toggleActions [ i ] = toAction ( {
218
+ id : action . id ,
219
+ label : action . label ,
220
+ checked : true ,
221
+ enabled : false ,
222
+ run ( ) { }
223
+ } ) ;
224
+ break ; // there is only one
225
+ }
226
+ }
227
+ }
228
+
229
+ // add "hide foo" actions
230
+ if ( ! noHide && ( action instanceof MenuItemAction || action instanceof SubmenuItemAction ) ) {
231
+ if ( ! action . hideActions ) {
232
+ // no context menu for MenuItemAction instances that support no hiding
233
+ // those are fake actions and need to be cleaned up
234
+ return ;
235
+ }
236
+ primaryActions . push ( action . hideActions . hide ) ;
237
+
238
+ } else {
239
+ primaryActions . push ( toAction ( {
240
+ id : 'label' ,
241
+ label : localize ( 'hide' , "Hide" ) ,
242
+ enabled : false ,
243
+ run ( ) { }
244
+ } ) ) ;
227
245
}
228
- primaryActions . push ( action . hideActions . hide ) ;
229
-
230
- } else {
231
- primaryActions . push ( toAction ( {
232
- id : 'label' ,
233
- label : localize ( 'hide' , "Hide" ) ,
234
- enabled : false ,
235
- run ( ) { }
236
- } ) ) ;
237
246
}
238
247
239
248
const actions = Separator . join ( primaryActions , toggleActions ) ;
@@ -251,6 +260,10 @@ export class WorkbenchToolBar extends ToolBar {
251
260
} ) ) ;
252
261
}
253
262
263
+ if ( actions . length === 0 ) {
264
+ return ;
265
+ }
266
+
254
267
this . _contextMenuService . showContextMenu ( {
255
268
getAnchor : ( ) => event ,
256
269
getActions : ( ) => actions ,
@@ -318,9 +331,10 @@ export class MenuWorkbenchToolBar extends WorkbenchToolBar {
318
331
@IContextKeyService contextKeyService : IContextKeyService ,
319
332
@IContextMenuService contextMenuService : IContextMenuService ,
320
333
@IKeybindingService keybindingService : IKeybindingService ,
334
+ @ICommandService commandService : ICommandService ,
321
335
@ITelemetryService telemetryService : ITelemetryService ,
322
336
) {
323
- super ( container , { resetMenu : menuId , ...options } , menuService , contextKeyService , contextMenuService , keybindingService , telemetryService ) ;
337
+ super ( container , { resetMenu : menuId , ...options } , menuService , contextKeyService , contextMenuService , keybindingService , commandService , telemetryService ) ;
324
338
325
339
// update logic
326
340
const menu = this . _store . add ( menuService . createMenu ( menuId , contextKeyService , { emitEventsForSubmenuChanges : true } ) ) ;
0 commit comments