Skip to content

Commit a8cb5b4

Browse files
author
Benjamin Pasero
committed
quickpick - use layout service from platform
1 parent 527513a commit a8cb5b4

12 files changed

Lines changed: 44 additions & 54 deletions

File tree

src/vs/platform/layout/browser/layoutService.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ export interface ILayoutService {
2727
*/
2828
readonly container: HTMLElement;
2929

30+
/**
31+
* An offset to use for positioning elements inside the container.
32+
*/
33+
readonly offset?: { top: number };
34+
3035
/**
3136
* An event that is emitted when the container is layed out. The
3237
* event carries the dimensions of the container as part of it.
3338
*/
3439
readonly onLayout: Event<IDimension>;
35-
}
40+
}

src/vs/workbench/browser/actions/developerActions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1717
import { Context } from 'vs/platform/contextkey/browser/contextKeyService';
1818
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
1919
import { timeout } from 'vs/base/common/async';
20-
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
20+
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
2121
import { Registry } from 'vs/platform/registry/common/platform';
2222
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
2323
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
@@ -101,7 +101,7 @@ class ToggleScreencastModeAction extends Action {
101101
id: string,
102102
label: string,
103103
@IKeybindingService private readonly keybindingService: IKeybindingService,
104-
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
104+
@ILayoutService private readonly layoutService: ILayoutService,
105105
@IConfigurationService private readonly configurationService: IConfigurationService
106106
) {
107107
super(id, label);
@@ -116,7 +116,7 @@ class ToggleScreencastModeAction extends Action {
116116

117117
const disposables = new DisposableStore();
118118

119-
const container = this.layoutService.getWorkbenchElement();
119+
const container = this.layoutService.container;
120120
const mouseMarker = append(container, $('.screencast-mouse'));
121121
disposables.add(toDisposable(() => mouseMarker.remove()));
122122

src/vs/workbench/browser/layout.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
118118
private _container: HTMLElement = document.createElement('div');
119119
get container(): HTMLElement { return this._container; }
120120

121+
get offset() {
122+
return {
123+
top: (() => {
124+
let offset = 0;
125+
if (this.isVisible(Parts.TITLEBAR_PART)) {
126+
offset = this.getPart(Parts.TITLEBAR_PART).maximumHeight;
127+
}
128+
129+
return offset;
130+
})()
131+
};
132+
}
133+
121134
private parts: Map<string, Part> = new Map<string, Part>();
122135

123136
private workbenchGrid!: SerializableGrid<ISerializableView>;
@@ -654,15 +667,6 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
654667
return this.getPart(part).dimension;
655668
}
656669

657-
getTitleBarOffset(): number {
658-
let offset = 0;
659-
if (this.isVisible(Parts.TITLEBAR_PART)) {
660-
offset = this.getPart(Parts.TITLEBAR_PART).maximumHeight;
661-
}
662-
663-
return offset;
664-
}
665-
666670
getMaximumEditorDimensions(): Dimension {
667671
const isColumn = this.state.panel.position === Position.RIGHT || this.state.panel.position === Position.LEFT;
668672
const takenWidth =
@@ -685,10 +689,6 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
685689
return this.parent;
686690
}
687691

688-
getWorkbenchElement(): HTMLElement {
689-
return this.container;
690-
}
691-
692692
toggleZenMode(skipLayout?: boolean, restoring = false): void {
693693
this.state.zenMode.active = !this.state.zenMode.active;
694694
this.state.zenMode.transitionDisposables.clear();

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { IQuickInputService, IQuickPickItem, IPickOptions, IInputOptions, IQuickNavigateConfiguration, IQuickPick, IQuickInputButton, IInputBox, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';
7-
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
7+
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
88
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
99
import { IThemeService } from 'vs/platform/theme/common/themeService';
1010
import { inputBackground, inputForeground, inputBorder, inputValidationInfoBackground, inputValidationInfoForeground, inputValidationInfoBorder, inputValidationWarningBackground, inputValidationWarningForeground, inputValidationWarningBorder, inputValidationErrorBackground, inputValidationErrorForeground, inputValidationErrorBorder, badgeBackground, badgeForeground, contrastBorder, buttonForeground, buttonBackground, buttonHoverBackground, progressBarBackground, widgetShadow, listFocusForeground, listFocusBackground, activeContrastBorder, pickerGroupBorder, pickerGroupForeground } from 'vs/platform/theme/common/colorRegistry';
@@ -54,13 +54,13 @@ export class QuickInputService extends PlatformQuickInputService {
5454
@IContextKeyService private readonly contextKeyService: IContextKeyService,
5555
@IThemeService themeService: IThemeService,
5656
@IAccessibilityService private readonly accessibilityService: IAccessibilityService,
57-
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService
57+
@ILayoutService private readonly layoutService: ILayoutService
5858
) {
5959
super(themeService);
6060

6161
this.controller = this._register(new QuickInputController({
6262
idPrefix: 'quickInput_', // Constant since there is still only one.
63-
container: this.layoutService.getWorkbenchElement(),
63+
container: this.layoutService.container,
6464
ignoreFocusOut: () => this.environmentService.args['sticky-quickopen'] || !this.configurationService.getValue(CLOSE_ON_FOCUS_LOST_CONFIG),
6565
isScreenReaderOptimized: () => this.accessibilityService.isScreenReaderOptimized(),
6666
backKeybindingLabel: () => this.keybindingService.lookupKeybinding(QuickPickBack.id)?.getLabel() || undefined,
@@ -76,15 +76,15 @@ export class QuickInputService extends PlatformQuickInputService {
7676
styles: this.computeStyles(),
7777
}));
7878

79-
this.controller.layout(this.layoutService.dimension, this.layoutService.getTitleBarOffset());
79+
this.controller.layout(this.layoutService.dimension, this.layoutService.offset?.top ?? 0);
8080

8181
this.registerListeners();
8282
}
8383

8484
private registerListeners(): void {
8585

8686
// Layout changes
87-
this._register(this.layoutService.onLayout(dimension => this.controller.layout(dimension, this.layoutService.getTitleBarOffset())));
87+
this._register(this.layoutService.onLayout(dimension => this.controller.layout(dimension, this.layoutService.offset?.top ?? 0)));
8888

8989
// Context keys
9090
this._register(this.controller.onShow(() => this.resetContextKeys()));

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
175175
// Create upon first open
176176
if (!this.quickOpenWidget) {
177177
const quickOpenWidget: QuickOpenWidget = this.quickOpenWidget = this._register(new QuickOpenWidget(
178-
this.layoutService.getWorkbenchElement(),
178+
this.layoutService.container,
179179
{
180180
onOk: () => this.onOk(),
181181
onCancel: () => { /* ignore */ },
@@ -238,10 +238,8 @@ export class QuickOpenController extends Component implements IQuickOpenService
238238
}
239239

240240
private positionQuickOpenWidget(): void {
241-
const titlebarOffset = this.layoutService.getTitleBarOffset();
242-
243241
if (this.quickOpenWidget) {
244-
this.quickOpenWidget.getElement().style.top = `${titlebarOffset}px`;
242+
this.quickOpenWidget.getElement().style.top = `${this.layoutService.offset?.top ?? 0}px`;
245243
}
246244
}
247245

src/vs/workbench/contrib/debug/browser/debugToolBar.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class DebugToolBar extends Themable implements IWorkbenchContribution {
6666
super(themeService);
6767

6868
this.$el = dom.$('div.debug-toolbar');
69-
this.$el.style.top = `${layoutService.getTitleBarOffset()}px`;
69+
this.$el.style.top = `${layoutService.offset?.top ?? 0}px`;
7070

7171
this.dragArea = dom.append(this.$el, dom.$('div.drag-area.codicon.codicon-gripper'));
7272

@@ -151,7 +151,7 @@ export class DebugToolBar extends Themable implements IWorkbenchContribution {
151151
// Prevent default to stop editor selecting text #8524
152152
mouseMoveEvent.preventDefault();
153153
// Reduce x by width of drag handle to reduce jarring #16604
154-
this.setCoordinates(mouseMoveEvent.posx - 14, mouseMoveEvent.posy - this.layoutService.getTitleBarOffset());
154+
this.setCoordinates(mouseMoveEvent.posx - 14, mouseMoveEvent.posy - (this.layoutService.offset?.top ?? 0));
155155
});
156156

157157
const mouseUpListener = dom.addDisposableGenericMouseUpListner(window, (e: MouseEvent) => {
@@ -197,7 +197,7 @@ export class DebugToolBar extends Themable implements IWorkbenchContribution {
197197
}
198198

199199
private setYCoordinate(y = this.yCoordinate): void {
200-
const titlebarOffset = this.layoutService.getTitleBarOffset();
200+
const titlebarOffset = this.layoutService.offset?.top ?? 0;
201201
this.$el.style.top = `${titlebarOffset + y}px`;
202202
this.yCoordinate = y;
203203
}
@@ -239,7 +239,7 @@ export class DebugToolBar extends Themable implements IWorkbenchContribution {
239239
}
240240
if (!this.isBuilt) {
241241
this.isBuilt = true;
242-
this.layoutService.getWorkbenchElement().appendChild(this.$el);
242+
this.layoutService.container.appendChild(this.$el);
243243
}
244244

245245
this.isVisible = true;

src/vs/workbench/contrib/webview/browser/dynamicWebviewEditorOverlay.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Emitter, Event } from 'vs/base/common/event';
99
import { Disposable, DisposableStore, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
1010
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
1111
import { IWebviewService, Webview, WebviewContentOptions, WebviewEditorOverlay, WebviewElement, WebviewOptions, WebviewExtensionDescription } from 'vs/workbench/contrib/webview/browser/webview';
12-
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
12+
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
1313
import { Dimension } from 'vs/base/browser/dom';
1414

1515
/**
@@ -37,7 +37,7 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewEd
3737
private readonly id: string,
3838
initialOptions: WebviewOptions,
3939
initialContentOptions: WebviewContentOptions,
40-
@IWorkbenchLayoutService private readonly _layoutService: IWorkbenchLayoutService,
40+
@ILayoutService private readonly _layoutService: ILayoutService,
4141
@IWebviewService private readonly _webviewService: IWebviewService
4242
) {
4343
super();
@@ -56,7 +56,7 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewEd
5656

5757
// Webviews cannot be reparented in the dom as it will destory their contents.
5858
// Mount them to a high level node to avoid this.
59-
this._layoutService.getWorkbenchElement().appendChild(container);
59+
this._layoutService.container.appendChild(container);
6060

6161
return container;
6262
}

src/vs/workbench/contrib/welcome/overlay/browser/welcomeOverlay.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
99
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1010
import { ShowAllCommandsAction } from 'vs/workbench/contrib/quickopen/browser/commandsHandler';
1111
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
12-
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
12+
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
1313
import { localize } from 'vs/nls';
1414
import { Action } from 'vs/base/common/actions';
1515
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
@@ -156,7 +156,7 @@ class WelcomeOverlay extends Disposable {
156156
private _overlay!: HTMLElement;
157157

158158
constructor(
159-
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
159+
@ILayoutService private readonly layoutService: ILayoutService,
160160
@IEditorService private readonly editorService: IEditorService,
161161
@ICommandService private readonly commandService: ICommandService,
162162
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@@ -168,8 +168,8 @@ class WelcomeOverlay extends Disposable {
168168
}
169169

170170
private create(): void {
171-
const offset = this.layoutService.getTitleBarOffset();
172-
this._overlay = dom.append(this.layoutService.getWorkbenchElement(), $('.welcomeOverlay'));
171+
const offset = this.layoutService.offset?.top ?? 0;
172+
this._overlay = dom.append(this.layoutService.container, $('.welcomeOverlay'));
173173
this._overlay.style.top = `${offset}px`;
174174
this._overlay.style.height = `calc(100% - ${offset}px)`;
175175
this._overlay.style.display = 'none';

src/vs/workbench/services/history/browser/history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class HistoryService extends Disposable implements IHistoryService {
140140
mouseBackForwardSupportListener.clear();
141141

142142
if (this.configurationService.getValue('workbench.editor.mouseBackForwardToNavigate')) {
143-
mouseBackForwardSupportListener.add(addDisposableListener(this.layoutService.getWorkbenchElement(), EventType.MOUSE_DOWN, e => this.onMouseDown(e)));
143+
mouseBackForwardSupportListener.add(addDisposableListener(this.layoutService.container, EventType.MOUSE_DOWN, e => this.onMouseDown(e)));
144144
}
145145
};
146146

src/vs/workbench/services/host/browser/browserHostService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { Event } from 'vs/base/common/event';
77
import { IHostService } from 'vs/workbench/services/host/browser/host';
88
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
9-
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
9+
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
1010
import { IResourceEditorInputType, IEditorService } from 'vs/workbench/services/editor/common/editorService';
1111
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1212
import { IWindowSettings, IWindowOpenable, IOpenWindowOptions, isFolderToOpen, isWorkspaceToOpen, isFileToOpen, IOpenEmptyWindowOptions } from 'vs/platform/windows/common/windows';
@@ -59,7 +59,7 @@ export class BrowserHostService extends Disposable implements IHostService {
5959
private workspaceProvider: IWorkspaceProvider;
6060

6161
constructor(
62-
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
62+
@ILayoutService private readonly layoutService: ILayoutService,
6363
@IEditorService private readonly editorService: IEditorService,
6464
@IConfigurationService private readonly configurationService: IConfigurationService,
6565
@IFileService private readonly fileService: IFileService,
@@ -177,7 +177,7 @@ export class BrowserHostService extends Disposable implements IHostService {
177177
}
178178

179179
async toggleFullScreen(): Promise<void> {
180-
const target = this.layoutService.getWorkbenchElement();
180+
const target = this.layoutService.container;
181181

182182
// Chromium
183183
if (document.fullscreen !== undefined) {

0 commit comments

Comments
 (0)