@@ -11,7 +11,7 @@ import { getZoomFactor } from 'vs/base/browser/browser';
11
11
import { MenuBarVisibility , getTitleBarStyle , getMenuBarVisibility } from 'vs/platform/window/common/window' ;
12
12
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
13
13
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent' ;
14
- import { IAction , toAction } from 'vs/base/common/actions' ;
14
+ import { IAction } from 'vs/base/common/actions' ;
15
15
import { IConfigurationService , IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration' ;
16
16
import { DisposableStore , dispose } from 'vs/base/common/lifecycle' ;
17
17
import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService' ;
@@ -21,13 +21,13 @@ import { isMacintosh, isWindows, isLinux, isWeb } from 'vs/base/common/platform'
21
21
import { Color } from 'vs/base/common/color' ;
22
22
import { EventType , EventHelper , Dimension , isAncestor , append , $ , addDisposableListener , runAtThisOrScheduleAtNextAnimationFrame , prepend , reset } from 'vs/base/browser/dom' ;
23
23
import { CustomMenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl' ;
24
- import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
24
+ import { IInstantiationService , ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
25
25
import { Emitter , Event } from 'vs/base/common/event' ;
26
26
import { IStorageService } from 'vs/platform/storage/common/storage' ;
27
27
import { Parts , IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService' ;
28
28
import { createActionViewItem , createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem' ;
29
- import { IMenuService , IMenu , MenuId } from 'vs/platform/actions/common/actions' ;
30
- import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
29
+ import { Action2 , IMenuService , MenuId , registerAction2 } from 'vs/platform/actions/common/actions' ;
30
+ import { ContextKeyExpr , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
31
31
import { IHostService } from 'vs/workbench/services/host/browser/host' ;
32
32
import { Codicon } from 'vs/base/common/codicons' ;
33
33
import { getIconRegistry } from 'vs/platform/theme/common/iconRegistry' ;
@@ -82,8 +82,6 @@ export class TitlebarPart extends Part implements ITitleService {
82
82
83
83
private readonly windowTitle : WindowTitle ;
84
84
85
- private readonly titleContextMenu : IMenu ;
86
-
87
85
constructor (
88
86
@IContextMenuService private readonly contextMenuService : IContextMenuService ,
89
87
@IConfigurationService protected readonly configurationService : IConfigurationService ,
@@ -99,7 +97,6 @@ export class TitlebarPart extends Part implements ITitleService {
99
97
) {
100
98
super ( Parts . TITLEBAR_PART , { hasTitle : false } , themeService , storageService , layoutService ) ;
101
99
this . windowTitle = this . _register ( instantiationService . createInstance ( WindowTitle ) ) ;
102
- this . titleContextMenu = this . _register ( menuService . createMenu ( MenuId . TitleBarTitleContext , contextKeyService ) ) ;
103
100
104
101
this . titleBarStyle = getTitleBarStyle ( this . configurationService ) ;
105
102
@@ -276,13 +273,6 @@ export class TitlebarPart extends Part implements ITitleService {
276
273
allowContextMenu : true
277
274
} ) ;
278
275
279
- this . _register ( addDisposableListener ( this . layoutControls , EventType . CONTEXT_MENU , e => {
280
- EventHelper . stop ( e ) ;
281
-
282
- this . onLayoutControlContextMenu ( e , this . layoutControls ! ) ;
283
- } ) ) ;
284
-
285
-
286
276
const menu = this . _register ( this . menuService . createMenu ( MenuId . LayoutControlMenu , this . contextKeyService ) ) ;
287
277
const updateLayoutMenu = ( ) => {
288
278
if ( ! this . layoutToolbar ) {
@@ -305,11 +295,10 @@ export class TitlebarPart extends Part implements ITitleService {
305
295
306
296
// Context menu on title
307
297
[ EventType . CONTEXT_MENU , EventType . MOUSE_DOWN ] . forEach ( event => {
308
- this . _register ( addDisposableListener ( this . title , event , e => {
298
+ this . _register ( addDisposableListener ( this . rootContainer , event , e => {
309
299
if ( e . type === EventType . CONTEXT_MENU || e . metaKey ) {
310
300
EventHelper . stop ( e ) ;
311
-
312
- this . onContextMenu ( e ) ;
301
+ this . onContextMenu ( e , e . target === this . title ? MenuId . TitleBarTitleContext : MenuId . TitleBarContext ) ;
313
302
}
314
303
} ) ) ;
315
304
} ) ;
@@ -380,42 +369,23 @@ export class TitlebarPart extends Part implements ITitleService {
380
369
}
381
370
}
382
371
383
- private onContextMenu ( e : MouseEvent ) : void {
372
+ private onContextMenu ( e : MouseEvent , menuId : MenuId ) : void {
384
373
// Find target anchor
385
374
const event = new StandardMouseEvent ( e ) ;
386
375
const anchor = { x : event . posx , y : event . posy } ;
387
376
388
377
// Fill in contributed actions
378
+ const menu = this . menuService . createMenu ( menuId , this . contextKeyService ) ;
389
379
const actions : IAction [ ] = [ ] ;
390
- const actionsDisposable = createAndFillInContextMenuActions ( this . titleContextMenu , undefined , actions ) ;
391
-
392
- // Show it
393
- this . contextMenuService . showContextMenu ( {
394
- getAnchor : ( ) => anchor ,
395
- getActions : ( ) => actions ,
396
- onHide : ( ) => dispose ( actionsDisposable )
397
- } ) ;
398
- }
399
-
400
- private onLayoutControlContextMenu ( e : MouseEvent , el : HTMLElement ) : void {
401
- // Find target anchor
402
- const event = new StandardMouseEvent ( e ) ;
403
- const anchor = { x : event . posx , y : event . posy } ;
404
-
405
- const actions : IAction [ ] = [ ] ;
406
- actions . push ( toAction ( {
407
- id : 'layoutControl.hide' ,
408
- label : localize ( 'layoutControl.hide' , "Hide Layout Control" ) ,
409
- run : ( ) => {
410
- this . configurationService . updateValue ( 'workbench.layoutControl.enabled' , false ) ;
411
- }
412
- } ) ) ;
380
+ const actionsDisposable = createAndFillInContextMenuActions ( menu , undefined , actions ) ;
381
+ menu . dispose ( ) ;
413
382
414
383
// Show it
415
384
this . contextMenuService . showContextMenu ( {
416
385
getAnchor : ( ) => anchor ,
417
386
getActions : ( ) => actions ,
418
- domForShadowRoot : el
387
+ onHide : ( ) => dispose ( actionsDisposable ) ,
388
+ domForShadowRoot : event . target
419
389
} ) ;
420
390
}
421
391
@@ -499,3 +469,34 @@ registerThemingParticipant((theme, collector) => {
499
469
` ) ;
500
470
}
501
471
} ) ;
472
+
473
+
474
+ class ToogleConfigAction extends Action2 {
475
+
476
+ constructor ( private readonly section : string , title : string , order : number ) {
477
+ super ( {
478
+ id : `toggle.${ section } ` ,
479
+ title,
480
+ toggled : ContextKeyExpr . equals ( `config.${ section } ` , true ) ,
481
+ menu : { id : MenuId . TitleBarContext , order }
482
+ } ) ;
483
+ }
484
+
485
+ run ( accessor : ServicesAccessor , ...args : any [ ] ) : void {
486
+ const configService = accessor . get ( IConfigurationService ) ;
487
+ const value = configService . getValue ( this . section ) ;
488
+ configService . updateValue ( this . section , ! value ) ;
489
+ }
490
+ }
491
+
492
+ registerAction2 ( class ToogleCommandCenter extends ToogleConfigAction {
493
+ constructor ( ) {
494
+ super ( 'window.commandCenter' , localize ( 'toggle.commandCenter' , 'Show Command Center' ) , 1 ) ;
495
+ }
496
+ } ) ;
497
+
498
+ registerAction2 ( class ToogleLayoutControl extends ToogleConfigAction {
499
+ constructor ( ) {
500
+ super ( 'workbench.layoutControl.enabled' , localize ( 'toggle.layout' , 'Show Layout Controls' ) , 1 ) ;
501
+ }
502
+ } ) ;
0 commit comments