Skip to content

Commit bc90807

Browse files
authored
title - actually fix menus (microsoft#199549)
1 parent 3dc8779 commit bc90807

File tree

5 files changed

+60
-32
lines changed

5 files changed

+60
-32
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export class MenuId {
126126
static readonly TestPeekTitle = new MenuId('TestPeekTitle');
127127
static readonly TouchBarContext = new MenuId('TouchBarContext');
128128
static readonly TitleBarContext = new MenuId('TitleBarContext');
129+
static readonly TitleBarTitleContext = new MenuId('TitleBarTitleContext');
129130
static readonly TunnelContext = new MenuId('TunnelContext');
130131
static readonly TunnelPrivacy = new MenuId('TunnelPrivacy');
131132
static readonly TunnelProtocol = new MenuId('TunnelProtocol');

src/vs/workbench/browser/actions/layoutActions.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -759,16 +759,18 @@ if (isWindows || isLinux || isWeb) {
759759
});
760760

761761
// Add separately to title bar context menu so we can use a different title
762-
MenuRegistry.appendMenuItem(MenuId.TitleBarContext, {
763-
command: {
764-
id: 'workbench.action.toggleMenuBar',
765-
title: localize('miMenuBarNoMnemonic', "Menu Bar"),
766-
toggled: ContextKeyExpr.and(IsMacNativeContext.toNegated(), ContextKeyExpr.notEquals('config.window.menuBarVisibility', 'hidden'), ContextKeyExpr.notEquals('config.window.menuBarVisibility', 'toggle'), ContextKeyExpr.notEquals('config.window.menuBarVisibility', 'compact'))
767-
},
768-
group: '2_config',
769-
when: IsAuxiliaryWindowFocusedContext.toNegated(),
770-
order: 0
771-
});
762+
for (const menuId of [MenuId.TitleBarContext, MenuId.TitleBarTitleContext]) {
763+
MenuRegistry.appendMenuItem(menuId, {
764+
command: {
765+
id: 'workbench.action.toggleMenuBar',
766+
title: localize('miMenuBarNoMnemonic', "Menu Bar"),
767+
toggled: ContextKeyExpr.and(IsMacNativeContext.toNegated(), ContextKeyExpr.notEquals('config.window.menuBarVisibility', 'hidden'), ContextKeyExpr.notEquals('config.window.menuBarVisibility', 'toggle'), ContextKeyExpr.notEquals('config.window.menuBarVisibility', 'compact'))
768+
},
769+
when: IsAuxiliaryWindowFocusedContext.toNegated(),
770+
group: menuId === MenuId.TitleBarTitleContext ? '2_config' : undefined,
771+
order: 0
772+
});
773+
}
772774
}
773775

774776
// --- Reset View Locations

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@ class ToggleConfigAction extends Action2 {
2121
id: `toggle.${section}`,
2222
title,
2323
toggled: ContextKeyExpr.equals(`config.${section}`, true),
24-
menu: {
25-
id: MenuId.TitleBarContext,
26-
when: mainWindowOnly ? IsAuxiliaryWindowFocusedContext.toNegated() : undefined,
27-
order,
28-
group: '2_config'
29-
}
24+
menu: [
25+
{
26+
id: MenuId.TitleBarContext,
27+
when: mainWindowOnly ? IsAuxiliaryWindowFocusedContext.toNegated() : undefined,
28+
order
29+
},
30+
{
31+
id: MenuId.TitleBarTitleContext,
32+
when: mainWindowOnly ? IsAuxiliaryWindowFocusedContext.toNegated() : undefined,
33+
order,
34+
group: '2_config'
35+
}
36+
]
3037
});
3138
}
3239

