Skip to content

Commit 2542c28

Browse files
authored
aux window - use layoutservice for containers (microsoft#196531)
1 parent aa74782 commit 2542c28

File tree

6 files changed

+54
-30
lines changed

6 files changed

+54
-30
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ export interface ILayoutService {
2424

2525
readonly _serviceBrand: undefined;
2626

27+
/**
28+
* An event that is emitted when the container is layed out. The
29+
* event carries the dimensions of the container as part of it.
30+
*/
31+
readonly onDidLayout: Event<IDimension>;
32+
2733
/**
2834
* The dimensions of the container.
2935
*/
@@ -64,12 +70,6 @@ export interface ILayoutService {
6470
*/
6571
readonly offset: ILayoutOffsetInfo;
6672

67-
/**
68-
* An event that is emitted when the container is layed out. The
69-
* event carries the dimensions of the container as part of it.
70-
*/
71-
readonly onDidLayout: Event<IDimension>;
72-
7373
/**
7474
* Focus the primary component of the container.
7575
*/

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle
1515
import { isNative } from 'vs/base/common/platform';
1616
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
1717
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
18-
import { IAuxiliaryWindowService } from 'vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService';
18+
import { Event } from 'vs/base/common/event';
1919

2020
export class TextInputActionsProvider extends Disposable implements IWorkbenchContribution {
2121

@@ -24,8 +24,7 @@ export class TextInputActionsProvider extends Disposable implements IWorkbenchCo
2424
constructor(
2525
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
2626
@IContextMenuService private readonly contextMenuService: IContextMenuService,
27-
@IClipboardService private readonly clipboardService: IClipboardService,
28-
@IAuxiliaryWindowService private readonly auxiliaryWindowService: IAuxiliaryWindowService
27+
@IClipboardService private readonly clipboardService: IClipboardService
2928
) {
3029
super();
3130

@@ -78,10 +77,10 @@ export class TextInputActionsProvider extends Disposable implements IWorkbenchCo
7877
private registerListeners(): void {
7978

8079
// Context menu support in input/textarea
81-
this._register(addDisposableListener(this.layoutService.container, 'contextmenu', e => this.onContextMenu(e)));
82-
this._register(this.auxiliaryWindowService.onDidOpenAuxiliaryWindow(({ window, disposables }) => {
83-
disposables.add(addDisposableListener(window.container, 'contextmenu', e => this.onContextMenu(e)));
84-
}));
80+
this._register(Event.runAndSubscribe(this.layoutService.onDidAddContainer, container => {
81+
const listener = addDisposableListener(container, 'contextmenu', e => this.onContextMenu(e));
82+
this._register(Event.filter(this.layoutService.onDidRemoveContainer, removed => removed === container, this._store)(() => listener.dispose()));
83+
}, this.layoutService.container));
8584
}
8685

8786
private onContextMenu(e: MouseEvent): void {

src/vs/workbench/browser/layout.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
6+
import { Disposable, DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
77
import { Event, Emitter } from 'vs/base/common/event';
88
import { EventType, addDisposableListener, getClientArea, Dimension, position, size, IDimension, isAncestorUsingFlowTo, computeScreenAwareSize, getActiveDocument, getWindows, getActiveWindow } from 'vs/base/browser/dom';
99
import { onDidChangeFullscreen, isFullscreen, isWCOEnabled } from 'vs/base/browser/browser';
@@ -47,6 +47,7 @@ import { IBannerService } from 'vs/workbench/services/banner/browser/bannerServi
4747
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';
4848
import { AuxiliaryBarPart } from 'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarPart';
4949
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
50+
import { IAuxiliaryWindowService } from 'vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService';
5051

5152
//#region Layout Implementation
5253

@@ -147,6 +148,12 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
147148
private readonly _onDidLayout = this._register(new Emitter<IDimension>());
148149
readonly onDidLayout = this._onDidLayout.event;
149150

151+
private readonly _onDidAddContainer = this._register(new Emitter<HTMLElement>());
152+
readonly onDidAddContainer = this._onDidAddContainer.event;
153+
154+
private readonly _onDidRemoveContainer = this._register(new Emitter<HTMLElement>());
155+
readonly onDidRemoveContainer = this._onDidRemoveContainer.event;
156+
150157
//#endregion
151158

152159
//#region Properties
@@ -227,6 +234,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
227234
private statusBarService!: IStatusbarService;
228235
private logService!: ILogService;
229236
private telemetryService!: ITelemetryService;
237+
private auxiliaryWindowService!: IAuxiliaryWindowService;
230238

231239
private state!: ILayoutState;
232240
private stateModel!: LayoutStateModel;
@@ -252,6 +260,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
252260
this.extensionService = accessor.get(IExtensionService);
253261
this.logService = accessor.get(ILogService);
254262
this.telemetryService = accessor.get(ITelemetryService);
263+
this.auxiliaryWindowService = accessor.get(IAuxiliaryWindowService);
255264

256265
// Parts
257266
this.editorService = accessor.get(IEditorService);
@@ -332,6 +341,13 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
332341
if (isWeb && typeof (navigator as any).windowControlsOverlay === 'object') {
333342
this._register(addDisposableListener((navigator as any).windowControlsOverlay, 'geometrychange', () => this.onDidChangeWCO()));
334343
}
344+
345+
// Auxiliary windows
346+
this._register(this.auxiliaryWindowService.onDidOpenAuxiliaryWindow(({ window, disposables }) => {
347+
this._onDidAddContainer.fire(window.container);
348+
349+
disposables.add(toDisposable(() => this._onDidRemoveContainer.fire(window.container)));
350+
}));
335351
}
336352

337353
private onMenubarToggled(visible: boolean): void {

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { IPathService } from 'vs/workbench/services/path/common/pathService';
3434
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
3535
import { ILifecycleService, LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
3636
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
37-
import { IAuxiliaryWindowService } from 'vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService';
3837

3938
export class HistoryService extends Disposable implements IHistoryService {
4039

@@ -58,8 +57,7 @@ export class HistoryService extends Disposable implements IHistoryService {
5857
@IWorkspacesService private readonly workspacesService: IWorkspacesService,
5958
@IInstantiationService private readonly instantiationService: IInstantiationService,
6059
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
61-
@IContextKeyService private readonly contextKeyService: IContextKeyService,
62-
@IAuxiliaryWindowService private readonly auxiliaryWindowService: IAuxiliaryWindowService
60+
@IContextKeyService private readonly contextKeyService: IContextKeyService
6361
) {
6462
super();
6563

@@ -113,14 +111,16 @@ export class HistoryService extends Disposable implements IHistoryService {
113111
mouseBackForwardSupportListener.clear();
114112

115113
if (this.configurationService.getValue(HistoryService.MOUSE_NAVIGATION_SETTING)) {
116-
this.doRegisterMouseNavigationListener(this.layoutService.container, mouseBackForwardSupportListener);
117-
118-
this._register(this.auxiliaryWindowService.onDidOpenAuxiliaryWindow(({ window, disposables }) => {
119-
const listenerDisposables = new DisposableStore();
120-
mouseBackForwardSupportListener.add(listenerDisposables);
121-
disposables.add(listenerDisposables);
122-
this.doRegisterMouseNavigationListener(window.container, listenerDisposables);
123-
}));
114+
115+
this._register(Event.runAndSubscribe(this.layoutService.onDidAddContainer, container => {
116+
const disposables = new DisposableStore();
117+
disposables.add(addDisposableListener(container, EventType.MOUSE_DOWN, e => this.onMouseDownOrUp(e, true)));
118+
disposables.add(addDisposableListener(container, EventType.MOUSE_UP, e => this.onMouseDownOrUp(e, false)));
119+
120+
this._register(Event.filter(this.layoutService.onDidRemoveContainer, removed => removed === container, this._store)(() => disposables.dispose()));
121+
122+
mouseBackForwardSupportListener.add(disposables);
123+
}, this.layoutService.container));
124124
}
125125
};
126126

@@ -133,11 +133,6 @@ export class HistoryService extends Disposable implements IHistoryService {
133133
handleMouseBackForwardSupport();
134134
}
135135

136-
private doRegisterMouseNavigationListener(container: HTMLElement, disposables: DisposableStore): void {
137-
disposables.add(addDisposableListener(container, EventType.MOUSE_DOWN, e => this.onMouseDownOrUp(e, true)));
138-
disposables.add(addDisposableListener(container, EventType.MOUSE_UP, e => this.onMouseDownOrUp(e, false)));
139-
}
140-
141136
private onMouseDownOrUp(event: MouseEvent, isMouseDown: boolean): void {
142137

143138
// Support to navigate in history when mouse buttons 4/5 are pressed

src/vs/workbench/services/layout/browser/layoutService.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ export interface IWorkbenchLayoutService extends ILayoutService {
129129
*/
130130
readonly onDidChangeNotificationsVisibility: Event<boolean>;
131131

132+
/**
133+
* An event that is emitted when a new container is added. This
134+
* can happen in multi-window environments.
135+
*/
136+
readonly onDidAddContainer: Event<HTMLElement>;
137+
138+
/**
139+
* An event that is emitted when a container is removed. This
140+
* can happen in multi-window environments.
141+
*/
142+
readonly onDidRemoveContainer: Event<HTMLElement>;
143+
132144
/**
133145
* True if a default layout with default editors was applied at startup
134146
*/

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,8 @@ export class TestLayoutService implements IWorkbenchLayoutService {
605605
onDidChangePartVisibility: Event<void> = Event.None;
606606
onDidLayout = Event.None;
607607
onDidChangeNotificationsVisibility = Event.None;
608+
onDidAddContainer = Event.None;
609+
onDidRemoveContainer = Event.None;
608610

609611
layout(): void { }
610612
isRestored(): boolean { return true; }

0 commit comments

Comments
 (0)