aux window - merge groups back to main on window close (#198239)

This commit is contained in:
Benjamin Pasero 2023-11-14 20:52:45 +01:00 committed by GitHub
parent bee13ad3bf
commit ba035ccf38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 24 deletions

View file

@ -174,16 +174,13 @@ function validateEditorPartOptions(options: IEditorPartOptions): IEditorPartOpti
*/
export interface IEditorPartsView {
/**
* An array of all editor groups across all editor parts.
*/
readonly groups: IEditorGroupView[];
readonly mainPart: IEditorGroupsView;
/**
* Get the group based on an identifier across all opened
* editor parts.
*/
readonly activeGroup: IEditorGroupView;
readonly groups: IEditorGroupView[];
getGroup(identifier: GroupIdentifier): IEditorGroupView | undefined;
mergeGroup(group: IEditorGroupView, target: IEditorGroupView, options?: IMergeGroupOptions): IEditorGroupView;
}
/**

View file

@ -152,7 +152,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupsView {
private readonly gridWidgetView = this._register(new GridWidgetView<IEditorGroupView>());
constructor(
private readonly editorPartsView: IEditorPartsView,
protected readonly editorPartsView: IEditorPartsView,
id: string,
private readonly groupsLabel: string,
public readonly isAuxiliary: boolean,
@ -1413,7 +1413,7 @@ export class AuxiliaryEditorPart extends EditorPart implements IAuxiliaryEditorP
// Close aux window when last group removed
const groupView = this.assertGroupView(group);
if (this.count === 1 && this.activeGroup === groupView) {
this.close();
this.doClose(false /* do not merge any groups to main part */);
}
// Otherwise delegate to parent implementation
@ -1426,8 +1426,17 @@ export class AuxiliaryEditorPart extends EditorPart implements IAuxiliaryEditorP
return; // TODO support auxiliary editor state
}
async close(): Promise<void> {
// TODO this needs full support for closing all editors, handling vetos and showing dialogs
close(): void {
this.doClose(true /* merge all groups to main part */);
}
private doClose(mergeGroupsToMainPart: boolean): void {
if (mergeGroupsToMainPart) {
for (const group of this.groups) {
this.editorPartsView.mergeGroup(group, this.editorPartsView.mainPart.activeGroup);
}
}
this._onDidClose.fire();
}
}

View file

@ -43,7 +43,6 @@ export class EditorParts extends Disposable implements IEditorGroupsService, IEd
const disposables = new DisposableStore();
const auxiliaryWindow = disposables.add(await this.auxiliaryWindowService.open(options));
disposables.add(Event.once(auxiliaryWindow.onDidClose)(() => disposables.dispose()));
const partContainer = document.createElement('div');
partContainer.classList.add('part', 'editor');
@ -52,14 +51,20 @@ export class EditorParts extends Disposable implements IEditorGroupsService, IEd
const editorPart = disposables.add(this.instantiationService.createInstance(AuxiliaryEditorPart, this, this.getGroupsLabel(this._parts.size)));
disposables.add(this.registerEditorPart(editorPart));
editorPart.create(partContainer, { restorePreviousState: false });
disposables.add(this.instantiationService.createInstance(WindowTitle, auxiliaryWindow.window, editorPart));
disposables.add(Event.once(auxiliaryWindow.onWillClose)(() => {
if (disposables.isDisposed) {
return; // the close happened as part of an earlier dispose call
}
editorPart.close();
disposables.dispose();
}));
disposables.add(Event.once(editorPart.onDidClose)(() => disposables.dispose()));
disposables.add(Event.once(this.lifecycleService.onDidShutdown)(() => disposables.dispose()));
editorPart.create(partContainer, { restorePreviousState: false });
disposables.add(this.instantiationService.createInstance(WindowTitle, auxiliaryWindow.window, editorPart));
disposables.add(auxiliaryWindow.onDidLayout(dimension => editorPart.layout(dimension.width, dimension.height, 0, 0)));
auxiliaryWindow.layout();

View file

@ -44,7 +44,7 @@ export interface IAuxiliaryWindowService {
export interface IAuxiliaryWindow extends IDisposable {
readonly onDidLayout: Event<Dimension>;
readonly onDidClose: Event<void>;
readonly onWillClose: Event<void>;
readonly window: CodeWindow;
readonly container: HTMLElement;
@ -57,8 +57,8 @@ class AuxiliaryWindow extends BaseWindow implements IAuxiliaryWindow {
private readonly _onDidLayout = this._register(new Emitter<Dimension>());
readonly onDidLayout = this._onDidLayout.event;
private readonly _onDidClose = this._register(new Emitter<void>());
readonly onDidClose = this._onDidClose.event;
private readonly _onWillClose = this._register(new Emitter<void>());
readonly onWillClose = this._onWillClose.event;
private readonly _onWillDispose = this._register(new Emitter<void>());
readonly onWillDispose = this._onWillDispose.event;
@ -70,8 +70,8 @@ class AuxiliaryWindow extends BaseWindow implements IAuxiliaryWindow {
}
private registerListeners(): void {
this._register(addDisposableListener(this.window, 'unload', () => {
this._onDidClose.fire();
this._register(addDisposableListener(this.window, 'beforeunload', () => {
this._onWillClose.fire();
}));
this._register(addDisposableListener(this.window, 'unhandledrejection', e => {

View file

@ -467,9 +467,10 @@ export interface IEditorPart extends IEditorGroupsContainer {
export interface IAuxiliaryEditorPart extends IEditorPart {
/**
* Close this auxiliary editor part and free up associated resources.
* Close this auxiliary editor part after moving all
* editors of all groups back to the main editor part.
*/
close(): Promise<void>;
close(): void;
}
/**