Skip to content

Commit d3800d2

Browse files
committed
add context menu to hide/show CC and layout controls
1 parent 27bb32d commit d3800d2

File tree

2 files changed

+44
-42
lines changed

2 files changed

+44
-42
lines changed

src/vs/platform/actions/common/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export class MenuId {
108108
static readonly TestPeekElement = new MenuId('TestPeekElement');
109109
static readonly TestPeekTitle = new MenuId('TestPeekTitle');
110110
static readonly TouchBarContext = new MenuId('TouchBarContext');
111+
static readonly TitleBarContext = new MenuId('TitleBarContext');
111112
static readonly TitleBarTitleContext = new MenuId('TitleBarTitleContext');
112113
static readonly TunnelContext = new MenuId('TunnelContext');
113114
static readonly TunnelPrivacy = new MenuId('TunnelPrivacy');

src/vs/workbench/browser/parts/titlebar/titlebarPart.ts

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { getZoomFactor } from 'vs/base/browser/browser';
1111
import { MenuBarVisibility, getTitleBarStyle, getMenuBarVisibility } from 'vs/platform/window/common/window';
1212
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1313
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
14-
import { IAction, toAction } from 'vs/base/common/actions';
14+
import { IAction } from 'vs/base/common/actions';
1515
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
1616
import { DisposableStore, dispose } from 'vs/base/common/lifecycle';
1717
import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService';
@@ -21,13 +21,13 @@ import { isMacintosh, isWindows, isLinux, isWeb } from 'vs/base/common/platform'
2121
import { Color } from 'vs/base/common/color';
2222
import { EventType, EventHelper, Dimension, isAncestor, append, $, addDisposableListener, runAtThisOrScheduleAtNextAnimationFrame, prepend, reset } from 'vs/base/browser/dom';
2323
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';
2525
import { Emitter, Event } from 'vs/base/common/event';
2626
import { IStorageService } from 'vs/platform/storage/common/storage';
2727
import { Parts, IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
2828
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';
3131
import { IHostService } from 'vs/workbench/services/host/browser/host';
3232
import { Codicon } from 'vs/base/common/codicons';
3333
import { getIconRegistry } from 'vs/platform/theme/common/iconRegistry';
@@ -82,8 +82,6 @@ export class TitlebarPart extends Part implements ITitleService {
8282

8383
private readonly windowTitle: WindowTitle;
8484

85-
private readonly titleContextMenu: IMenu;
86-
8785
constructor(
8886
@IContextMenuService private readonly contextMenuService: IContextMenuService,
8987
@IConfigurationService protected readonly configurationService: IConfigurationService,
@@ -99,7 +97,6 @@ export class TitlebarPart extends Part implements ITitleService {
9997
) {
10098
super(Parts.TITLEBAR_PART, { hasTitle: false }, themeService, storageService, layoutService);
10199
this.windowTitle = this._register(instantiationService.createInstance(WindowTitle));
102-
this.titleContextMenu = this._register(menuService.createMenu(MenuId.TitleBarTitleContext, contextKeyService));
103100

104101
this.titleBarStyle = getTitleBarStyle(this.configurationService);
105102

@@ -276,13 +273,6 @@ export class TitlebarPart extends Part implements ITitleService {
276273
allowContextMenu: true
277274
});
278275

279-
this._register(addDisposableListener(this.layoutControls, EventType.CONTEXT_MENU, e => {
280-
EventHelper.stop(e);
281-
282-
this.onLayoutControlContextMenu(e, this.layoutControls!);
283-
}));
284-
285-
286276
const menu = this._register(this.menuService.createMenu(MenuId.LayoutControlMenu, this.contextKeyService));
287277
const updateLayoutMenu = () => {
288278
if (!this.layoutToolbar) {
@@ -305,11 +295,10 @@ export class TitlebarPart extends Part implements ITitleService {
305295

306296
// Context menu on title
307297
[EventType.CONTEXT_MENU, EventType.MOUSE_DOWN].forEach(event => {
308-
this._register(addDisposableListener(this.title, event, e => {
298+
this._register(addDisposableListener(this.rootContainer, event, e => {
309299
if (e.type === EventType.CONTEXT_MENU || e.metaKey) {
310300
EventHelper.stop(e);
311-
312-
this.onContextMenu(e);
301+
this.onContextMenu(e, e.target === this.title ? MenuId.TitleBarTitleContext : MenuId.TitleBarContext);
313302
}
314303
}));
315304
});
@@ -380,42 +369,23 @@ export class TitlebarPart extends Part implements ITitleService {
380369
}
381370
}
382371

383-
private onContextMenu(e: MouseEvent): void {
372+
private onContextMenu(e: MouseEvent, menuId: MenuId): void {
384373
// Find target anchor
385374
const event = new StandardMouseEvent(e);
386375
const anchor = { x: event.posx, y: event.posy };
387376

388377
// Fill in contributed actions
378+
const menu = this.menuService.createMenu(menuId, this.contextKeyService);
389379
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();
413382

414383
// Show it
415384
this.contextMenuService.showContextMenu({
416385
getAnchor: () => anchor,
417386
getActions: () => actions,
418-
domForShadowRoot: el
387+
onHide: () => dispose(actionsDisposable),
388+
domForShadowRoot: event.target
419389
});
420390
}
421391

@@ -499,3 +469,34 @@ registerThemingParticipant((theme, collector) => {
499469
`);
500470
}
501471
});
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

Comments
 (0)