Skip to content

Commit

Permalink
touch events: context menu support across workbench
Browse files Browse the repository at this point in the history
fixes #120956
  • Loading branch information
isidorn committed Jun 9, 2021
1 parent b5d6d7e commit a12af58
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/vs/workbench/browser/parts/compositeBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ViewContainerLocation, IViewDescriptorService } from 'vs/workbench/comm
import { IPaneComposite } from 'vs/workbench/common/panecomposite';
import { IComposite } from 'vs/workbench/common/composite';
import { CompositeDragAndDropData, CompositeDragAndDropObserver, IDraggedCompositeData, ICompositeDragAndDrop, Before2D, toggleDropEffect } from 'vs/workbench/browser/dnd';
import { Gesture, EventType as TouchEventType, GestureEvent } from 'vs/base/browser/touch';

export interface ICompositeBarItem {
id: string;
Expand Down Expand Up @@ -233,6 +234,8 @@ export class CompositeBar extends Widget implements ICompositeBar {

// Contextmenu for composites
this._register(addDisposableListener(parent, EventType.CONTEXT_MENU, e => this.showContextMenu(e)));
this._register(Gesture.addTarget(parent));
this._register(addDisposableListener(parent, TouchEventType.Contextmenu, e => this.showContextMenu(e)));

let insertDropBefore: Before2D | undefined = undefined;
// Register a drop target on the whole bar to prevent forbidden feedback
Expand Down Expand Up @@ -619,7 +622,7 @@ export class CompositeBar extends Widget implements ICompositeBar {
return this.model.visibleItems.filter(c => overflowingIds.includes(c.id)).map(item => { return { id: item.id, name: this.getAction(item.id)?.label || item.name }; });
}

private showContextMenu(e: MouseEvent): void {
private showContextMenu(e: MouseEvent | GestureEvent): void {
EventHelper.stop(e, true);
const event = new StandardMouseEvent(e);
this.contextMenuService.showContextMenu({
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/browser/parts/sidebar/sidebarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { CompositeDragAndDropObserver } from 'vs/workbench/browser/dnd';
import { IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/common/views';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { CATEGORIES } from 'vs/workbench/common/actions';
import { Gesture, EventType as GestureEventType } from 'vs/base/browser/touch';

export class SidebarPart extends CompositePart<Viewlet> implements IViewletService {

Expand Down Expand Up @@ -171,6 +172,10 @@ export class SidebarPart extends CompositePart<Viewlet> implements IViewletServi
this._register(addDisposableListener(titleArea, EventType.CONTEXT_MENU, e => {
this.onTitleAreaContextMenu(new StandardMouseEvent(e));
}));
this._register(Gesture.addTarget(titleArea));
this._register(addDisposableListener(titleArea, GestureEventType.Contextmenu, e => {
this.onTitleAreaContextMenu(new StandardMouseEvent(e));
}));

this.titleLabelElement!.draggable = true;

Expand Down
5 changes: 4 additions & 1 deletion src/vs/workbench/browser/parts/statusbar/statusbarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { dispose, IDisposable, Disposable, toDisposable, MutableDisposable } fro
import { SimpleIconLabel } from 'vs/base/browser/ui/iconLabel/simpleIconLabel';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { Part } from 'vs/workbench/browser/part';
import { EventType as TouchEventType, Gesture, GestureEvent } from 'vs/base/browser/touch';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { StatusbarAlignment, IStatusbarService, IStatusbarEntry, IStatusbarEntryAccessor } from 'vs/workbench/services/statusbar/common/statusbar';
Expand Down Expand Up @@ -586,6 +587,8 @@ export class StatusbarPart extends Part implements IStatusbarService {

// Context menu support
this._register(addDisposableListener(parent, EventType.CONTEXT_MENU, e => this.showContextMenu(e)));
this._register(Gesture.addTarget(parent));
this._register(addDisposableListener(parent, TouchEventType.Contextmenu, e => this.showContextMenu(e)));

// Initial status bar entries
this.createInitialStatusbarEntries();
Expand Down Expand Up @@ -660,7 +663,7 @@ export class StatusbarPart extends Part implements IStatusbarService {
}
}

private showContextMenu(e: MouseEvent): void {
private showContextMenu(e: MouseEvent | GestureEvent): void {
EventHelper.stop(e, true);

const event = new StandardMouseEvent(e);
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/browser/parts/views/viewPaneContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ViewPane } from 'vs/workbench/browser/parts/views/viewPane';
import { CompositeMenuActions } from 'vs/workbench/browser/actions';
import { createActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
import { Gesture, EventType as TouchEventType } from 'vs/base/browser/touch';

export const ViewsSubMenu = new MenuId('Views');
MenuRegistry.appendMenuItem(MenuId.ViewContainerTitle, <ISubmenuItem>{
Expand Down Expand Up @@ -409,6 +410,8 @@ export class ViewPaneContainer extends Component implements IViewPaneContainer {
this._register(this.paneview.onDidDrop(({ from, to }) => this.movePane(from as ViewPane, to as ViewPane)));
this._register(this.paneview.onDidScroll(_ => this.onDidScrollPane()));
this._register(addDisposableListener(parent, EventType.CONTEXT_MENU, (e: MouseEvent) => this.showContextMenu(new StandardMouseEvent(e))));
this._register(Gesture.addTarget(parent));
this._register(addDisposableListener(parent, TouchEventType.Contextmenu, (e: MouseEvent) => this.showContextMenu(new StandardMouseEvent(e))));

this._menuActions = this._register(this.instantiationService.createInstance(ViewContainerMenuActions, this.paneview.element, this.viewContainer));
this._register(this._menuActions.onDidChange(() => this.updateTitleArea()));
Expand Down

0 comments on commit a12af58

Please sign in to comment.