Merge from master

This commit is contained in:
Raj Musuku
2019-02-21 17:56:04 -08:00
parent 5a146e34fa
commit 666ae11639
11482 changed files with 119352 additions and 255574 deletions

View File

@@ -3,98 +3,109 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'vs/css!./contextMenuHandler';
import { $, Builder } from 'vs/base/browser/builder';
import { combinedDisposable, IDisposable } from 'vs/base/common/lifecycle';
import { combinedDisposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { ActionRunner, IAction, IRunEvent } from 'vs/base/common/actions';
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 } from 'vs/base/browser/dom';
import { attachMenuStyler } from 'vs/platform/theme/common/styler';
import { domEvent } from 'vs/base/browser/event';
export class ContextMenuHandler {
private contextViewService: IContextViewService;
private notificationService: INotificationService;
private telemetryService: ITelemetryService;
private $el: Builder;
private element: HTMLElement;
private elementDisposable: IDisposable;
private menuContainerElement: HTMLElement;
private focusToReturn: HTMLElement;
constructor(element: HTMLElement, contextViewService: IContextViewService, telemetryService: ITelemetryService, notificationService: INotificationService) {
constructor(
element: HTMLElement,
private contextViewService: IContextViewService,
private telemetryService: ITelemetryService,
private notificationService: INotificationService,
private keybindingService: IKeybindingService,
private themeService: IThemeService
) {
this.setContainer(element);
this.contextViewService = contextViewService;
this.telemetryService = telemetryService;
this.notificationService = notificationService;
this.menuContainerElement = null;
}
public setContainer(container: HTMLElement): void {
if (this.$el) {
this.$el.off(['click', 'mousedown']);
this.$el = null;
setContainer(container: HTMLElement): void {
if (this.element) {
this.elementDisposable = dispose(this.elementDisposable);
this.element = null;
}
if (container) {
this.$el = $(container);
this.$el.on('mousedown', (e: Event) => this.onMouseDown(e as MouseEvent));
this.element = container;
this.elementDisposable = addDisposableListener(this.element, EventType.MOUSE_DOWN, (e) => this.onMouseDown(e as MouseEvent));
}
}
public showContextMenu(delegate: IContextMenuDelegate): void {
delegate.getActions().done((actions: IAction[]) => {
if (!actions.length) {
return; // Don't render an empty context menu
}
showContextMenu(delegate: IContextMenuDelegate): void {
const actions = delegate.getActions();
if (!actions.length) {
return; // Don't render an empty context menu
}
this.contextViewService.showContextView({
getAnchor: () => delegate.getAnchor(),
canRelayout: false,
this.focusToReturn = document.activeElement as HTMLElement;
render: (container) => {
this.menuContainerElement = container;
let menu: Menu | undefined;
let className = delegate.getMenuClassName ? delegate.getMenuClassName() : '';
this.contextViewService.showContextView({
getAnchor: () => delegate.getAnchor(),
canRelayout: false,
anchorAlignment: delegate.anchorAlignment,
if (className) {
container.className += ' ' + className;
}
render: (container) => {
this.menuContainerElement = container;
const menuDisposables: IDisposable[] = [];
let className = delegate.getMenuClassName ? delegate.getMenuClassName() : '';
const actionRunner = delegate.actionRunner || new ActionRunner();
actionRunner.onDidBeforeRun(this.onActionRun, this, menuDisposables);
actionRunner.onDidRun(this.onDidActionRun, this, menuDisposables);
const menu = new Menu(container, actions, {
actionItemProvider: delegate.getActionItem,
context: delegate.getActionsContext ? delegate.getActionsContext() : null,
actionRunner,
getKeyBinding: delegate.getKeyBinding
});
menu.onDidCancel(() => this.contextViewService.hideContextView(true), null, menuDisposables);
menu.onDidBlur(() => this.contextViewService.hideContextView(true), null, menuDisposables);
menu.focus(!!delegate.autoSelectFirstItem);
return combinedDisposable([...menuDisposables, menu]);
},
onHide: (didCancel?: boolean) => {
if (delegate.onHide) {
delegate.onHide(didCancel);
}
this.menuContainerElement = null;
if (className) {
container.className += ' ' + className;
}
});
const menuDisposables: IDisposable[] = [];
const actionRunner = delegate.actionRunner || new ActionRunner();
actionRunner.onDidBeforeRun(this.onActionRun, this, menuDisposables);
actionRunner.onDidRun(this.onDidActionRun, this, menuDisposables);
menu = new Menu(container, actions, {
actionItemProvider: delegate.getActionItem,
context: delegate.getActionsContext ? delegate.getActionsContext() : null,
actionRunner,
getKeyBinding: delegate.getKeyBinding ? delegate.getKeyBinding : action => this.keybindingService.lookupKeybinding(action.id)
});
menuDisposables.push(attachMenuStyler(menu, this.themeService));
menu.onDidCancel(() => this.contextViewService.hideContextView(true), null, menuDisposables);
menu.onDidBlur(() => this.contextViewService.hideContextView(true), null, menuDisposables);
domEvent(window, EventType.BLUR)(() => { this.contextViewService.hideContextView(true); }, null, menuDisposables);
return combinedDisposable([...menuDisposables, menu]);
},
focus: () => {
menu.focus(!!delegate.autoSelectFirstItem);
},
onHide: (didCancel?: boolean) => {
if (delegate.onHide) {
delegate.onHide(didCancel);
}
this.menuContainerElement = null;
}
});
}
@@ -110,6 +121,11 @@ export class ContextMenuHandler {
}
this.contextViewService.hideContextView(false);
// Restore focus here
if (this.focusToReturn) {
this.focusToReturn.focus();
}
}
private onDidActionRun(e: IRunEvent): void {
@@ -137,7 +153,7 @@ export class ContextMenuHandler {
this.contextViewService.hideContextView();
}
public dispose(): void {
dispose(): void {
this.setContainer(null);
}
}
}

View File

@@ -2,7 +2,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { ContextMenuHandler } from './contextMenuHandler';
import { IContextViewService, IContextMenuService } from './contextView';
@@ -10,34 +9,43 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { Event, Emitter } from 'vs/base/common/event';
import { INotificationService } from 'vs/platform/notification/common/notification';
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';
export class ContextMenuService extends Disposable implements IContextMenuService {
_serviceBrand: any;
export class ContextMenuService implements IContextMenuService {
public _serviceBrand: any;
private _onDidContextMenu = this._register(new Emitter<void>());
get onDidContextMenu(): Event<void> { return this._onDidContextMenu.event; }
private contextMenuHandler: ContextMenuHandler;
private _onDidContextMenu = new Emitter<void>();
constructor(container: HTMLElement, telemetryService: ITelemetryService, notificationService: INotificationService, contextViewService: IContextViewService) {
this.contextMenuHandler = new ContextMenuHandler(container, contextViewService, telemetryService, notificationService);
constructor(
container: HTMLElement,
@ITelemetryService telemetryService: ITelemetryService,
@INotificationService notificationService: INotificationService,
@IContextViewService contextViewService: IContextViewService,
@IKeybindingService keybindingService: IKeybindingService,
@IThemeService themeService: IThemeService
) {
super();
this.contextMenuHandler = this._register(new ContextMenuHandler(container, contextViewService, telemetryService, notificationService, keybindingService, themeService));
}
public dispose(): void {
dispose(): void {
this.contextMenuHandler.dispose();
}
public setContainer(container: HTMLElement): void {
setContainer(container: HTMLElement): void {
this.contextMenuHandler.setContainer(container);
}
// ContextMenu
public showContextMenu(delegate: IContextMenuDelegate): void {
showContextMenu(delegate: IContextMenuDelegate): void {
this.contextMenuHandler.showContextMenu(delegate);
this._onDidContextMenu.fire();
}
public get onDidContextMenu(): Event<void> {
return this._onDidContextMenu.event;
}
}

View File

@@ -2,35 +2,43 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IDisposable } from 'vs/base/common/lifecycle';
import { Event } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IContextMenuDelegate } from 'vs/base/browser/contextmenu';
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
export const IContextViewService = createDecorator<IContextViewService>('contextViewService');
export interface IContextViewService {
_serviceBrand: any;
showContextView(delegate: IContextViewDelegate): void;
hideContextView(data?: any): void;
layout(): void;
anchorAlignment?: AnchorAlignment;
}
export interface IContextViewDelegate {
getAnchor(): HTMLElement | { x: number; y: number; };
render(container: HTMLElement): IDisposable;
canRelayout?: boolean; // Default: true
getAnchor(): HTMLElement | { x: number; y: number; width?: number; height?: number; };
render(container: HTMLElement): IDisposable;
onDOMEvent?(e: any, activeElement: HTMLElement): void;
onHide?(data?: any): void;
focus?(): void;
anchorAlignment?: AnchorAlignment;
}
export const IContextMenuService = createDecorator<IContextMenuService>('contextMenuService');
export interface IContextMenuService {
_serviceBrand: any;
showContextMenu(delegate: IContextMenuDelegate): void;
// TODO@isidor these event should be removed once we get async context menus
onDidContextMenu: Event<void>;
onDidContextMenu: Event<void>; // TODO@isidor these event should be removed once we get async context menus
}

View File

@@ -2,15 +2,15 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IContextViewService, IContextViewDelegate } from './contextView';
import { ContextView } from 'vs/base/browser/ui/contextview/contextview';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ILogService } from 'vs/platform/log/common/log';
import { Disposable } from 'vs/base/common/lifecycle';
export class ContextViewService implements IContextViewService {
public _serviceBrand: any;
export class ContextViewService extends Disposable implements IContextViewService {
_serviceBrand: any;
private contextView: ContextView;
@@ -19,30 +19,28 @@ export class ContextViewService implements IContextViewService {
@ITelemetryService telemetryService: ITelemetryService,
@ILogService private logService: ILogService
) {
this.contextView = new ContextView(container);
}
super();
public dispose(): void {
this.contextView.dispose();
this.contextView = this._register(new ContextView(container));
}
// ContextView
public setContainer(container: HTMLElement): void {
setContainer(container: HTMLElement): void {
this.logService.trace('ContextViewService#setContainer');
this.contextView.setContainer(container);
}
public showContextView(delegate: IContextViewDelegate): void {
showContextView(delegate: IContextViewDelegate): void {
this.logService.trace('ContextViewService#showContextView');
this.contextView.show(delegate);
}
public layout(): void {
layout(): void {
this.contextView.layout();
}
public hideContextView(data?: any): void {
hideContextView(data?: any): void {
this.logService.trace('ContextViewService#hideContextView');
this.contextView.hide(data);
}