Skip to content

Commit 597b59a

Browse files
authored
menus - show context menu in global activity like in views (microsoft#158172)
1 parent 6504980 commit 597b59a

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

src/vs/workbench/browser/parts/activitybar/activitybarActions.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import 'vs/css!./media/activityaction';
77
import { localize } from 'vs/nls';
8-
import { EventType, addDisposableListener, EventHelper } from 'vs/base/browser/dom';
8+
import { EventType, addDisposableListener, EventHelper, getDomNodePagePosition } from 'vs/base/browser/dom';
99
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
1010
import { EventType as TouchEventType, GestureEvent } from 'vs/base/browser/touch';
1111
import { Action, IAction, Separator, SubmenuAction, toAction } from 'vs/base/common/actions';
@@ -157,23 +157,38 @@ class MenuActivityActionViewItem extends ActivityActionViewItem {
157157
private async showContextMenu(e?: MouseEvent): Promise<void> {
158158
const disposables = new DisposableStore();
159159

160-
let actions: IAction[];
161-
if (e?.button !== 2) {
160+
const isLeftClick = e?.button !== 2;
161+
162+
// Left-click main menu
163+
if (isLeftClick) {
162164
const menu = disposables.add(this.menuService.createMenu(this.menuId, this.contextKeyService));
163-
actions = await this.resolveMainMenuActions(menu, disposables);
164-
} else {
165-
actions = await this.resolveContextMenuActions(disposables);
165+
const actions = await this.resolveMainMenuActions(menu, disposables);
166+
167+
this.contextMenuService.showContextMenu({
168+
getAnchor: () => this.container,
169+
anchorAlignment: this.configurationService.getValue('workbench.sideBar.location') === 'left' ? AnchorAlignment.RIGHT : AnchorAlignment.LEFT,
170+
anchorAxisAlignment: AnchorAxisAlignment.HORIZONTAL,
171+
getActions: () => actions,
172+
onHide: () => disposables.dispose()
173+
});
166174
}
167175

168-
const position = this.configurationService.getValue('workbench.sideBar.location');
176+
// Right-click context menu
177+
else {
178+
const actions = await this.resolveContextMenuActions(disposables);
169179

170-
this.contextMenuService.showContextMenu({
171-
getAnchor: () => this.container,
172-
anchorAlignment: position === 'left' ? AnchorAlignment.RIGHT : AnchorAlignment.LEFT,
173-
anchorAxisAlignment: AnchorAxisAlignment.HORIZONTAL,
174-
getActions: () => actions,
175-
onHide: () => disposables.dispose()
176-
});
180+
const elementPosition = getDomNodePagePosition(this.container);
181+
const anchor = {
182+
x: Math.floor(elementPosition.left + (elementPosition.width / 2)),
183+
y: elementPosition.top + elementPosition.height
184+
};
185+
186+
this.contextMenuService.showContextMenu({
187+
getAnchor: () => anchor,
188+
getActions: () => actions,
189+
onHide: () => disposables.dispose()
190+
});
191+
}
177192
}
178193

179194
protected async resolveMainMenuActions(menu: IMenu, disposables: DisposableStore): Promise<IAction[]> {

0 commit comments

Comments
 (0)