Skip to content

Commit f3dcaf1

Browse files
authored
Merge branch 'main' into tyriar/update_cursor_still__suggest__2
2 parents 1bf95e6 + 7b1acd9 commit f3dcaf1

File tree

1 file changed

+54
-25
lines changed

1 file changed

+54
-25
lines changed

src/vs/workbench/browser/parts/views/treeView.ts

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import 'vs/css!./media/views';
3333
import { VSDataTransfer } from 'vs/base/common/dataTransfer';
3434
import { localize } from 'vs/nls';
3535
import { createActionViewItem, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
36-
import { Action2, IMenu, IMenuService, MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions';
36+
import { Action2, IMenuService, MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions';
3737
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
3838
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
3939
import { ContextKeyExpr, IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
@@ -800,7 +800,9 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
800800
event.stopPropagation();
801801

802802
this.tree!.setFocus([node]);
803-
const actions = treeMenus.getResourceContextActions(node);
803+
const selected = this.canSelectMany ? this.getSelection() : [];
804+
selected.unshift(node);
805+
const actions = treeMenus.getResourceContextActions(selected);
804806
if (!actions.length) {
805807
return;
806808
}
@@ -1311,7 +1313,7 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS
13111313

13121314
templateData.actionBar.context = <TreeViewItemHandleArg>{ $treeViewId: this.treeViewId, $treeItemHandle: node.handle };
13131315

1314-
const menuActions = this.menus.getResourceActions(node, templateData.elementDisposable);
1316+
const menuActions = this.menus.getResourceActions([node], templateData.elementDisposable);
13151317
templateData.actionBar.push(menuActions.actions, { icon: true, label: false });
13161318

13171319
if (this._actionRunner) {
@@ -1581,41 +1583,68 @@ class TreeMenus implements IDisposable {
15811583
@IMenuService private readonly menuService: IMenuService
15821584
) { }
15831585

1584-
getResourceActions(element: ITreeItem, disposableStore: DisposableStore): { menu?: IMenu; actions: IAction[] } {
1585-
const actions = this.getActions(MenuId.ViewItemContext, element, disposableStore);
1586-
return { menu: actions.menu, actions: actions.primary };
1586+
getResourceActions(elements: ITreeItem[], disposableStore: DisposableStore): { actions: IAction[] } {
1587+
const actions = this.getActions(MenuId.ViewItemContext, elements, disposableStore);
1588+
return { actions: actions.primary };
15871589
}
15881590

1589-
getResourceContextActions(element: ITreeItem): IAction[] {
1590-
return this.getActions(MenuId.ViewItemContext, element).secondary;
1591+
getResourceContextActions(elements: ITreeItem[]): IAction[] {
1592+
return this.getActions(MenuId.ViewItemContext, elements).secondary;
15911593
}
15921594

15931595
public setContextKeyService(service: IContextKeyService) {
15941596
this.contextKeyService = service;
15951597
}
15961598

1597-
private getActions(menuId: MenuId, element: ITreeItem, listen?: DisposableStore): { menu?: IMenu; primary: IAction[]; secondary: IAction[] } {
1599+
private getActions(menuId: MenuId, elements: ITreeItem[], listen?: DisposableStore): { primary: IAction[]; secondary: IAction[] } {
15981600
if (!this.contextKeyService) {
15991601
return { primary: [], secondary: [] };
16001602
}
16011603

1602-
const contextKeyService = this.contextKeyService.createOverlay([
1603-
['view', this.id],
1604-
['viewItem', element.contextValue]
1605-
]);
1606-
1607-
const menu = this.menuService.createMenu(menuId, contextKeyService);
1608-
const primary: IAction[] = [];
1609-
const secondary: IAction[] = [];
1610-
const result = { primary, secondary, menu };
1611-
createAndFillInContextMenuActions(menu, { shouldForwardArgs: true }, result, 'inline');
1612-
if (listen) {
1613-
listen.add(menu.onDidChange(() => this._onDidChange.fire(element)));
1614-
listen.add(menu);
1615-
} else {
1616-
menu.dispose();
1604+
const allowedPrimary = new Map<string, IAction>();
1605+
const allowedSecondary = new Map<string, IAction>();
1606+
for (let i = 0; i < elements.length; i++) {
1607+
const element = elements[i];
1608+
const contextKeyService = this.contextKeyService.createOverlay([
1609+
['view', this.id],
1610+
['viewItem', element.contextValue]
1611+
]);
1612+
1613+
const menu = this.menuService.createMenu(menuId, contextKeyService);
1614+
const primary: IAction[] = [];
1615+
const secondary: IAction[] = [];
1616+
const result = { primary, secondary, menu };
1617+
createAndFillInContextMenuActions(menu, { shouldForwardArgs: true }, result, 'inline');
1618+
if (i === 0) {
1619+
for (const action of result.primary) {
1620+
allowedPrimary.set(action.id, action);
1621+
}
1622+
for (const action of result.secondary) {
1623+
allowedSecondary.set(action.id, action);
1624+
}
1625+
} else {
1626+
const primaryKeys = allowedPrimary.keys();
1627+
for (const key of primaryKeys) {
1628+
if (!result.primary.some(action => action.id === key)) {
1629+
allowedPrimary.delete(key);
1630+
}
1631+
}
1632+
const secondaryKeys = allowedSecondary.keys();
1633+
for (const key of secondaryKeys) {
1634+
if (!result.secondary.some(action => action.id === key)) {
1635+
allowedSecondary.delete(key);
1636+
}
1637+
}
1638+
}
1639+
if (listen && elements.length === 1) {
1640+
listen.add(menu.onDidChange(() => this._onDidChange.fire(element)));
1641+
listen.add(menu);
1642+
} else {
1643+
menu.dispose();
1644+
}
16171645
}
1618-
return result;
1646+
1647+
return { primary: Array.from(allowedPrimary.values()), secondary: Array.from(allowedSecondary.values()) };
16191648
}
16201649

16211650
dispose() {

0 commit comments

Comments
 (0)