Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

menus - show context menu in global activity like in views #158172

Merged
merged 1 commit into from Aug 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 29 additions & 14 deletions src/vs/workbench/browser/parts/activitybar/activitybarActions.ts
Expand Up @@ -5,7 +5,7 @@

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

let actions: IAction[];
if (e?.button !== 2) {
const isLeftClick = e?.button !== 2;

// Left-click main menu
if (isLeftClick) {
const menu = disposables.add(this.menuService.createMenu(this.menuId, this.contextKeyService));
actions = await this.resolveMainMenuActions(menu, disposables);
} else {
actions = await this.resolveContextMenuActions(disposables);
const actions = await this.resolveMainMenuActions(menu, disposables);

this.contextMenuService.showContextMenu({
getAnchor: () => this.container,
anchorAlignment: this.configurationService.getValue('workbench.sideBar.location') === 'left' ? AnchorAlignment.RIGHT : AnchorAlignment.LEFT,
anchorAxisAlignment: AnchorAxisAlignment.HORIZONTAL,
getActions: () => actions,
onHide: () => disposables.dispose()
});
}

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

this.contextMenuService.showContextMenu({
getAnchor: () => this.container,
anchorAlignment: position === 'left' ? AnchorAlignment.RIGHT : AnchorAlignment.LEFT,
anchorAxisAlignment: AnchorAxisAlignment.HORIZONTAL,
getActions: () => actions,
onHide: () => disposables.dispose()
});
const elementPosition = getDomNodePagePosition(this.container);
const anchor = {
x: Math.floor(elementPosition.left + (elementPosition.width / 2)),
y: elementPosition.top + elementPosition.height
};

this.contextMenuService.showContextMenu({
getAnchor: () => anchor,
getActions: () => actions,
onHide: () => disposables.dispose()
});
}
}

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