Skip to content

Commit

Permalink
Do not dispose dialogs on close (#14456)
Browse files Browse the repository at this point in the history
Fixes #12093

The about dialog in Theia is reopened and must no be disposed on close.

Contributed on behalf of STMicroelectronics
  • Loading branch information
tsmaeder authored Nov 21, 2024
1 parent 6bf4078 commit 77cba8c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
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

- [plugin] added stubs for the additional LanguageModel APIs [#14446](https://github.com/eclipse-theia/theia/pull/14446) - Contributed on behalf of STMicroelectronics
- [plugin] added support for ThemeColor property id [#14437](https://github.com/eclipse-theia/theia/pull/14437) - Contributed on behalf of STMicroelectronics
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

0 comments on commit 77cba8c

Please # to comment.