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

use ctxt menu event for all actBar context menus #165177

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions src/vs/workbench/browser/parts/activitybar/activitybarActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import 'vs/css!./media/activityaction';
import { localize } from 'vs/nls';
import { EventType, addDisposableListener, EventHelper, getDomNodePagePosition } from 'vs/base/browser/dom';
import { EventType, addDisposableListener, EventHelper } 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 @@ -38,6 +38,7 @@ import { ViewContainerLocation } from 'vs/workbench/common/views';
import { IPaneCompositePart } from 'vs/workbench/browser/parts/paneCompositePart';
import { ICredentialsService } from 'vs/platform/credentials/common/credentials';
import { IUserDataProfileService, ManageProfilesSubMenu, PROFILES_CATEGORY } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';

export class ViewContainerActivityAction extends ActivityAction {

Expand Down Expand Up @@ -131,33 +132,33 @@ abstract class AbstractGlobalActivityActionViewItem extends ActivityActionViewIt
override render(container: HTMLElement): void {
super.render(container);

// Context menus are triggered on mouse down so that an item can be picked
// and executed with releasing the mouse over it

this._register(addDisposableListener(this.container, EventType.MOUSE_DOWN, async (e: MouseEvent) => {
EventHelper.stop(e, true);
const isLeftClick = e?.button !== 2;
// Left-click run
if (isLeftClick) {
this.run();
} else {
const disposables = new DisposableStore();
const actions = await this.resolveContextMenuActions(disposables);

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()
});
}
}));

// The rest of the activity bar uses context menu event for the context menu, so we match this
this._register(addDisposableListener(this.container, EventType.CONTEXT_MENU, async (e: MouseEvent) => {
const disposables = new DisposableStore();
const actions = await this.resolveContextMenuActions(disposables);

const event = new StandardMouseEvent(e);
const anchor = {
x: event.posx,
y: event.posy
};

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

this._register(addDisposableListener(this.container, EventType.KEY_UP, (e: KeyboardEvent) => {
const event = new StandardKeyboardEvent(e);
if (event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {
Expand Down