Skip to content

Commit e64c658

Browse files
committed
move max menu/toolbar size into Toolbar itself, hidden item don't count against limit
fixes microsoft#167270
1 parent 9a188c9 commit e64c658

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

src/vs/platform/actions/browser/menuEntryActionViewItem.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,18 @@ export function createAndFillInContextMenuActions(menu: IMenu, options: IMenuAct
3737
fillInActions(groups, target, useAlternativeActions, primaryGroup ? actionGroup => actionGroup === primaryGroup : actionGroup => actionGroup === 'navigation');
3838
}
3939

40-
export function createAndFillInActionBarActions(menu: IMenu, options: IMenuActionOptions | undefined, target: IAction[] | { primary: IAction[]; secondary: IAction[] }, primaryGroup?: string | ((actionGroup: string) => boolean), primaryMaxCount?: number, shouldInlineSubmenu?: (action: SubmenuAction, group: string, groupSize: number) => boolean, useSeparatorsInPrimaryActions?: boolean): void {
40+
export function createAndFillInActionBarActions(menu: IMenu, options: IMenuActionOptions | undefined, target: IAction[] | { primary: IAction[]; secondary: IAction[] }, primaryGroup?: string | ((actionGroup: string) => boolean), shouldInlineSubmenu?: (action: SubmenuAction, group: string, groupSize: number) => boolean, useSeparatorsInPrimaryActions?: boolean): void {
4141
const groups = menu.getActions(options);
4242
const isPrimaryAction = typeof primaryGroup === 'string' ? (actionGroup: string) => actionGroup === primaryGroup : primaryGroup;
4343

4444
// Action bars handle alternative actions on their own so the alternative actions should be ignored
45-
fillInActions(groups, target, false, isPrimaryAction, primaryMaxCount, shouldInlineSubmenu, useSeparatorsInPrimaryActions);
45+
fillInActions(groups, target, false, isPrimaryAction, shouldInlineSubmenu, useSeparatorsInPrimaryActions);
4646
}
4747

4848
function fillInActions(
4949
groups: ReadonlyArray<[string, ReadonlyArray<MenuItemAction | SubmenuItemAction>]>, target: IAction[] | { primary: IAction[]; secondary: IAction[] },
5050
useAlternativeActions: boolean,
5151
isPrimaryAction: (actionGroup: string) => boolean = actionGroup => actionGroup === 'navigation',
52-
primaryMaxCount: number = Number.MAX_SAFE_INTEGER,
5352
shouldInlineSubmenu: (action: SubmenuAction, group: string, groupSize: number) => boolean = () => false,
5453
useSeparatorsInPrimaryActions: boolean = false
5554
): void {
@@ -101,16 +100,10 @@ function fillInActions(
101100
// inlining submenus with length 0 or 1 is easy,
102101
// larger submenus need to be checked with the overall limit
103102
const submenuActions = action.actions;
104-
if ((submenuActions.length <= 1 || target.length + submenuActions.length - 2 <= primaryMaxCount) && shouldInlineSubmenu(action, group, target.length)) {
103+
if (submenuActions.length <= 1 && shouldInlineSubmenu(action, group, target.length)) {
105104
target.splice(index, 1, ...submenuActions);
106105
}
107106
}
108-
109-
// overflow items from the primary group into the secondary bucket
110-
if (primaryBucket !== secondaryBucket && primaryBucket.length > primaryMaxCount) {
111-
const overflow = primaryBucket.splice(primaryMaxCount, primaryBucket.length - primaryMaxCount);
112-
secondaryBucket.unshift(...overflow, new Separator());
113-
}
114107
}
115108

116109
export interface IMenuEntryActionViewItemOptions {

src/vs/platform/actions/browser/toolbar.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ export type IWorkbenchToolBarOptions = IToolBarOptions & {
5959

6060
/** This is controlled by the WorkbenchToolBar */
6161
allowContextMenu?: never;
62+
63+
/**
64+
* Maximun number of items that can shown. Extra items will be shown in the overflow menu.
65+
*/
66+
maxNumberOfItems?: number;
6267
};
6368

6469
/**
@@ -107,10 +112,11 @@ export class WorkbenchToolBar extends ToolBar {
107112
const secondary = _secondary.slice();
108113
const toggleActions: IAction[] = [];
109114

115+
const extraSecondary: IAction[] = [];
116+
110117
let someAreHidden = false;
111118
// unless disabled, move all hidden items to secondary group or ignore them
112119
if (this._options?.hiddenItemStrategy !== HiddenItemStrategy.NoHide) {
113-
let shouldPrependSeparator = secondary.length > 0;
114120
for (let i = 0; i < primary.length; i++) {
115121
const action = primary[i];
116122
if (!(action instanceof MenuItemAction) && !(action instanceof SubmenuItemAction)) {
@@ -129,17 +135,30 @@ export class WorkbenchToolBar extends ToolBar {
129135
someAreHidden = true;
130136
primary[i] = undefined!;
131137
if (this._options?.hiddenItemStrategy !== HiddenItemStrategy.Ignore) {
132-
if (shouldPrependSeparator) {
133-
shouldPrependSeparator = false;
134-
secondary.unshift(new Separator());
135-
}
136-
secondary.unshift(action);
138+
extraSecondary[i] = action;
137139
}
138140
}
139141
}
140142
}
143+
144+
// count for max
145+
if (this._options?.maxNumberOfItems !== undefined) {
146+
let count = 0;
147+
for (let i = 0; i < primary.length; i++) {
148+
const action = primary[i];
149+
if (!action) {
150+
continue;
151+
}
152+
if (++count >= this._options.maxNumberOfItems) {
153+
primary[i] = undefined!;
154+
extraSecondary[i] = action;
155+
}
156+
}
157+
}
158+
141159
coalesceInPlace(primary);
142-
super.setActions(primary, secondary);
160+
coalesceInPlace(extraSecondary);
161+
super.setActions(primary, Separator.join(extraSecondary, secondary));
143162

144163
// add context menu for toggle actions
145164
if (toggleActions.length > 0) {
@@ -210,12 +229,6 @@ export interface IToolBarRenderOptions {
210229
*/
211230
primaryGroup?: string | ((actionGroup: string) => boolean);
212231

213-
/**
214-
* Limits the number of items that make it in the primary group. The rest overflows into the
215-
* secondary menu.
216-
*/
217-
primaryMaxCount?: number;
218-
219232
/**
220233
* Inlinse submenus with just a single item
221234
*/
@@ -269,7 +282,7 @@ export class MenuWorkbenchToolBar extends WorkbenchToolBar {
269282
menu,
270283
options?.menuOptions,
271284
{ primary, secondary },
272-
options?.toolbarOptions?.primaryGroup, options?.toolbarOptions?.primaryMaxCount, options?.toolbarOptions?.shouldInlineSubmenu, options?.toolbarOptions?.useSeparatorsInPrimaryActions
285+
options?.toolbarOptions?.primaryGroup, options?.toolbarOptions?.shouldInlineSubmenu, options?.toolbarOptions?.useSeparatorsInPrimaryActions
273286
);
274287
super.setActions(primary, secondary);
275288
};

src/vs/workbench/browser/parts/editor/titleControl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ export abstract class TitleControl extends Themable {
188188
anchorAlignmentProvider: () => AnchorAlignment.RIGHT,
189189
renderDropdownAsChildElement: this.renderDropdownAsChildElement,
190190
telemetrySource: 'editorPart',
191-
resetMenu: MenuId.EditorTitle
191+
resetMenu: MenuId.EditorTitle,
192+
maxNumberOfItems: 9
192193
}));
193194

194195
// Context
@@ -270,7 +271,6 @@ export abstract class TitleControl extends Themable {
270271
{ arg: this.resourceContext.get(), shouldForwardArgs: true },
271272
{ primary, secondary },
272273
'navigation',
273-
9,
274274
shouldInlineGroup
275275
);
276276
}

0 commit comments

Comments
 (0)