Add onClosed event to ModelView dialogs (#17531)

* Add onClosed event to ModelView dialogs

* Use defined type

* Fix compile

* fix tests

* fix tests2

* Remove unused
This commit is contained in:
Charles Gagnon
2021-10-28 20:53:20 -07:00
committed by GitHub
parent 62b6e781ce
commit 82805638ad
12 changed files with 82 additions and 15 deletions

View File

@@ -29,6 +29,7 @@ import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
import { ILogService } from 'vs/platform/log/common/log';
import { attachButtonStyler } from 'vs/platform/theme/common/styler';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { Emitter } from 'vs/base/common/event';
export enum MessageLevel {
Error = 0,
@@ -147,6 +148,9 @@ export abstract class Modal extends Disposable implements IThemable {
private _modalShowingContext: IContextKey<Array<string>>;
private readonly _staticKey: string;
private _onClosed = new Emitter<HideReason>();
public onClosed = this._onClosed.event;
/**
* Get the back button, only available after render and if the hasBackButton option is true
*/
@@ -458,7 +462,7 @@ export abstract class Modal extends Disposable implements IThemable {
}
}));
this.disposableStore.add(trapKeyboardNavigation(this._modalDialog!));
this.disposableStore.add(DOM.addDisposableListener(window, DOM.EventType.RESIZE, (e: Event) => {
this.disposableStore.add(DOM.addDisposableListener(window, DOM.EventType.RESIZE, e => {
this.layout(DOM.getTotalHeight(this._modalBodySection!));
}));
@@ -476,7 +480,7 @@ export abstract class Modal extends Disposable implements IThemable {
/**
* Hides the modal and removes key listeners
*/
protected hide(reason?: HideReason, currentPageName?: string): void {
protected hide(reason: HideReason = 'close', currentPageName?: string): void {
this._modalShowingContext.get()!.pop();
this._bodyContainer!.remove();
this.disposableStore.clear();
@@ -488,6 +492,7 @@ export abstract class Modal extends Disposable implements IThemable {
})
.send();
this.restoreKeyboardFocus();
this._onClosed.fire(reason);
}
private restoreKeyboardFocus() {