From 3385ec73419138b589c58ba27da4a7b2cd6bb156 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 8 Mar 2019 08:28:57 +0100 Subject: [PATCH] debt - declarative context view service --- .../editor/standalone/browser/simpleServices.ts | 6 ++++++ .../standalone/browser/standaloneServices.ts | 4 ++-- .../contextview/browser/contextViewService.ts | 15 +++++---------- src/vs/platform/layout/browser/layoutService.ts | 5 +++++ src/vs/workbench/electron-browser/workbench.ts | 17 +++++++---------- src/vs/workbench/test/workbenchTestServices.ts | 2 ++ src/vs/workbench/workbench.main.ts | 1 + 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/vs/editor/standalone/browser/simpleServices.ts b/src/vs/editor/standalone/browser/simpleServices.ts index 66f68e5bc26..416092593c5 100644 --- a/src/vs/editor/standalone/browser/simpleServices.ts +++ b/src/vs/editor/standalone/browser/simpleServices.ts @@ -686,4 +686,10 @@ export class SimpleLayoutService implements ILayoutService { return this._dimension; } + + get container(): HTMLElement { + return this._container; + } + + constructor(private _container: HTMLElement) { } } diff --git a/src/vs/editor/standalone/browser/standaloneServices.ts b/src/vs/editor/standalone/browser/standaloneServices.ts index 01f45b769c4..ec8771e32bb 100644 --- a/src/vs/editor/standalone/browser/standaloneServices.ts +++ b/src/vs/editor/standalone/browser/standaloneServices.ts @@ -197,9 +197,9 @@ export class DynamicStandaloneServices extends Disposable { let keybindingService = ensure(IKeybindingService, () => this._register(new StandaloneKeybindingService(contextKeyService, commandService, telemetryService, notificationService, domElement))); - let layoutService = ensure(ILayoutService, () => new SimpleLayoutService()); + let layoutService = ensure(ILayoutService, () => new SimpleLayoutService(domElement)); - let contextViewService = ensure(IContextViewService, () => this._register(new ContextViewService(domElement, telemetryService, new NullLogService(), layoutService))); + let contextViewService = ensure(IContextViewService, () => this._register(new ContextViewService(layoutService))); ensure(IContextMenuService, () => this._register(new ContextMenuService(domElement, telemetryService, notificationService, contextViewService, keybindingService, themeService))); diff --git a/src/vs/platform/contextview/browser/contextViewService.ts b/src/vs/platform/contextview/browser/contextViewService.ts index 0bcada24ea8..8244328604f 100644 --- a/src/vs/platform/contextview/browser/contextViewService.ts +++ b/src/vs/platform/contextview/browser/contextViewService.ts @@ -5,10 +5,9 @@ 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'; import { ILayoutService } from 'vs/platform/layout/browser/layoutService'; +import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; export class ContextViewService extends Disposable implements IContextViewService { _serviceBrand: any; @@ -16,14 +15,11 @@ export class ContextViewService extends Disposable implements IContextViewServic private contextView: ContextView; constructor( - container: HTMLElement, - @ITelemetryService telemetryService: ITelemetryService, - @ILogService private readonly logService: ILogService, @ILayoutService readonly layoutService: ILayoutService ) { super(); - this.contextView = this._register(new ContextView(container)); + this.contextView = this._register(new ContextView(layoutService.container)); this.layout(); this._register(layoutService.onLayout(() => this.layout())); @@ -32,12 +28,10 @@ export class ContextViewService extends Disposable implements IContextViewServic // ContextView setContainer(container: HTMLElement): void { - this.logService.trace('ContextViewService#setContainer'); this.contextView.setContainer(container); } showContextView(delegate: IContextViewDelegate): void { - this.logService.trace('ContextViewService#showContextView'); this.contextView.show(delegate); } @@ -46,7 +40,8 @@ export class ContextViewService extends Disposable implements IContextViewServic } hideContextView(data?: any): void { - this.logService.trace('ContextViewService#hideContextView'); this.contextView.hide(data); } -} \ No newline at end of file +} + +registerSingleton(IContextViewService, ContextViewService, true); \ No newline at end of file diff --git a/src/vs/platform/layout/browser/layoutService.ts b/src/vs/platform/layout/browser/layoutService.ts index d86d7c1bb05..a54ef23a7bb 100644 --- a/src/vs/platform/layout/browser/layoutService.ts +++ b/src/vs/platform/layout/browser/layoutService.ts @@ -22,6 +22,11 @@ export interface ILayoutService { */ readonly dimension: IDimension; + /** + * Container of the application. + */ + readonly container: HTMLElement; + /** * An event that is emitted when the container is layed out. The * event carries the dimensions of the container as part of it. diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index b35ed508310..40e3338459d 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -39,7 +39,6 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { LifecyclePhase, StartupKind, ILifecycleService, WillShutdownEvent } from 'vs/platform/lifecycle/common/lifecycle'; import { IWindowService, IWindowConfiguration, IPath, MenuBarVisibility, getTitleBarStyle, IWindowsService } from 'vs/platform/windows/common/windows'; -import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { NotificationService } from 'vs/workbench/services/notification/common/notificationService'; @@ -50,7 +49,6 @@ import { registerNotificationCommands } from 'vs/workbench/browser/parts/notific import { NotificationsToasts } from 'vs/workbench/browser/parts/notifications/notificationsToasts'; import { IEditorService, IResourceEditor } from 'vs/workbench/services/editor/common/editorService'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; -import { ContextViewService } from 'vs/platform/contextview/browser/contextViewService'; import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService'; import { Sizing, Direction, Grid, View } from 'vs/base/browser/ui/grid/grid'; import { WorkbenchLegacyLayout } from 'vs/workbench/browser/legacyLayout'; @@ -151,7 +149,7 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService { private parts: Map = new Map(); constructor( - private container: HTMLElement, + private parent: HTMLElement, private configuration: IWindowConfiguration, private serviceCollection: ServiceCollection, @IInstantiationService instantiationService: IInstantiationService, @@ -364,9 +362,6 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService { const localizationsChannel = getDelayedChannel(sharedProcess.then(c => c.getChannel('localizations'))); serviceCollection.set(ILocalizationsService, new SyncDescriptor(LocalizationsChannelClient, [localizationsChannel])); - // Context view service - serviceCollection.set(IContextViewService, new SyncDescriptor(ContextViewService, [this.workbench], true)); - // Contributed services const contributedServices = getServices(); for (let contributedService of contributedServices) { @@ -489,7 +484,7 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService { this.instantiationService.invokeFunction(accessor => this.createNotificationsHandlers(accessor)); // Add Workbench to DOM - this.container.appendChild(this.workbench); + this.parent.appendChild(this.workbench); } private createTitlebarPart(): void { @@ -690,6 +685,8 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService { private _dimension: IDimension; get dimension(): IDimension { return this._dimension; } + get container(): HTMLElement { return this.workbench; } + private workbenchGrid: Grid | WorkbenchLegacyLayout; private titleBarPartView: View; @@ -1283,7 +1280,7 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService { } else { this.workbenchGrid = this.instantiationService.createInstance( WorkbenchLegacyLayout, - this.container, + this.parent, this.workbench, { titlebar: titleBar, @@ -1299,7 +1296,7 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService { layout(options?: ILayoutOptions): void { if (!this.disposed) { - this._dimension = getClientArea(this.container); + this._dimension = getClientArea(this.parent); if (this.workbenchGrid instanceof Grid) { position(this.workbench, 0, 0, 0, 0, 'relative'); @@ -1615,7 +1612,7 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService { // Layout if (!skipLayout) { if (this.workbenchGrid instanceof Grid) { - const dimensions = getClientArea(this.container); + const dimensions = getClientArea(this.parent); this.workbenchGrid.layout(dimensions.width, dimensions.height); } else { this.workbenchGrid.layout(); diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index ddea86ace50..50c496776a8 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -450,6 +450,8 @@ export class TestLayoutService implements IWorkbenchLayoutService { dimension: IDimension = { width: 800, height: 600 }; + container: HTMLElement = window.document.body; + onZenModeChange: Event = Event.None; onLayout = Event.None; diff --git a/src/vs/workbench/workbench.main.ts b/src/vs/workbench/workbench.main.ts index b3f5eed523c..f0b567c35ec 100644 --- a/src/vs/workbench/workbench.main.ts +++ b/src/vs/workbench/workbench.main.ts @@ -98,6 +98,7 @@ import 'vs/workbench/services/commands/common/commandService'; import 'vs/workbench/services/themes/browser/workbenchThemeService'; import 'vs/workbench/services/extensions/electron-browser/extensionService'; import 'vs/workbench/services/contextmenu/electron-browser/contextmenuService'; +import 'vs/platform/contextview/browser/contextViewService'; registerSingleton(IMenuService, MenuService, true); registerSingleton(IListService, ListService, true); -- GitLab