Skip to content

Commit 84b046c

Browse files
author
Benjamin Pasero
committed
debt - introduce ILayoutService
This allows to declare more services declaratively.
1 parent 2f62d28 commit 84b046c

10 files changed

Lines changed: 113 additions & 95 deletions

File tree

src/vs/editor/standalone/browser/simpleServices.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { ITelemetryInfo, ITelemetryService } from 'vs/platform/telemetry/common/
4343
import { IWorkspace, IWorkspaceContextService, IWorkspaceFolder, IWorkspaceFoldersChangeEvent, WorkbenchState, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
4444
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
4545
import { IAccessibilityService, AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
46+
import { ILayoutService, IDimension } from 'vs/platform/layout/browser/layoutService';
4647

4748
export class SimpleModel implements IResolvedTextEditorModel {
4849

@@ -671,3 +672,18 @@ export class SimpleUriLabelService implements ILabelService {
671672
return '';
672673
}
673674
}
675+
676+
export class SimpleLayoutService implements ILayoutService {
677+
_serviceBrand: any;
678+
679+
public onLayout = Event.None;
680+
681+
private _dimension: IDimension;
682+
get dimension(): IDimension {
683+
if (!this._dimension) {
684+
this._dimension = dom.getClientArea(window.document.body);
685+
}
686+
687+
return this._dimension;
688+
}
689+
}

src/vs/editor/standalone/browser/standaloneServices.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
1313
import { IModelService } from 'vs/editor/common/services/modelService';
1414
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
1515
import { ITextResourceConfigurationService, ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
16-
import { SimpleBulkEditService, SimpleConfigurationService, SimpleDialogService, SimpleNotificationService, SimpleProgressService, SimpleResourceConfigurationService, SimpleResourcePropertiesService, SimpleUriLabelService, SimpleWorkspaceContextService, StandaloneCommandService, StandaloneKeybindingService, StandaloneTelemetryService, BrowserAccessibilityService } from 'vs/editor/standalone/browser/simpleServices';
16+
import { SimpleBulkEditService, SimpleConfigurationService, SimpleDialogService, SimpleNotificationService, SimpleProgressService, SimpleResourceConfigurationService, SimpleResourcePropertiesService, SimpleUriLabelService, SimpleWorkspaceContextService, StandaloneCommandService, StandaloneKeybindingService, StandaloneTelemetryService, BrowserAccessibilityService, SimpleLayoutService } from 'vs/editor/standalone/browser/simpleServices';
1717
import { StandaloneCodeEditorServiceImpl } from 'vs/editor/standalone/browser/standaloneCodeServiceImpl';
1818
import { StandaloneThemeServiceImpl } from 'vs/editor/standalone/browser/standaloneThemeServiceImpl';
1919
import { IStandaloneThemeService } from 'vs/editor/standalone/common/standaloneThemeService';
@@ -46,6 +46,7 @@ import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDeco
4646
import { MarkerDecorationsService } from 'vs/editor/common/services/markerDecorationsServiceImpl';
4747
import { ISuggestMemoryService, SuggestMemoryService } from 'vs/editor/contrib/suggest/suggestMemory';
4848
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
49+
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
4950

5051
export interface IEditorOverrideServices {
5152
[index: string]: any;
@@ -196,7 +197,9 @@ export class DynamicStandaloneServices extends Disposable {
196197

197198
let keybindingService = ensure(IKeybindingService, () => this._register(new StandaloneKeybindingService(contextKeyService, commandService, telemetryService, notificationService, domElement)));
198199

199-
let contextViewService = ensure(IContextViewService, () => this._register(new ContextViewService(domElement, telemetryService, new NullLogService())));
200+
let layoutService = ensure(ILayoutService, () => new SimpleLayoutService());
201+
202+
let contextViewService = ensure(IContextViewService, () => this._register(new ContextViewService(domElement, telemetryService, new NullLogService(), layoutService)));
200203

201204
ensure(IContextMenuService, () => this._register(new ContextMenuService(domElement, telemetryService, notificationService, contextViewService, keybindingService, themeService)));
202205

src/vs/platform/contextview/browser/contextViewService.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ContextView } from 'vs/base/browser/ui/contextview/contextview';
88
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
99
import { ILogService } from 'vs/platform/log/common/log';
1010
import { Disposable } from 'vs/base/common/lifecycle';
11+
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
1112

1213
export class ContextViewService extends Disposable implements IContextViewService {
1314
_serviceBrand: any;
@@ -17,11 +18,15 @@ export class ContextViewService extends Disposable implements IContextViewServic
1718
constructor(
1819
container: HTMLElement,
1920
@ITelemetryService telemetryService: ITelemetryService,
20-
@ILogService private readonly logService: ILogService
21+
@ILogService private readonly logService: ILogService,
22+
@ILayoutService readonly layoutService: ILayoutService
2123
) {
2224
super();
2325

2426
this.contextView = this._register(new ContextView(container));
27+
this.layout();
28+
29+
this._register(layoutService.onLayout(() => this.layout()));
2530
}
2631

2732
// ContextView
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { Event } from 'vs/base/common/event';
7+
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
8+
9+
export const ILayoutService = createDecorator<ILayoutService>('layoutService');
10+
11+
export interface IDimension {
12+
width: number;
13+
height: number;
14+
}
15+
16+
export interface ILayoutService {
17+
18+
_serviceBrand: any;
19+
20+
/**
21+
* The dimensions of the container.
22+
*/
23+
readonly dimension: IDimension;
24+
25+
/**
26+
* An event that is emitted when the container is layed out. The
27+
* event carries the dimensions of the container as part of it.
28+
*/
29+
readonly onLayout: Event<IDimension>;
30+
}

src/vs/workbench/browser/legacyLayout.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
7-
import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickInput';
86
import { Sash, ISashEvent, IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider, Orientation } from 'vs/base/browser/ui/sash/sash';
97
import { IPartService, Position, ILayoutOptions, Parts } from 'vs/workbench/services/part/common/partService';
108
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
@@ -14,8 +12,6 @@ import { Disposable } from 'vs/base/common/lifecycle';
1412
import { IThemeService } from 'vs/platform/theme/common/themeService';
1513
import { isMacintosh } from 'vs/base/common/platform';
1614
import { memoize } from 'vs/base/common/decorators';
17-
import { NotificationsCenter } from 'vs/workbench/browser/parts/notifications/notificationsCenter';
18-
import { NotificationsToasts } from 'vs/workbench/browser/parts/notifications/notificationsToasts';
1915
import { Dimension, getClientArea, size, position, hide, show } from 'vs/base/browser/dom';
2016
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
2117
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
@@ -78,10 +74,6 @@ export class WorkbenchLegacyLayout extends Disposable implements IVerticalSashLa
7874
panel: PanelPart,
7975
statusbar: StatusbarPart
8076
},
81-
private quickopen: QuickOpenController,
82-
private quickInput: QuickInputService,
83-
private notificationsCenter: NotificationsCenter,
84-
private notificationsToasts: NotificationsToasts,
8577
@IStorageService private readonly storageService: IStorageService,
8678
@IContextViewService private readonly contextViewService: IContextViewService,
8779
@IPartService private readonly partService: IPartService,
@@ -626,16 +618,6 @@ export class WorkbenchLegacyLayout extends Disposable implements IVerticalSashLa
626618
show(statusbarContainer);
627619
}
628620

629-
// Quick open
630-
this.quickopen.layout(this.workbenchSize);
631-
632-
// Quick input
633-
this.quickInput.layout(this.workbenchSize);
634-
635-
// Notifications
636-
this.notificationsCenter.layout(this.workbenchSize);
637-
this.notificationsToasts.layout(this.workbenchSize);
638-
639621
// Sashes
640622
this.sashXOne.layout();
641623
if (panelPosition === Position.BOTTOM) {

src/vs/workbench/browser/parts/quickinput/quickInput.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import { getIconClass } from 'vs/workbench/browser/parts/quickinput/quickInputUt
4343
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
4444
import { IStorageService } from 'vs/platform/storage/common/storage';
4545
import { IAccessibilityService, AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
46+
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
47+
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
4648

4749
const $ = dom.$;
4850

@@ -816,7 +818,6 @@ export class QuickInputService extends Component implements IQuickInputService {
816818
private static readonly MAX_WIDTH = 600; // Max total width of quick open widget
817819

818820
private idPrefix = 'quickInput_'; // Constant since there is still only one.
819-
private layoutDimensions: dom.Dimension;
820821
private titleBar: HTMLElement;
821822
private filterContainer: HTMLElement;
822823
private visibleCountContainer: HTMLElement;
@@ -846,12 +847,14 @@ export class QuickInputService extends Component implements IQuickInputService {
846847
@IContextKeyService private readonly contextKeyService: IContextKeyService,
847848
@IThemeService themeService: IThemeService,
848849
@IStorageService storageService: IStorageService,
849-
@IAccessibilityService private readonly accessibilityService: IAccessibilityService
850+
@IAccessibilityService private readonly accessibilityService: IAccessibilityService,
851+
@ILayoutService private readonly layoutService: ILayoutService
850852
) {
851853
super(QuickInputService.ID, themeService, storageService);
852854
this.inQuickOpenContext = InQuickOpenContextKey.bindTo(contextKeyService);
853855
this._register(this.quickOpenService.onShow(() => this.inQuickOpen('quickOpen', true)));
854856
this._register(this.quickOpenService.onHide(() => this.inQuickOpen('quickOpen', false)));
857+
this._register(this.layoutService.onLayout(dimension => this.layout(dimension)));
855858
this.registerKeyModsListeners();
856859
}
857860

@@ -1400,17 +1403,16 @@ export class QuickInputService extends Component implements IQuickInputService {
14001403
}
14011404

14021405
layout(dimension: dom.Dimension): void {
1403-
this.layoutDimensions = dimension;
14041406
this.updateLayout();
14051407
}
14061408

14071409
private updateLayout() {
1408-
if (this.layoutDimensions && this.ui) {
1410+
if (this.ui) {
14091411
const titlebarOffset = this.partService.getTitleBarOffset();
14101412
this.ui.container.style.top = `${titlebarOffset}px`;
14111413

14121414
const style = this.ui.container.style;
1413-
const width = Math.min(this.layoutDimensions.width * 0.62 /* golden cut */, QuickInputService.MAX_WIDTH);
1415+
const width = Math.min(this.layoutService.dimension.width * 0.62 /* golden cut */, QuickInputService.MAX_WIDTH);
14141416
style.width = width + 'px';
14151417
style.marginLeft = '-' + (width / 2) + 'px';
14161418

@@ -1467,3 +1469,5 @@ export class BackAction extends Action {
14671469
return Promise.resolve();
14681470
}
14691471
}
1472+
1473+
registerSingleton(IQuickInputService, QuickInputService, true);

src/vs/workbench/browser/parts/quickopen/quickOpenController.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import { timeout } from 'vs/base/common/async';
5050
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
5151
import { CancellationTokenSource, CancellationToken } from 'vs/base/common/cancellation';
5252
import { IStorageService } from 'vs/platform/storage/common/storage';
53+
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
54+
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
5355

5456
const HELP_PREFIX = '?';
5557

@@ -73,7 +75,6 @@ export class QuickOpenController extends Component implements IQuickOpenService
7375
private lastInputValue: string;
7476
private lastSubmittedInputValue: string;
7577
private quickOpenWidget: QuickOpenWidget;
76-
private dimension: Dimension;
7778
private mapResolvedHandlersToPrefix: { [prefix: string]: Promise<QuickOpenHandler>; } = Object.create(null);
7879
private mapContextKeyToContext: { [id: string]: IContextKey<boolean>; } = Object.create(null);
7980
private handlerOnOpenCalled: { [prefix: string]: boolean; } = Object.create(null);
@@ -94,7 +95,8 @@ export class QuickOpenController extends Component implements IQuickOpenService
9495
@IPartService private readonly partService: IPartService,
9596
@IEnvironmentService private readonly environmentService: IEnvironmentService,
9697
@IThemeService themeService: IThemeService,
97-
@IStorageService storageService: IStorageService
98+
@IStorageService storageService: IStorageService,
99+
@ILayoutService private readonly layoutService: ILayoutService
98100
) {
99101
super(QuickOpenController.ID, themeService, storageService);
100102

@@ -109,6 +111,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
109111
this._register(this.configurationService.onDidChangeConfiguration(() => this.updateConfiguration()));
110112
this._register(this.partService.onTitleBarVisibilityChange(() => this.positionQuickOpenWidget()));
111113
this._register(browser.onDidChangeZoomLevel(() => this.positionQuickOpenWidget()));
114+
this._register(this.layoutService.onLayout(dimension => this.layout(dimension)));
112115
}
113116

114117
private updateConfiguration(): void {
@@ -195,9 +198,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
195198
}
196199

197200
// Layout
198-
if (this.dimension) {
199-
this.quickOpenWidget.layout(this.dimension);
200-
}
201+
this.quickOpenWidget.layout(this.layoutService.dimension);
201202

202203
// Show quick open with prefix or editor history
203204
if (!this.quickOpenWidget.isVisible() || quickNavigateConfiguration) {
@@ -624,9 +625,8 @@ export class QuickOpenController extends Component implements IQuickOpenService
624625
}
625626

626627
layout(dimension: Dimension): void {
627-
this.dimension = dimension;
628628
if (this.quickOpenWidget) {
629-
this.quickOpenWidget.layout(this.dimension);
629+
this.quickOpenWidget.layout(dimension);
630630
}
631631
}
632632
}
@@ -863,3 +863,5 @@ export class RemoveFromEditorHistoryAction extends Action {
863863
});
864864
}
865865
}
866+
867+
registerSingleton(IQuickOpenService, QuickOpenController, true);

0 commit comments

Comments
 (0)