Skip to content

Commit 5e1f457

Browse files
authored
SCM - 💄 cleanup graph submenu/menu code (#237745)
1 parent d6fd2c0 commit 5e1f457

File tree

1 file changed

+42
-37
lines changed

1 file changed

+42
-37
lines changed

‎src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,54 +1586,59 @@ export class SCMHistoryViewPane extends ViewPane {
15861586
// If there are any history item references we have to add a submenu item for each orignal action,
15871587
// and a menu item for each history item ref that matches the `when` clause of the original action.
15881588
if (historyItemRefMenuItems.length > 0 && element.historyItemViewModel.historyItem.references?.length) {
1589-
const submenuIds = new Map<string, MenuId>();
1589+
const historyItemRefActions = new Map<string, ISCMHistoryItemRef[]>();
15901590

15911591
for (const ref of element.historyItemViewModel.historyItem.references) {
15921592
const contextKeyService = this.scopedContextKeyService.createOverlay([
15931593
['scmHistoryItemRef', ref.id]
15941594
]);
15951595

1596-
for (const [, actions] of this._menuService.getMenuActions(MenuId.SCMHistoryItemRefContext, contextKeyService)) {
1597-
for (const action of actions) {
1598-
let subMenuId = submenuIds.get(action.id);
1596+
const menuActions = this._menuService.getMenuActions(
1597+
MenuId.SCMHistoryItemRefContext, contextKeyService);
15991598

1600-
if (!subMenuId) {
1601-
subMenuId = MenuId.for(action.id);
1599+
for (const action of menuActions.flatMap(a => a[1])) {
1600+
if (!historyItemRefActions.has(action.id)) {
1601+
historyItemRefActions.set(action.id, []);
1602+
}
16021603

1603-
// Get the menu item for the original action so that
1604-
// we can create a submenu with the same group, order
1605-
const historyItemRefMenuItem = historyItemRefMenuItems
1606-
.find(item => item.command.id === action.id);
1604+
historyItemRefActions.get(action.id)!.push(ref);
1605+
}
1606+
}
16071607

1608-
// Register the submenu for the original action
1609-
this._contextMenuDisposables.value.add(MenuRegistry.appendMenuItem(MenuId.SCMChangesContext, {
1610-
title: action.label,
1611-
submenu: subMenuId,
1612-
group: historyItemRefMenuItem?.group,
1613-
order: historyItemRefMenuItem?.order
1614-
}));
1608+
// Register submenu, menu items
1609+
for (const historyItemRefMenuItem of historyItemRefMenuItems) {
1610+
const actionId = historyItemRefMenuItem.command.id;
16151611

1616-
submenuIds.set(action.id, subMenuId);
1617-
}
1612+
if (!historyItemRefActions.has(actionId)) {
1613+
continue;
1614+
}
16181615

1619-
// Register a new action for the history item ref
1620-
this._contextMenuDisposables.value.add(registerAction2(class extends Action2 {
1621-
constructor() {
1622-
super({
1623-
id: `${action.id}.${ref.id}`,
1624-
title: ref.name,
1625-
menu: {
1626-
id: subMenuId!,
1627-
group: ref.category
1628-
}
1629-
});
1630-
}
1631-
override run(accessor: ServicesAccessor, ...args: any[]): void {
1632-
const commandService = accessor.get(ICommandService);
1633-
commandService.executeCommand(action.id, ...args, ref.id);
1634-
}
1635-
}));
1636-
}
1616+
// Register the submenu for the original action
1617+
this._contextMenuDisposables.value.add(MenuRegistry.appendMenuItem(MenuId.SCMChangesContext, {
1618+
title: historyItemRefMenuItem.command.title,
1619+
submenu: MenuId.for(actionId),
1620+
group: historyItemRefMenuItem?.group,
1621+
order: historyItemRefMenuItem?.order
1622+
}));
1623+
1624+
// Register the action for the history item ref
1625+
for (const historyItemRef of historyItemRefActions.get(actionId) ?? []) {
1626+
this._contextMenuDisposables.value.add(registerAction2(class extends Action2 {
1627+
constructor() {
1628+
super({
1629+
id: `${actionId}.${historyItemRef.id}`,
1630+
title: historyItemRef.name,
1631+
menu: {
1632+
id: MenuId.for(actionId),
1633+
group: historyItemRef.category
1634+
}
1635+
});
1636+
}
1637+
override run(accessor: ServicesAccessor, ...args: any[]): void {
1638+
const commandService = accessor.get(ICommandService);
1639+
commandService.executeCommand(actionId, ...args, historyItemRef.id);
1640+
}
1641+
}));
16371642
}
16381643
}
16391644
}

0 commit comments

Comments
 (0)