Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not dispose dialogs on close #14456

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- [Previous Changelogs](https://github.com/eclipse-theia/theia/tree/master/doc/changelogs/)

<!-- ## 1.56.0 - not yet released -->
<a name="breaking_changes_1.56.0">[Breaking Changes:](#breaking_changes_1.56.0)</a>
- [core] Do not dispose dialogs on close - [#14456](https://github.com/eclipse-theia/theia/pull/14456) - Contributed on behalf of STMicroelectronics

## 1.55.0 - 10/31/2024

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
}

protected async openAbout(): Promise<void> {
this.aboutDialog.open();
this.aboutDialog.open(false);
}

protected shouldPreventClose = false;
Expand Down
20 changes: 18 additions & 2 deletions packages/core/src/browser/dialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,15 @@ export abstract class AbstractDialog<T> extends BaseWidget {
}
}

open(): Promise<T | undefined> {
open(disposeOnResolve: boolean = true): Promise<T | undefined> {
if (this.resolve) {
return Promise.reject(new Error('The dialog is already opened.'));
}
this.activeElement = this.node.ownerDocument.activeElement as HTMLElement;
return new Promise<T | undefined>((resolve, reject) => {
this.resolve = resolve;
this.resolve = value => {
resolve(value);
};
this.reject = reject;
this.toDisposeOnDetach.push(Disposable.create(() => {
this.resolve = undefined;
Expand All @@ -273,9 +275,23 @@ export abstract class AbstractDialog<T> extends BaseWidget {

Widget.attach(this, this.node.ownerDocument.body);
this.activate();
}).finally(() => {
if (disposeOnResolve) {
this.dispose();
}
});
}

protected override onCloseRequest(msg: Message): void {
// super.onCloseRequest() would automatically dispose the dialog, which we don't want because we're reusing it
if (this.parent) {
// eslint-disable-next-line no-null/no-null
this.parent = null;
} else if (this.isAttached) {
Widget.detach(this);
}
}

override close(): void {
if (this.resolve) {
if (this.activeElement) {
Expand Down
Loading