@@ -56,7 +63,10 @@ registerAction2(class ToggleEditorActions extends Action2 {
5663
id: `toggle.${ToggleEditorActions.settingsID}`,
5764
title: localize('toggle.editorActions', 'Editor Actions'),
5865
toggled: ContextKeyExpr.equals(`config.${ToggleEditorActions.settingsID}`, 'hidden').negate(),
59-
menu: { id: MenuId.TitleBarContext, order: 3, when: ContextKeyExpr.equals(`config.workbench.editor.showTabs`, 'none'), group: '2_config' }
66+
menu: [
67+
{ id: MenuId.TitleBarContext, order: 3, when: ContextKeyExpr.equals(`config.workbench.editor.showTabs`, 'none') },
68+
{ id: MenuId.TitleBarTitleContext, order: 3, when: ContextKeyExpr.equals(`config.workbench.editor.showTabs`, 'none'), group: '2_config' }
69+
]
6070
});
6171
}
6272

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ThemeIcon } from 'vs/base/common/themables';
1919
import { TITLE_BAR_ACTIVE_BACKGROUND, TITLE_BAR_ACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_BACKGROUND, TITLE_BAR_BORDER, WORKBENCH_BACKGROUND } from 'vs/workbench/common/theme';
2020
import { isMacintosh, isWindows, isLinux, isWeb, isNative, platformLocale } from 'vs/base/common/platform';
2121
import { Color } from 'vs/base/common/color';
22-
import { EventType, EventHelper, Dimension, append, $, addDisposableListener, prepend, reset, getWindow, getActiveWindow, getWindowId } from 'vs/base/browser/dom';
22+
import { EventType, EventHelper, Dimension, append, $, addDisposableListener, prepend, reset, getWindow, getActiveWindow, getWindowId, isAncestor } from 'vs/base/browser/dom';
2323
import { CustomMenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl';
2424
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2525
import { Emitter, Event } from 'vs/base/common/event';
@@ -412,16 +412,35 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart {
412412
this.primaryWindowControls = append(primaryControlLocation === 'left' ? this.leftContent : this.rightContent, $('div.window-controls-container.primary'));
413413
append(primaryControlLocation === 'left' ? this.rightContent : this.leftContent, $('div.window-controls-container.secondary'));
414414

415-
// Context menu on title
416-
[EventType.CONTEXT_MENU, EventType.CLICK].forEach(event => {
417-
this._register(addDisposableListener(this.rootContainer, event, e => {
418-
if (event === EventType.CONTEXT_MENU || (isMacintosh && e.metaKey /* https://github.com/microsoft/vscode/issues/173563 */)) {
419-
EventHelper.stop(e, event === EventType.CLICK /* prevents command center from appearing */);
420-
421-
this.onContextMenu(e, MenuId.TitleBarContext);
415+
// Context menu over title bar: depending on the OS and the location of the click this will either be
416+
// the overall context menu for the entire title bar or a specific title context menu.
417+
// Windows / Linux: we only support the overall context menu on the title bar
418+
// macOS: we support both the overall context menu and the title context menu.
419+
// in addition, we allow Cmd+click to bring up the title context menu.
420+
{
421+
this._register(addDisposableListener(this.rootContainer, EventType.CONTEXT_MENU, e => {
422+
EventHelper.stop(e);
423+
424+
let targetMenu: MenuId;
425+
if (isMacintosh && e.target instanceof HTMLElement && isAncestor(e.target, this.title)) {
426+
targetMenu = MenuId.TitleBarTitleContext;
427+
} else {
428+
targetMenu = MenuId.TitleBarContext;
422429
}
423-
}, event === EventType.CLICK /* prevents command center from appearing */));
424-
});
430+
431+
this.onContextMenu(e, targetMenu);
432+
}));
433+
434+
if (isMacintosh) {
435+
this._register(addDisposableListener(this.title, EventType.CLICK, e => {
436+
if (e.metaKey) {
437+
EventHelper.stop(e, true /* stop bubbling to prevent command center from opening */);
438+
439+
this.onContextMenu(e, MenuId.TitleBarTitleContext);
440+
}
441+
}, true /* capture phase to prevent command center from opening */));
442+
}
443+
}
425444

426445
// Focus action
427446
const that = this;

src/vs/workbench/electron-sandbox/window.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,11 +660,7 @@ export class NativeWindow extends BaseWindow {
660660

661661
const commandId = `workbench.action.revealPathInFinder${i}`;
662662
this.customTitleContextMenuDisposable.add(CommandsRegistry.registerCommand(commandId, () => this.nativeHostService.showItemInFolder(path.fsPath)));
663-
this.customTitleContextMenuDisposable.add(MenuRegistry.appendMenuItem(MenuId.TitleBarContext, {
664-
command: { id: commandId, title: label || posix.sep },
665-
order: -i,
666-
group: '1_file'
667-
}));
663+
this.customTitleContextMenuDisposable.add(MenuRegistry.appendMenuItem(MenuId.TitleBarTitleContext, { command: { id: commandId, title: label || posix.sep }, order: -i, group: '1_file' }));
668664
}
669665
}
670666

0 commit comments

Comments
 (0)