Skip to content

Commit 61f44f9

Browse files
authored
give menuIds to setActions, adopt for composite panes (microsoft#162317)
fixes microsoft#162003 (comment)
1 parent b784e05 commit 61f44f9

File tree

6 files changed

+40
-13
lines changed

6 files changed

+40
-13
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class WorkbenchToolBar extends ToolBar {
9696
}
9797
}
9898

99-
override setActions(_primary: readonly IAction[], _secondary: readonly IAction[] = []): void {
99+
override setActions(_primary: readonly IAction[], _secondary: readonly IAction[] = [], menuIds?: readonly MenuId[]): void {
100100

101101
this._sessionDisposables.clear();
102102
const primary = _primary.slice();
@@ -170,12 +170,15 @@ export class WorkbenchToolBar extends ToolBar {
170170
actions = [hideAction, new Separator(), ...toggleActions];
171171

172172
// add "Reset Menu" action
173-
if (someAreHidden && this._options?.resetMenu) {
173+
if (this._options?.resetMenu && !menuIds) {
174+
menuIds = [this._options.resetMenu];
175+
}
176+
if (someAreHidden && menuIds) {
174177
actions.push(new Separator());
175178
actions.push(toAction({
176179
id: 'resetThisMenu',
177180
label: localize('resetThisMenu', "Reset Menu"),
178-
run: () => this._menuService.resetHiddenStates(this._options!.resetMenu)
181+
run: () => this._menuService.resetHiddenStates(menuIds)
179182
}));
180183
}
181184

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export interface IMenuService {
238238
/**
239239
* Reset the menu's hidden states.
240240
*/
241-
resetHiddenStates(menuId: MenuId | undefined): void;
241+
resetHiddenStates(menuIds: readonly MenuId[] | undefined): void;
242242
}
243243

244244
export type ICommandsMap = Map<string, ICommandAction>;

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export class MenuService implements IMenuService {
3232
return new MenuImpl(id, this._hiddenStates, { emitEventsForSubmenuChanges: false, eventDebounceDelay: 50, ...options }, this._commandService, contextKeyService);
3333
}
3434

35-
resetHiddenStates(id?: MenuId): void {
36-
this._hiddenStates.reset(id);
35+
resetHiddenStates(ids?: MenuId[]): void {
36+
this._hiddenStates.reset(ids);
3737
}
3838
}
3939

@@ -108,17 +108,19 @@ class PersistedMenuHideState {
108108
this._persist();
109109
}
110110

111-
reset(menu?: MenuId): void {
112-
if (menu === undefined) {
111+
reset(menus?: MenuId[]): void {
112+
if (menus === undefined) {
113113
// reset all
114114
this._data = Object.create(null);
115115
this._persist();
116116
} else {
117117
// reset only for a specific menu
118-
if (this._data[menu.id]) {
119-
delete this._data[menu.id];
120-
this._persist();
118+
for (const { id } of menus) {
119+
if (this._data[id]) {
120+
delete this._data[id];
121+
}
121122
}
123+
this._persist();
122124
}
123125
}
124126

src/vs/workbench/browser/composite.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
1515
import { Disposable } from 'vs/base/common/lifecycle';
1616
import { assertIsDefined } from 'vs/base/common/types';
1717
import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
18+
import { MenuId } from 'vs/platform/actions/common/actions';
1819

1920
/**
2021
* Composites are layed out in the sidebar and panel part of the workbench. At a time only one composite
@@ -161,6 +162,15 @@ export abstract class Composite extends Component implements IComposite {
161162
super.updateStyles();
162163
}
163164

165+
166+
/**
167+
*
168+
* @returns the action runner for this composite
169+
*/
170+
getMenuIds(): readonly MenuId[] {
171+
return [];
172+
}
173+
164174
/**
165175
* Returns an array of actions to show in the action bar of the composite.
166176
*/

src/vs/workbench/browser/panecomposite.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { URI } from 'vs/base/common/uri';
1010
import { Dimension } from 'vs/base/browser/dom';
1111
import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
1212
import { IAction, Separator } from 'vs/base/common/actions';
13-
import { SubmenuItemAction } from 'vs/platform/actions/common/actions';
13+
import { MenuId, SubmenuItemAction } from 'vs/platform/actions/common/actions';
1414
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1515
import { IStorageService } from 'vs/platform/storage/common/storage';
1616
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
@@ -73,6 +73,17 @@ export abstract class PaneComposite extends Composite implements IPaneComposite
7373
return this.viewPaneContainer?.menuActions?.getContextMenuActions() ?? [];
7474
}
7575

76+
override getMenuIds(): MenuId[] {
77+
const result: MenuId[] = [];
78+
if (this.viewPaneContainer?.menuActions) {
79+
result.push(this.viewPaneContainer.menuActions.menuId);
80+
if (this.viewPaneContainer.isViewMergedWithContainer()) {
81+
result.push(this.viewPaneContainer.panes[0].menuActions.menuId);
82+
}
83+
}
84+
return result;
85+
}
86+
7687
override getActions(): readonly IAction[] {
7788
const result = [];
7889
if (this.viewPaneContainer?.menuActions) {

src/vs/workbench/browser/parts/compositePart.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ export abstract class CompositePart<T extends Composite> extends Part {
329329
private collectCompositeActions(composite?: Composite): () => void {
330330

331331
// From Composite
332+
const menuIds = composite?.getMenuIds();
332333
const primaryActions: IAction[] = composite?.getActions().slice(0) || [];
333334
const secondaryActions: IAction[] = composite?.getSecondaryActions().slice(0) || [];
334335

@@ -337,7 +338,7 @@ export abstract class CompositePart<T extends Composite> extends Part {
337338
toolBar.context = this.actionsContextProvider();
338339

339340
// Return fn to set into toolbar
340-
return () => toolBar.setActions(prepareActions(primaryActions), prepareActions(secondaryActions));
341+
return () => toolBar.setActions(prepareActions(primaryActions), prepareActions(secondaryActions), menuIds);
341342
}
342343

343344
protected getActiveComposite(): IComposite | undefined {

0 commit comments

Comments
 (0)