8000 feat(dialog): add onBeforeButtonClick hook to support validation before closing dialog by ensorrow · Pull Request #251900 · microsoft/vscode · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(dialog): add onBeforeButtonClick hook to support validation before closing dialog #251900

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Fi 8000 lter 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
24 changes: 17 additions & 7 deletions src/vs/base/browser/ui/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface IDialogOptions {
readonly checkboxStyles: ICheckboxStyles;
readonly inputBoxStyles: IInputBoxStyles;
readonly dialogStyles: IDialogStyles;
readonly onBeforeButtonClick?: (index: number, values?: string[], checkboxChecked?: boolean) => boolean | Promise<boolean>;
}

export interface IDialogResult {
Expand Down Expand Up @@ -269,11 +270,20 @@ export class Dialog extends Disposable {
const buttonBar = this.buttonBar = this._register(new ButtonBar(this.buttonsContainer, { alignment: this.options?.alignment === DialogContentsAlignment.Vertical ? ButtonBarAlignment.Vertical : ButtonBarAlignment.Horizontal }));
const buttonMap = this.rearrangeButtons(this.buttons, this.options.cancelId);

const number) => {
const (index: number) => {
const values = this.inputs.length > 0 ? this.inputs.map(input => input.value) : undefined;
const checkboxChecked = this.checkbox ? this.checkbox.checked : undefined;
const button = buttonMap[index].index;
if (this.options.onBeforeButtonClick) {
const canClose = await this.options.onBeforeButtonClick(button, values, checkboxChecked);
if (!canClose) {
return;
}
}
resolve({
button: buttonMap[index].index,
checkboxChecked: this.checkbox ? this.checkbox.checked : undefined,
values: this.inputs.length > 0 ? this.inputs.map(input => input.value) : undefined
button,
checkboxChecked,
values
});
};

Expand All @@ -294,7 +304,7 @@ export class Dialog extends Disposable {
run: async () => {
await action.run();

onButtonClick(index);
await onButtonClick(index);
}
}))
}));
Expand All @@ -314,12 +324,12 @@ export class Dialog extends Disposable {
button.description = buttonOptions?.sublabel;
}
}
this._register(button.onDidClick(e => {
this._register(button.onDidClick(async e => {
if (e) {
EventHelper.stop(e);
}

onButtonClick(index);
await onButtonClick(index);
}));
});

Expand Down
0