Skip to content

Commit c72dd8c

Browse files
committed
aux window - introduce event for new aux parts
1 parent 7f76fab commit c72dd8c

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

src/vs/workbench/browser/layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
12411241
this.focusPart(Parts.EDITOR_PART);
12421242
} else {
12431243
// auxiliary window
1244-
this.editorGroupService.getPart(activeContainer)?.activeGroup.focus();
1244+
this.editorGroupService.getPart(activeContainer).activeGroup.focus();
12451245
}
12461246
}
12471247

src/vs/workbench/browser/parts/editor/editorPart.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,7 @@ export class AuxiliaryEditorPart extends EditorPart implements IAuxiliaryEditorP
13981398
readonly onWillClose = this._onWillClose.event;
13991399

14001400
constructor(
1401+
readonly windowId: number,
14011402
editorPartsView: IEditorPartsView,
14021403
groupsLabel: string,
14031404
@IInstantiationService instantiationService: IInstantiationService,

src/vs/workbench/browser/parts/editor/editorParts.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export class EditorParts extends Disposable implements IEditorGroupsService, IEd
4040

4141
//#region Auxiliary Editor Parts
4242

43+
private readonly _onDidCreateAuxiliaryEditorPart = this._register(new Emitter<{ readonly part: IAuxiliaryEditorPart; readonly disposables: DisposableStore }>());
44+
readonly onDidCreateAuxiliaryEditorPart = this._onDidCreateAuxiliaryEditorPart.event;
45+
4346
async createAuxiliaryEditorPart(options?: IAuxiliaryWindowOpenOptions): Promise<IAuxiliaryEditorPart> {
4447
const disposables = new DisposableStore();
4548

@@ -50,7 +53,7 @@ export class EditorParts extends Disposable implements IEditorGroupsService, IEd
5053
partContainer.setAttribute('role', 'main');
5154
auxiliaryWindow.container.appendChild(partContainer);
5255

53-
const editorPart = disposables.add(this.instantiationService.createInstance(AuxiliaryEditorPart, this, this.getGroupsLabel(this._parts.size)));
56+
const editorPart = disposables.add(this.instantiationService.createInstance(AuxiliaryEditorPart, auxiliaryWindow.window.vscodeWindowId, this, this.getGroupsLabel(this._parts.size)));
5457
disposables.add(this.registerEditorPart(editorPart));
5558
editorPart.create(partContainer, { restorePreviousState: false });
5659
disposables.add(this.instantiationService.createInstance(WindowTitle, auxiliaryWindow.window, editorPart));
@@ -72,6 +75,9 @@ export class EditorParts extends Disposable implements IEditorGroupsService, IEd
7275

7376
this._onDidAddGroup.fire(editorPart.activeGroup);
7477

78+
const eventDisposables = disposables.add(new DisposableStore());
79+
this._onDidCreateAuxiliaryEditorPart.fire({ part: editorPart, disposables: eventDisposables });
80+
7581
return editorPart;
7682
}
7783

src/vs/workbench/electron-sandbox/window.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'
7070
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
7171
import { IUtilityProcessWorkerWorkbenchService } from 'vs/workbench/services/utilityProcess/electron-sandbox/utilityProcessWorkerWorkbenchService';
7272
import { registerWindowDriver } from 'vs/workbench/services/driver/electron-sandbox/driver';
73-
import { IAuxiliaryWindowService } from 'vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService';
7473
import { mainWindow } from 'vs/base/browser/window';
7574
import { BaseWindow } from 'vs/workbench/browser/window';
7675

@@ -125,8 +124,7 @@ export class NativeWindow extends BaseWindow {
125124
@IBannerService private readonly bannerService: IBannerService,
126125
@IUriIdentityService private readonly uriIdentityService: IUriIdentityService,
127126
@IPreferencesService private readonly preferencesService: IPreferencesService,
128-
@IUtilityProcessWorkerWorkbenchService private readonly utilityProcessWorkerWorkbenchService: IUtilityProcessWorkerWorkbenchService,
129-
@IAuxiliaryWindowService private readonly auxiliaryWindowService: IAuxiliaryWindowService
127+
@IUtilityProcessWorkerWorkbenchService private readonly utilityProcessWorkerWorkbenchService: IUtilityProcessWorkerWorkbenchService
130128
) {
131129
super(mainWindow);
132130

@@ -364,12 +362,9 @@ export class NativeWindow extends BaseWindow {
364362

365363
this._register(this.mainPartEditorService.onDidActiveEditorChange(() => updateRepresentedFilename(this.mainPartEditorService, undefined)));
366364

367-
this._register(this.auxiliaryWindowService.onDidOpenAuxiliaryWindow(({ window, disposables }) => {
368-
const auxiliaryWindowEditorPart = this.editorGroupService.getPart(window.container);
369-
if (auxiliaryWindowEditorPart) {
370-
const auxiliaryEditorService = this.editorService.createScoped(auxiliaryWindowEditorPart, disposables);
371-
disposables.add(auxiliaryEditorService.onDidActiveEditorChange(() => updateRepresentedFilename(auxiliaryEditorService, window.window.vscodeWindowId)));
372-
}
365+
this._register(this.editorGroupService.onDidCreateAuxiliaryEditorPart(({ part, disposables }) => {
366+
const auxiliaryEditorService = this.editorService.createScoped(part, disposables);
367+
disposables.add(auxiliaryEditorService.onDidActiveEditorChange(() => updateRepresentedFilename(auxiliaryEditorService, part.windowId)));
373368
}));
374369
}
375370

src/vs/workbench/services/editor/common/editorGroupsService.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ export interface IEditorPart extends IEditorGroupsContainer {
466466

467467
export interface IAuxiliaryEditorPart extends IEditorPart {
468468

469+
/**
470+
* The identifier of the window the auxiliary editor part is contained in.
471+
*/
472+
readonly windowId: number;
473+
469474
/**
470475
* Close this auxiliary editor part after moving all
471476
* editors of all groups back to the main editor part.
@@ -480,6 +485,11 @@ export interface IEditorGroupsService extends IEditorGroupsContainer {
480485

481486
readonly _serviceBrand: undefined;
482487

488+
/**
489+
* An event for when a new auxiliary editor part is created.
490+
*/
491+
readonly onDidCreateAuxiliaryEditorPart: Event<{ readonly part: IAuxiliaryEditorPart; readonly disposables: DisposableStore }>;
492+
483493
/**
484494
* Provides access to the currently active editor part.
485495
*/
@@ -503,7 +513,7 @@ export interface IEditorGroupsService extends IEditorGroupsContainer {
503513
/**
504514
* Get the editor part that is rooted in the provided container.
505515
*/
506-
getPart(container: unknown /* HTMLElement */): IEditorPart | undefined;
516+
getPart(container: unknown /* HTMLElement */): IEditorPart;
507517

508518
/**
509519
* Opens a new window with a full editor part instantiated

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ export class TestEditorGroupsService implements IEditorGroupsService {
825825

826826
readonly parts: readonly IEditorPart[] = [this];
827827

828+
onDidCreateAuxiliaryEditorPart: Event<{ readonly part: IAuxiliaryEditorPart; readonly disposables: DisposableStore }> = Event.None;
828829
onDidChangeActiveGroup: Event<IEditorGroup> = Event.None;
829830
onDidActivateGroup: Event<IEditorGroup> = Event.None;
830831
onDidAddGroup: Event<IEditorGroup> = Event.None;
@@ -1757,6 +1758,8 @@ export class TestEditorPart extends MainEditorPart implements IEditorGroupsServi
17571758
readonly mainPart = this;
17581759
readonly parts: readonly IEditorPart[] = [this];
17591760

1761+
readonly onDidCreateAuxiliaryEditorPart: Event<{ readonly part: IAuxiliaryEditorPart; readonly disposables: DisposableStore }> = Event.None;
1762+
17601763
testSaveState(): void {
17611764
return super.saveState();
17621765
}

0 commit comments

Comments
 (0)