提交 84b046ce 编写于 作者: B Benjamin Pasero

debt - introduce ILayoutService

This allows to declare more services declaratively.
上级 2f62d285
......@@ -43,6 +43,7 @@ import { ITelemetryInfo, ITelemetryService } from 'vs/platform/telemetry/common/
import { IWorkspace, IWorkspaceContextService, IWorkspaceFolder, IWorkspaceFoldersChangeEvent, WorkbenchState, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { IAccessibilityService, AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
import { ILayoutService, IDimension } from 'vs/platform/layout/browser/layoutService';
export class SimpleModel implements IResolvedTextEditorModel {
......@@ -671,3 +672,18 @@ export class SimpleUriLabelService implements ILabelService {
return '';
}
}
export class SimpleLayoutService implements ILayoutService {
_serviceBrand: any;
public onLayout = Event.None;
private _dimension: IDimension;
get dimension(): IDimension {
if (!this._dimension) {
this._dimension = dom.getClientArea(window.document.body);
}
return this._dimension;
}
}
......@@ -13,7 +13,7 @@ import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { ITextResourceConfigurationService, ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
import { SimpleBulkEditService, SimpleConfigurationService, SimpleDialogService, SimpleNotificationService, SimpleProgressService, SimpleResourceConfigurationService, SimpleResourcePropertiesService, SimpleUriLabelService, SimpleWorkspaceContextService, StandaloneCommandService, StandaloneKeybindingService, StandaloneTelemetryService, BrowserAccessibilityService } from 'vs/editor/standalone/browser/simpleServices';
import { SimpleBulkEditService, SimpleConfigurationService, SimpleDialogService, SimpleNotificationService, SimpleProgressService, SimpleResourceConfigurationService, SimpleResourcePropertiesService, SimpleUriLabelService, SimpleWorkspaceContextService, StandaloneCommandService, StandaloneKeybindingService, StandaloneTelemetryService, BrowserAccessibilityService, SimpleLayoutService } from 'vs/editor/standalone/browser/simpleServices';
import { StandaloneCodeEditorServiceImpl } from 'vs/editor/standalone/browser/standaloneCodeServiceImpl';
import { StandaloneThemeServiceImpl } from 'vs/editor/standalone/browser/standaloneThemeServiceImpl';
import { IStandaloneThemeService } from 'vs/editor/standalone/common/standaloneThemeService';
......@@ -46,6 +46,7 @@ import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDeco
import { MarkerDecorationsService } from 'vs/editor/common/services/markerDecorationsServiceImpl';
import { ISuggestMemoryService, SuggestMemoryService } from 'vs/editor/contrib/suggest/suggestMemory';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
export interface IEditorOverrideServices {
[index: string]: any;
......@@ -196,7 +197,9 @@ export class DynamicStandaloneServices extends Disposable {
let keybindingService = ensure(IKeybindingService, () => this._register(new StandaloneKeybindingService(contextKeyService, commandService, telemetryService, notificationService, domElement)));
let contextViewService = ensure(IContextViewService, () => this._register(new ContextViewService(domElement, telemetryService, new NullLogService())));
let layoutService = ensure(ILayoutService, () => new SimpleLayoutService());
let contextViewService = ensure(IContextViewService, () => this._register(new ContextViewService(domElement, telemetryService, new NullLogService(), layoutService)));
ensure(IContextMenuService, () => this._register(new ContextMenuService(domElement, telemetryService, notificationService, contextViewService, keybindingService, themeService)));
......
......@@ -8,6 +8,7 @@ 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';
export class ContextViewService extends Disposable implements IContextViewService {
_serviceBrand: any;
......@@ -17,11 +18,15 @@ export class ContextViewService extends Disposable implements IContextViewServic
constructor(
container: HTMLElement,
@ITelemetryService telemetryService: ITelemetryService,
@ILogService private readonly logService: ILogService
@ILogService private readonly logService: ILogService,
@ILayoutService readonly layoutService: ILayoutService
) {
super();
this.contextView = this._register(new ContextView(container));
this.layout();
this._register(layoutService.onLayout(() => this.layout()));
}
// ContextView
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
export const ILayoutService = createDecorator<ILayoutService>('layoutService');
export interface IDimension {
width: number;
height: number;
}
export interface ILayoutService {
_serviceBrand: any;
/**
* The dimensions of the container.
*/
readonly dimension: IDimension;
/**
* An event that is emitted when the container is layed out. The
* event carries the dimensions of the container as part of it.
*/
readonly onLayout: Event<IDimension>;
}
\ No newline at end of file
......@@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickInput';
import { Sash, ISashEvent, IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider, Orientation } from 'vs/base/browser/ui/sash/sash';
import { IPartService, Position, ILayoutOptions, Parts } from 'vs/workbench/services/part/common/partService';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
......@@ -14,8 +12,6 @@ import { Disposable } from 'vs/base/common/lifecycle';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { isMacintosh } from 'vs/base/common/platform';
import { memoize } from 'vs/base/common/decorators';
import { NotificationsCenter } from 'vs/workbench/browser/parts/notifications/notificationsCenter';
import { NotificationsToasts } from 'vs/workbench/browser/parts/notifications/notificationsToasts';
import { Dimension, getClientArea, size, position, hide, show } from 'vs/base/browser/dom';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
......@@ -78,10 +74,6 @@ export class WorkbenchLegacyLayout extends Disposable implements IVerticalSashLa
panel: PanelPart,
statusbar: StatusbarPart
},
private quickopen: QuickOpenController,
private quickInput: QuickInputService,
private notificationsCenter: NotificationsCenter,
private notificationsToasts: NotificationsToasts,
@IStorageService private readonly storageService: IStorageService,
@IContextViewService private readonly contextViewService: IContextViewService,
@IPartService private readonly partService: IPartService,
......@@ -626,16 +618,6 @@ export class WorkbenchLegacyLayout extends Disposable implements IVerticalSashLa
show(statusbarContainer);
}
// Quick open
this.quickopen.layout(this.workbenchSize);
// Quick input
this.quickInput.layout(this.workbenchSize);
// Notifications
this.notificationsCenter.layout(this.workbenchSize);
this.notificationsToasts.layout(this.workbenchSize);
// Sashes
this.sashXOne.layout();
if (panelPosition === Position.BOTTOM) {
......
......@@ -43,6 +43,8 @@ import { getIconClass } from 'vs/workbench/browser/parts/quickinput/quickInputUt
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IAccessibilityService, AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
const $ = dom.$;
......@@ -816,7 +818,6 @@ export class QuickInputService extends Component implements IQuickInputService {
private static readonly MAX_WIDTH = 600; // Max total width of quick open widget
private idPrefix = 'quickInput_'; // Constant since there is still only one.
private layoutDimensions: dom.Dimension;
private titleBar: HTMLElement;
private filterContainer: HTMLElement;
private visibleCountContainer: HTMLElement;
......@@ -846,12 +847,14 @@ export class QuickInputService extends Component implements IQuickInputService {
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService,
@IAccessibilityService private readonly accessibilityService: IAccessibilityService
@IAccessibilityService private readonly accessibilityService: IAccessibilityService,
@ILayoutService private readonly layoutService: ILayoutService
) {
super(QuickInputService.ID, themeService, storageService);
this.inQuickOpenContext = InQuickOpenContextKey.bindTo(contextKeyService);
this._register(this.quickOpenService.onShow(() => this.inQuickOpen('quickOpen', true)));
this._register(this.quickOpenService.onHide(() => this.inQuickOpen('quickOpen', false)));
this._register(this.layoutService.onLayout(dimension => this.layout(dimension)));
this.registerKeyModsListeners();
}
......@@ -1400,17 +1403,16 @@ export class QuickInputService extends Component implements IQuickInputService {
}
layout(dimension: dom.Dimension): void {
this.layoutDimensions = dimension;
this.updateLayout();
}
private updateLayout() {
if (this.layoutDimensions && this.ui) {
if (this.ui) {
const titlebarOffset = this.partService.getTitleBarOffset();
this.ui.container.style.top = `${titlebarOffset}px`;
const style = this.ui.container.style;
const width = Math.min(this.layoutDimensions.width * 0.62 /* golden cut */, QuickInputService.MAX_WIDTH);
const width = Math.min(this.layoutService.dimension.width * 0.62 /* golden cut */, QuickInputService.MAX_WIDTH);
style.width = width + 'px';
style.marginLeft = '-' + (width / 2) + 'px';
......@@ -1467,3 +1469,5 @@ export class BackAction extends Action {
return Promise.resolve();
}
}
registerSingleton(IQuickInputService, QuickInputService, true);
\ No newline at end of file
......@@ -50,6 +50,8 @@ import { timeout } from 'vs/base/common/async';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { CancellationTokenSource, CancellationToken } from 'vs/base/common/cancellation';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
const HELP_PREFIX = '?';
......@@ -73,7 +75,6 @@ export class QuickOpenController extends Component implements IQuickOpenService
private lastInputValue: string;
private lastSubmittedInputValue: string;
private quickOpenWidget: QuickOpenWidget;
private dimension: Dimension;
private mapResolvedHandlersToPrefix: { [prefix: string]: Promise<QuickOpenHandler>; } = Object.create(null);
private mapContextKeyToContext: { [id: string]: IContextKey<boolean>; } = Object.create(null);
private handlerOnOpenCalled: { [prefix: string]: boolean; } = Object.create(null);
......@@ -94,7 +95,8 @@ export class QuickOpenController extends Component implements IQuickOpenService
@IPartService private readonly partService: IPartService,
@IEnvironmentService private readonly environmentService: IEnvironmentService,
@IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService
@IStorageService storageService: IStorageService,
@ILayoutService private readonly layoutService: ILayoutService
) {
super(QuickOpenController.ID, themeService, storageService);
......@@ -109,6 +111,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
this._register(this.configurationService.onDidChangeConfiguration(() => this.updateConfiguration()));
this._register(this.partService.onTitleBarVisibilityChange(() => this.positionQuickOpenWidget()));
this._register(browser.onDidChangeZoomLevel(() => this.positionQuickOpenWidget()));
this._register(this.layoutService.onLayout(dimension => this.layout(dimension)));
}
private updateConfiguration(): void {
......@@ -195,9 +198,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
}
// Layout
if (this.dimension) {
this.quickOpenWidget.layout(this.dimension);
}
this.quickOpenWidget.layout(this.layoutService.dimension);
// Show quick open with prefix or editor history
if (!this.quickOpenWidget.isVisible() || quickNavigateConfiguration) {
......@@ -624,9 +625,8 @@ export class QuickOpenController extends Component implements IQuickOpenService
}
layout(dimension: Dimension): void {
this.dimension = dimension;
if (this.quickOpenWidget) {
this.quickOpenWidget.layout(this.dimension);
this.quickOpenWidget.layout(dimension);
}
}
}
......@@ -863,3 +863,5 @@ export class RemoveFromEditorHistoryAction extends Action {
});
}
}
registerSingleton(IQuickOpenService, QuickOpenController, true);
\ No newline at end of file
......@@ -29,9 +29,6 @@ import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
import { IActionBarRegistry, Extensions as ActionBarExtensions } from 'vs/workbench/browser/actions';
import { PanelRegistry, Extensions as PanelExtensions } from 'vs/workbench/browser/panel';
import { ViewletRegistry, Extensions as ViewletExtensions } from 'vs/workbench/browser/viewlet';
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickInput';
import { getServices } from 'vs/platform/instantiation/common/extensions';
import { Position, Parts, IPartService, ILayoutOptions } from 'vs/workbench/services/part/common/partService';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
......@@ -46,9 +43,7 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IFileService } from 'vs/platform/files/common/files';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { ITitleService } from 'vs/workbench/services/title/common/titleService';
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
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';
......@@ -97,12 +92,11 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { ILocalizationsService } from 'vs/platform/localizations/common/localizations';
import { HistoryService } from 'vs/workbench/services/history/browser/history';
import { WorkbenchThemeService } from 'vs/workbench/services/themes/browser/workbenchThemeService';
import { IProductService } from 'vs/platform/product/common/product';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { WorkbenchContextKeysHandler } from 'vs/workbench/browser/contextkeys';
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { ILayoutService, IDimension } from 'vs/platform/layout/browser/layoutService';
// import@node
import { getDelayedChannel } from 'vs/base/parts/ipc/node/ipc';
......@@ -203,12 +197,6 @@ export class Workbench extends Disposable implements IPartService {
private editorPart: EditorPart;
private statusbarPart: StatusbarPart;
private quickOpen: QuickOpenController;
private quickInput: QuickInputService;
private notificationsCenter: NotificationsCenter;
private notificationsToasts: NotificationsToasts;
constructor(
private container: HTMLElement,
private configuration: IWindowConfiguration,
......@@ -358,6 +346,7 @@ export class Workbench extends Disposable implements IPartService {
// Parts
serviceCollection.set(IPartService, this); // TODO@Ben use SyncDescriptor
serviceCollection.set(ILayoutService, this); // TODO@Ben use SyncDescriptor
// Labels
serviceCollection.set(ILabelService, new SyncDescriptor(LabelService, undefined, true));
......@@ -502,17 +491,6 @@ export class Workbench extends Disposable implements IPartService {
this.titlebarPart = this.instantiationService.createInstance(TitlebarPart, Identifiers.TITLEBAR_PART);
serviceCollection.set(ITitleService, this.titlebarPart); // TODO@Ben use SyncDescriptor
// History
serviceCollection.set(IHistoryService, new SyncDescriptor(HistoryService));
// Quick open service (quick open controller)
this.quickOpen = this.instantiationService.createInstance(QuickOpenController);
serviceCollection.set(IQuickOpenService, this.quickOpen); // TODO@Ben use SyncDescriptor
// Quick input service
this.quickInput = this.instantiationService.createInstance(QuickInputService);
serviceCollection.set(IQuickInputService, this.quickInput); // TODO@Ben use SyncDescriptor
// Contributed services
const contributedServices = getServices();
for (let contributedService of contributedServices) {
......@@ -692,30 +670,26 @@ export class Workbench extends Disposable implements IPartService {
private createNotificationsHandlers(accessor: ServicesAccessor): void {
const notificationService = accessor.get(INotificationService) as NotificationService;
// Notifications Center
this.notificationsCenter = this._register(this.instantiationService.createInstance(NotificationsCenter, this.workbench, notificationService.model));
// Notifications Toasts
this.notificationsToasts = this._register(this.instantiationService.createInstance(NotificationsToasts, this.workbench, notificationService.model));
// Notifications Alerts
// Instantiate Notification components
const notificationsCenter = this._register(this.instantiationService.createInstance(NotificationsCenter, this.workbench, notificationService.model));
const notificationsToasts = this._register(this.instantiationService.createInstance(NotificationsToasts, this.workbench, notificationService.model));
this._register(this.instantiationService.createInstance(NotificationsAlerts, notificationService.model));
// Notifications Status
const notificationsStatus = this.instantiationService.createInstance(NotificationsStatus, notificationService.model);
// Eventing
this._register(this.notificationsCenter.onDidChangeVisibility(() => {
// Update status
notificationsStatus.update(this.notificationsCenter.isVisible);
// Visibility
this._register(notificationsCenter.onDidChangeVisibility(() => {
notificationsStatus.update(notificationsCenter.isVisible);
notificationsToasts.update(notificationsCenter.isVisible);
}));
// Update toasts
this.notificationsToasts.update(this.notificationsCenter.isVisible);
// Layout
this._register(this.onLayout(dimension => {
notificationsCenter.layout(dimension);
notificationsToasts.layout(dimension);
}));
// Register Commands
registerNotificationCommands(this.notificationsCenter, this.notificationsToasts);
registerNotificationCommands(notificationsCenter, notificationsToasts);
}
private restoreWorkbench(): Promise<void> {
......@@ -828,6 +802,12 @@ export class Workbench extends Disposable implements IPartService {
private readonly _onZenMode: Emitter<boolean> = this._register(new Emitter<boolean>());
get onZenModeChange(): Event<boolean> { return this._onZenMode.event; }
private readonly _onLayout = this._register(new Emitter<IDimension>());
get onLayout(): Event<IDimension> { return this._onLayout.event; }
private _dimension: IDimension;
get dimension(): IDimension { return this._dimension; }
private workbenchGrid: Grid<View> | WorkbenchLegacyLayout;
private titleBarPartView: View;
......@@ -837,7 +817,6 @@ export class Workbench extends Disposable implements IPartService {
private editorPartView: View;
private statusBarPartView: View;
private contextViewService: IContextViewService;
private windowService: IWindowService;
private readonly state = {
......@@ -1035,7 +1014,6 @@ export class Workbench extends Disposable implements IPartService {
const environmentService = accessor.get(IEnvironmentService);
this.windowService = accessor.get(IWindowService);
this.contextViewService = accessor.get(IContextViewService);
// Fullscreen
this.state.fullscreen = isFullscreen();
......@@ -1406,38 +1384,30 @@ export class Workbench extends Disposable implements IPartService {
sidebar: this.sidebarPart,
panel: this.panelPart,
statusbar: this.statusbarPart,
},
this.quickOpen,
this.quickInput,
this.notificationsCenter,
this.notificationsToasts
}
);
}
}
layout(options?: ILayoutOptions): void {
this.contextViewService.layout();
if (!this.disposed) {
this._dimension = getClientArea(this.container);
if (this.workbenchGrid instanceof Grid) {
const dimensions = getClientArea(this.container);
position(this.workbench, 0, 0, 0, 0, 'relative');
size(this.workbench, dimensions.width, dimensions.height);
size(this.workbench, this._dimension.width, this._dimension.height);
// Layout the grid
this.workbenchGrid.layout(dimensions.width, dimensions.height);
// Layout the grid widget
this.workbenchGrid.layout(this._dimension.width, this._dimension.height);
// Layout non-view ui components
this.quickInput.layout(dimensions);
this.quickOpen.layout(dimensions);
this.notificationsCenter.layout(dimensions);
this.notificationsToasts.layout(dimensions);
// Layout Grid
// Layout grid views
this.layoutGrid();
} else {
this.workbenchGrid.layout(options);
}
// Emit as event
this._onLayout.fire(this._dimension);
}
}
......
......@@ -30,6 +30,7 @@ import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { coalesce } from 'vs/base/common/arrays';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
/**
* Stores the selection & view state of an editor and allows to compare it to other selection states.
......@@ -971,3 +972,5 @@ export class HistoryService extends Disposable implements IHistoryService {
return undefined;
}
}
registerSingleton(IHistoryService, HistoryService);
\ No newline at end of file
......@@ -74,6 +74,9 @@ import 'vs/workbench/services/textmodelResolver/common/textModelResolverService'
import 'vs/workbench/services/textfile/common/textFileService';
import 'vs/workbench/services/dialogs/electron-browser/dialogService';
import 'vs/workbench/services/backup/node/backupFileService';
import 'vs/workbench/services/history/browser/history';
import 'vs/workbench/browser/parts/quickinput/quickInput';
import 'vs/workbench/browser/parts/quickopen/quickOpenController';
registerSingleton(IMenuService, MenuService, true);
registerSingleton(IListService, ListService, true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册