Skip to content

Commit

Permalink
dialogs contribution (microsoft#203947) (microsoft#204118)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero authored Feb 2, 2024
1 parent a54c753 commit 942ed9a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
19 changes: 12 additions & 7 deletions src/vs/workbench/browser/parts/dialogs/dialog.web.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import { BrowserDialogHandler } from 'vs/workbench/browser/parts/dialogs/dialogH
import { DialogService } from 'vs/workbench/services/dialogs/common/dialogService';
import { Disposable } from 'vs/base/common/lifecycle';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Lazy } from 'vs/base/common/lazy';

export class DialogHandlerContribution extends Disposable implements IWorkbenchContribution {

static readonly ID = 'workbench.contrib.dialogHandler';

private readonly model: IDialogsModel;
private readonly impl: IDialogHandler;
private readonly impl: Lazy<IDialogHandler>;

private currentDialog: IDialogViewItem | undefined;

Expand All @@ -36,7 +37,7 @@ export class DialogHandlerContribution extends Disposable implements IWorkbenchC
) {
super();

this.impl = new BrowserDialogHandler(logService, layoutService, keybindingService, instantiationService, productService, clipboardService);
this.impl = new Lazy(() => new BrowserDialogHandler(logService, layoutService, keybindingService, instantiationService, productService, clipboardService));

this.model = (this.dialogService as DialogService).model;

Expand All @@ -57,15 +58,15 @@ export class DialogHandlerContribution extends Disposable implements IWorkbenchC
try {
if (this.currentDialog.args.confirmArgs) {
const args = this.currentDialog.args.confirmArgs;
result = await this.impl.confirm(args.confirmation);
result = await this.impl.value.confirm(args.confirmation);
} else if (this.currentDialog.args.inputArgs) {
const args = this.currentDialog.args.inputArgs;
result = await this.impl.input(args.input);
result = await this.impl.value.input(args.input);
} else if (this.currentDialog.args.promptArgs) {
const args = this.currentDialog.args.promptArgs;
result = await this.impl.prompt(args.prompt);
result = await this.impl.value.prompt(args.prompt);
} else {
await this.impl.about();
await this.impl.value.about();
}
} catch (error) {
result = error;
Expand All @@ -77,4 +78,8 @@ export class DialogHandlerContribution extends Disposable implements IWorkbenchC
}
}

registerWorkbenchContribution2(DialogHandlerContribution.ID, DialogHandlerContribution, WorkbenchContributionInstantiation.BlockStartup);
registerWorkbenchContribution2(
DialogHandlerContribution.ID,
DialogHandlerContribution,
WorkbenchContributionInstantiation.BlockStartup // Block to allow for dialogs to show before restore finished
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import { NativeDialogHandler } from 'vs/workbench/electron-sandbox/parts/dialogs
import { DialogService } from 'vs/workbench/services/dialogs/common/dialogService';
import { Disposable } from 'vs/base/common/lifecycle';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Lazy } from 'vs/base/common/lazy';

export class DialogHandlerContribution extends Disposable implements IWorkbenchContribution {

static readonly ID = 'workbench.contrib.dialogHandler';

private nativeImpl: IDialogHandler;
private browserImpl: IDialogHandler;
private nativeImpl: Lazy<IDialogHandler>;
private browserImpl: Lazy<IDialogHandler>;

private model: IDialogsModel;
private currentDialog: IDialogViewItem | undefined;
Expand All @@ -42,8 +43,8 @@ export class DialogHandlerContribution extends Disposable implements IWorkbenchC
) {
super();

this.browserImpl = new BrowserDialogHandler(logService, layoutService, keybindingService, instantiationService, productService, clipboardService);
this.nativeImpl = new NativeDialogHandler(logService, nativeHostService, productService, clipboardService);
this.browserImpl = new Lazy(() => new BrowserDialogHandler(logService, layoutService, keybindingService, instantiationService, productService, clipboardService));
this.nativeImpl = new Lazy(() => new NativeDialogHandler(logService, nativeHostService, productService, clipboardService));

this.model = (this.dialogService as DialogService).model;

Expand All @@ -67,30 +68,30 @@ export class DialogHandlerContribution extends Disposable implements IWorkbenchC
if (this.currentDialog.args.confirmArgs) {
const args = this.currentDialog.args.confirmArgs;
result = (this.useCustomDialog || args?.confirmation.custom) ?
await this.browserImpl.confirm(args.confirmation) :
await this.nativeImpl.confirm(args.confirmation);
await this.browserImpl.value.confirm(args.confirmation) :
await this.nativeImpl.value.confirm(args.confirmation);
}

// Input (custom only)
else if (this.currentDialog.args.inputArgs) {
const args = this.currentDialog.args.inputArgs;
result = await this.browserImpl.input(args.input);
result = await this.browserImpl.value.input(args.input);
}

// Prompt
else if (this.currentDialog.args.promptArgs) {
const args = this.currentDialog.args.promptArgs;
result = (this.useCustomDialog || args?.prompt.custom) ?
await this.browserImpl.prompt(args.prompt) :
await this.nativeImpl.prompt(args.prompt);
await this.browserImpl.value.prompt(args.prompt) :
await this.nativeImpl.value.prompt(args.prompt);
}

// About
else {
if (this.useCustomDialog) {
await this.browserImpl.about();
await this.browserImpl.value.about();
} else {
await this.nativeImpl.about();
await this.nativeImpl.value.about();
}
}
} catch (error) {
Expand All @@ -107,4 +108,8 @@ export class DialogHandlerContribution extends Disposable implements IWorkbenchC
}
}

registerWorkbenchContribution2(DialogHandlerContribution.ID, DialogHandlerContribution, WorkbenchContributionInstantiation.BlockStartup);
registerWorkbenchContribution2(
DialogHandlerContribution.ID,
DialogHandlerContribution,
WorkbenchContributionInstantiation.BlockStartup // Block to allow for dialogs to show before restore finished
);

0 comments on commit 942ed9a

Please sign in to comment.