Merge pull request #193767 from microsoft/joh/disgusted-dolphin

WorkbenchToolBar allows to configure exemption from overflow logic
This commit is contained in:
Johannes Rieken
2023-09-22 10:12:03 +02:00
committed by GitHub
2 changed files with 16 additions and 5 deletions

View File

@@ -63,9 +63,11 @@ export type IWorkbenchToolBarOptions = IToolBarOptions & {
allowContextMenu?: never; allowContextMenu?: never;
/** /**
* Maximun number of items that can shown. Extra items will be shown in the overflow menu. * Controls the overflow behavior of the primary group of toolbar. This isthe maximum number of items and id of
* items that should never overflow
*
*/ */
maxNumberOfItems?: number; overflowBehavior?: { maxItems: number; exempted?: string[] };
}; };
/** /**
@@ -150,14 +152,22 @@ export class WorkbenchToolBar extends ToolBar {
} }
// count for max // count for max
if (this._options?.maxNumberOfItems !== undefined) { if (this._options?.overflowBehavior !== undefined) {
const exempted = new Set(this._options.overflowBehavior.exempted);
const maxItems = this._options.overflowBehavior.maxItems - exempted.size;
let count = 0; let count = 0;
for (let i = 0; i < primary.length; i++) { for (let i = 0; i < primary.length; i++) {
const action = primary[i]; const action = primary[i];
if (!action) { if (!action) {
continue; continue;
} }
if (++count >= this._options.maxNumberOfItems) { count++;
if (exempted.has(action.id)) {
continue;
}
if (count >= maxItems) {
primary[i] = undefined!; primary[i] = undefined!;
extraSecondary[i] = action; extraSecondary[i] = action;
} }

View File

@@ -39,6 +39,7 @@ import { DraggedTreeItemsIdentifier } from 'vs/editor/common/services/treeViewsD
import { IEditorResolverService } from 'vs/workbench/services/editor/common/editorResolverService'; import { IEditorResolverService } from 'vs/workbench/services/editor/common/editorResolverService';
import { IEditorTitleControlDimensions } from 'vs/workbench/browser/parts/editor/editorTitleControl'; import { IEditorTitleControlDimensions } from 'vs/workbench/browser/parts/editor/editorTitleControl';
import { IReadonlyEditorGroupModel } from 'vs/workbench/common/editor/editorGroupModel'; import { IReadonlyEditorGroupModel } from 'vs/workbench/common/editor/editorGroupModel';
import { CLOSE_EDITOR_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
export interface IToolbarActions { export interface IToolbarActions {
readonly primary: IAction[]; readonly primary: IAction[];
@@ -173,7 +174,7 @@ export abstract class EditorTabsControl extends Themable implements IEditorTabsC
renderDropdownAsChildElement: this.renderDropdownAsChildElement, renderDropdownAsChildElement: this.renderDropdownAsChildElement,
telemetrySource: 'editorPart', telemetrySource: 'editorPart',
resetMenu: MenuId.EditorTitle, resetMenu: MenuId.EditorTitle,
maxNumberOfItems: 9, overflowBehavior: { maxItems: 9, exempted: [CLOSE_EDITOR_COMMAND_ID] },
highlightToggledItems: true, highlightToggledItems: true,
})); }));