mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-10 02:02:35 -05:00
Merge from vscode 011858832762aaff245b2336fb1c38166e7a10fb (#4663)
This commit is contained in:
@@ -5,50 +5,38 @@
|
||||
|
||||
import 'vs/css!./contextMenuHandler';
|
||||
|
||||
import { combinedDisposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
|
||||
import { combinedDisposable, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ActionRunner, IRunEvent } from 'vs/base/common/actions';
|
||||
import { Menu } from 'vs/base/browser/ui/menu/menu';
|
||||
|
||||
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { IContextMenuDelegate } from 'vs/base/browser/contextmenu';
|
||||
import { addDisposableListener, EventType, $, removeNode } from 'vs/base/browser/dom';
|
||||
import { EventType, $, removeNode } from 'vs/base/browser/dom';
|
||||
import { attachMenuStyler } from 'vs/platform/theme/common/styler';
|
||||
import { domEvent } from 'vs/base/browser/event';
|
||||
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
|
||||
|
||||
export interface IContextMenuHandlerOptions {
|
||||
blockMouse: boolean;
|
||||
}
|
||||
|
||||
export class ContextMenuHandler {
|
||||
private element: HTMLElement | null;
|
||||
private elementDisposable: IDisposable;
|
||||
private menuContainerElement: HTMLElement | null;
|
||||
private focusToReturn: HTMLElement;
|
||||
private block: HTMLElement | null;
|
||||
private options: IContextMenuHandlerOptions = { blockMouse: true };
|
||||
|
||||
constructor(
|
||||
private layoutService: ILayoutService,
|
||||
private contextViewService: IContextViewService,
|
||||
private telemetryService: ITelemetryService,
|
||||
private notificationService: INotificationService,
|
||||
private keybindingService: IKeybindingService,
|
||||
private themeService: IThemeService
|
||||
) {
|
||||
this.setContainer(this.layoutService.container);
|
||||
}
|
||||
) { }
|
||||
|
||||
setContainer(container: HTMLElement | null): void {
|
||||
if (this.element) {
|
||||
this.elementDisposable = dispose(this.elementDisposable);
|
||||
this.element = null;
|
||||
}
|
||||
|
||||
if (container) {
|
||||
this.element = container;
|
||||
this.elementDisposable = addDisposableListener(this.element, EventType.MOUSE_DOWN, (e) => this.onMouseDown(e as MouseEvent));
|
||||
}
|
||||
configure(options: IContextMenuHandlerOptions): void {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
showContextMenu(delegate: IContextMenuDelegate): void {
|
||||
@@ -67,8 +55,6 @@ export class ContextMenuHandler {
|
||||
anchorAlignment: delegate.anchorAlignment,
|
||||
|
||||
render: (container) => {
|
||||
this.menuContainerElement = container;
|
||||
|
||||
let className = delegate.getMenuClassName ? delegate.getMenuClassName() : '';
|
||||
|
||||
if (className) {
|
||||
@@ -76,7 +62,7 @@ export class ContextMenuHandler {
|
||||
}
|
||||
|
||||
// Render invisible div to block mouse interaction in the rest of the UI
|
||||
if (this.layoutService.hasWorkbench) {
|
||||
if (this.options.blockMouse) {
|
||||
this.block = container.appendChild($('.context-view-block'));
|
||||
}
|
||||
|
||||
@@ -120,8 +106,6 @@ export class ContextMenuHandler {
|
||||
if (this.focusToReturn) {
|
||||
this.focusToReturn.focus();
|
||||
}
|
||||
|
||||
this.menuContainerElement = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -150,27 +134,4 @@ export class ContextMenuHandler {
|
||||
this.notificationService.error(e.error);
|
||||
}
|
||||
}
|
||||
|
||||
private onMouseDown(e: MouseEvent): void {
|
||||
if (!this.menuContainerElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
let event = new StandardMouseEvent(e);
|
||||
let element: HTMLElement | null = event.target;
|
||||
|
||||
while (element) {
|
||||
if (element === this.menuContainerElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
element = element.parentElement;
|
||||
}
|
||||
|
||||
this.contextViewService.hideContextView();
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.setContainer(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user