Skip to content

Commit c41b1ca

Browse files
authored
Allow menubar to convert into hamburger below threshold (microsoft#155223)
fixes microsoft#152906
1 parent 29a4da1 commit c41b1ca

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

src/vs/base/browser/ui/menu/menu.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export const MENU_ESCAPED_MNEMONIC_REGEX = /(&)?(&)([^\s&])/g;
3333

3434
export enum Direction {
3535
Right,
36-
Left,
37-
Down
36+
Left
3837
}
3938

4039
export interface IMenuOptions {

src/vs/base/browser/ui/menu/menubar.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
overflow: hidden;
1414
}
1515

16+
.menubar.overflow-menu-only {
17+
width: 38px;
18+
}
19+
1620
.fullscreen .menubar:not(.compact) {
1721
margin: 0px;
1822
padding: 4px 5px;
@@ -93,6 +97,7 @@
9397
justify-content: center;
9498
}
9599

100+
.menubar:not(.compact) .menubar-menu-button:first-child .toolbar-toggle-more::before,
96101
.menubar.compact .toolbar-toggle-more::before {
97102
content: "\eb94" !important;
98103
}

src/vs/base/browser/ui/menu/menubar.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ export class MenuBar extends Disposable {
334334
triggerKeys.push(KeyCode.RightArrow);
335335
} else if (this.options.compactMode === Direction.Left) {
336336
triggerKeys.push(KeyCode.LeftArrow);
337-
} else if (this.options.compactMode === Direction.Down) {
338-
triggerKeys.push(KeyCode.DownArrow);
339337
}
340338
}
341339

@@ -475,6 +473,11 @@ export class MenuBar extends Disposable {
475473
return;
476474
}
477475

476+
const overflowMenuOnlyClass = 'overflow-menu-only';
477+
478+
// Remove overflow only restriction to allow the most space
479+
this.container.classList.toggle(overflowMenuOnlyClass, false);
480+
478481
const sizeAvailable = this.container.offsetWidth;
479482
let currentSize = 0;
480483
let full = this.isCompact;
@@ -501,6 +504,18 @@ export class MenuBar extends Disposable {
501504
}
502505
}
503506

507+
508+
// If below minimium menu threshold, show the overflow menu only as hamburger menu
509+
if (this.numMenusShown - 1 <= showableMenus.length / 2) {
510+
for (const menuBarMenu of showableMenus) {
511+
menuBarMenu.buttonElement.style.visibility = 'hidden';
512+
}
513+
514+
full = true;
515+
this.numMenusShown = 0;
516+
currentSize = 0;
517+
}
518+
504519
// Overflow
505520
if (this.isCompact) {
506521
this.overflowMenu.actions = [];
@@ -540,6 +555,9 @@ export class MenuBar extends Disposable {
540555
this.container.appendChild(this.overflowMenu.buttonElement);
541556
this.overflowMenu.buttonElement.style.visibility = 'hidden';
542557
}
558+
559+
// If we are only showing the overflow, add this class to avoid taking up space
560+
this.container.classList.toggle(overflowMenuOnlyClass, this.numMenusShown === 0);
543561
}
544562

545563
private updateLabels(titleElement: HTMLElement, buttonElement: HTMLElement, label: string): void {

src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133

134134
/* width */
135135
width: 16px;
136+
flex-shrink: 0;
136137
}
137138

138139
.monaco-workbench .part.titlebar>.titlebar-container>.window-title>.command-center .action-item.quickopen>.action-label {

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -581,17 +581,6 @@ export class CustomMenubarControl extends MenubarControl {
581581
return getMenuBarVisibility(this.configurationService);
582582
}
583583

584-
private get currentCommandCenterEnabled(): boolean {
585-
const settingValue = this.configurationService.getValue<boolean>('window.commandCenter');
586-
587-
let enableCommandCenter = false;
588-
if (typeof settingValue === 'boolean') {
589-
enableCommandCenter = !!settingValue;
590-
}
591-
592-
return enableCommandCenter;
593-
}
594-
595584
private get currentDisableMenuBarAltFocus(): boolean {
596585
const settingValue = this.configurationService.getValue<boolean>('window.customMenuBarAltFocus');
597586

@@ -637,11 +626,6 @@ export class CustomMenubarControl extends MenubarControl {
637626

638627
private get currentCompactMenuMode(): Direction | undefined {
639628
if (this.currentMenubarVisibility !== 'compact') {
640-
// With the command center enabled, use compact menu in title bar and flow to the right
641-
if (this.currentCommandCenterEnabled) {
642-
return Direction.Down;
643-
}
644-
645629
return undefined;
646630
}
647631

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,6 @@ export class TitlebarPart extends Part implements ITitleService {
157157
this.installMenubar();
158158
}
159159
}
160-
161-
// Trigger a re-install of the menubar with command center change
162-
if (event.affectsConfiguration('window.commandCenter')) {
163-
if (this.currentMenubarVisibility !== 'compact') {
164-
this.uninstallMenubar();
165-
this.installMenubar();
166-
}
167-
}
168160
}
169161

170162
if (this.titleBarStyle !== 'native' && this.layoutControls && event.affectsConfiguration('workbench.layoutControl.enabled')) {

0 commit comments

Comments
 (0)