Merge from vscode 011858832762aaff245b2336fb1c38166e7a10fb (#4663)

This commit is contained in:
Anthony Dresser
2019-03-22 13:07:54 -07:00
committed by GitHub
parent f5c9174c2f
commit 4a87a24235
296 changed files with 2531 additions and 2472 deletions

View File

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

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ContextMenuHandler } from './contextMenuHandler';
import { ContextMenuHandler, IContextMenuHandlerOptions } from './contextMenuHandler';
import { IContextViewService, IContextMenuService } from './contextView';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { Event, Emitter } from 'vs/base/common/event';
@@ -12,7 +12,6 @@ import { IContextMenuDelegate } from 'vs/base/browser/contextmenu';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { Disposable } from 'vs/base/common/lifecycle';
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
export class ContextMenuService extends Disposable implements IContextMenuService {
_serviceBrand: any;
@@ -23,7 +22,6 @@ export class ContextMenuService extends Disposable implements IContextMenuServic
private contextMenuHandler: ContextMenuHandler;
constructor(
@ILayoutService layoutService: ILayoutService,
@ITelemetryService telemetryService: ITelemetryService,
@INotificationService notificationService: INotificationService,
@IContextViewService contextViewService: IContextViewService,
@@ -32,15 +30,11 @@ export class ContextMenuService extends Disposable implements IContextMenuServic
) {
super();
this.contextMenuHandler = this._register(new ContextMenuHandler(layoutService, contextViewService, telemetryService, notificationService, keybindingService, themeService));
this.contextMenuHandler = new ContextMenuHandler(contextViewService, telemetryService, notificationService, keybindingService, themeService);
}
dispose(): void {
this.contextMenuHandler.dispose();
}
setContainer(container: HTMLElement): void {
this.contextMenuHandler.setContainer(container);
configure(options: IContextMenuHandlerOptions): void {
this.contextMenuHandler.configure(options);
}
// ContextMenu