Skip to content

Commit 87b65b9

Browse files
committed
dialogService: show should return an IShowResult
1 parent 631e805 commit 87b65b9

17 files changed

Lines changed: 83 additions & 67 deletions

File tree

src/vs/editor/standalone/browser/simpleServices.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { CommandsRegistry, ICommand, ICommandEvent, ICommandHandler, ICommandSer
2828
import { IConfigurationChangeEvent, IConfigurationData, IConfigurationOverrides, IConfigurationService, IConfigurationModel } from 'vs/platform/configuration/common/configuration';
2929
import { Configuration, ConfigurationModel, DefaultConfigurationModel } from 'vs/platform/configuration/common/configurationModels';
3030
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
31-
import { IConfirmation, IConfirmationResult, IDialogOptions, IDialogService } from 'vs/platform/dialogs/common/dialogs';
31+
import { IConfirmation, IConfirmationResult, IDialogOptions, IDialogService, IShowResult } from 'vs/platform/dialogs/common/dialogs';
3232
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
3333
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
3434
import { IKeybindingEvent, IKeyboardEvent, KeybindingSource } from 'vs/platform/keybinding/common/keybinding';
@@ -183,8 +183,8 @@ export class SimpleDialogService implements IDialogService {
183183
return Promise.resolve(window.confirm(messageText));
184184
}
185185

186-
public show(severity: Severity, message: string, buttons: string[], options?: IDialogOptions): Promise<number> {
187-
return Promise.resolve(0);
186+
public show(severity: Severity, message: string, buttons: string[], options?: IDialogOptions): Promise<IShowResult> {
187+
return Promise.resolve({ choice: 0 });
188188
}
189189
}
190190

src/vs/platform/dialogs/browser/dialogService.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as nls from 'vs/nls';
7-
import { IDialogService, IDialogOptions, IConfirmation, IConfirmationResult, DialogType } from 'vs/platform/dialogs/common/dialogs';
7+
import { IDialogService, IDialogOptions, IConfirmation, IConfirmationResult, DialogType, IShowResult } from 'vs/platform/dialogs/common/dialogs';
88
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
99
import { ILogService } from 'vs/platform/log/common/log';
1010
import Severity from 'vs/base/common/severity';
@@ -78,7 +78,7 @@ export class DialogService implements IDialogService {
7878
return (severity === Severity.Info) ? 'question' : (severity === Severity.Error) ? 'error' : (severity === Severity.Warning) ? 'warning' : 'none';
7979
}
8080

81-
async show(severity: Severity, message: string, buttons: string[], options?: IDialogOptions): Promise<number> {
81+
async show(severity: Severity, message: string, buttons: string[], options?: IDialogOptions): Promise<IShowResult> {
8282
this.logService.trace('DialogService#show', message);
8383

8484
const dialogDisposables = new DisposableStore();
@@ -106,6 +106,8 @@ export class DialogService implements IDialogService {
106106
const result = await dialog.show();
107107
dialogDisposables.dispose();
108108

109-
return result.button;
109+
return {
110+
choice: result.button
111+
};
110112
}
111113
}

src/vs/platform/dialogs/common/dialogs.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ export interface IConfirmationResult {
4141
checkboxChecked?: boolean;
4242
}
4343

44+
export interface IShowResult {
45+
46+
/**
47+
* Selected choice index. If the user refused to choose,
48+
* then a promise with index of `cancelId` option is returned. If there is no such
49+
* option then promise with index `0` is returned.
50+
*/
51+
choice: number;
52+
53+
/**
54+
* This will only be defined if the confirmation was created
55+
* with the checkbox option defined.
56+
*/
57+
checkboxChecked?: boolean;
58+
}
59+
4460
export interface IPickAndOpenOptions {
4561
forceNewWindow?: boolean;
4662
defaultUri?: URI;
@@ -151,7 +167,7 @@ export interface IDialogService {
151167
* then a promise with index of `cancelId` option is returned. If there is no such
152168
* option then promise with index `0` is returned.
153169
*/
154-
show(severity: Severity, message: string, buttons: string[], options?: IDialogOptions): Promise<number>;
170+
show(severity: Severity, message: string, buttons: string[], options?: IDialogOptions): Promise<IShowResult>;
155171
}
156172

157173
export const IFileDialogService = createDecorator<IFileDialogService>('fileDialogService');

src/vs/platform/dialogs/node/dialogIpc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
7-
import { IDialogService, IConfirmation, IConfirmationResult } from 'vs/platform/dialogs/common/dialogs';
7+
import { IDialogService, IConfirmation, IConfirmationResult, IShowResult } from 'vs/platform/dialogs/common/dialogs';
88
import Severity from 'vs/base/common/severity';
99
import { Event } from 'vs/base/common/event';
1010

@@ -31,11 +31,11 @@ export class DialogChannelClient implements IDialogService {
3131

3232
constructor(private channel: IChannel) { }
3333

34-
show(severity: Severity, message: string, options: string[]): Promise<number> {
34+
show(severity: Severity, message: string, options: string[]): Promise<IShowResult> {
3535
return this.channel.call('show', [severity, message, options]);
3636
}
3737

3838
confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
3939
return this.channel.call('confirm', [confirmation]);
4040
}
41-
}
41+
}

src/vs/workbench/api/browser/mainThreadMessageService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class MainThreadMessageService implements MainThreadMessageServiceShape {
9797
});
9898
}
9999

100-
private _showModalMessage(severity: Severity, message: string, commands: { title: string; isCloseAffordance: boolean; handle: number; }[]): Promise<number | undefined> {
100+
private async _showModalMessage(severity: Severity, message: string, commands: { title: string; isCloseAffordance: boolean; handle: number; }[]): Promise<number | undefined> {
101101
let cancelId: number | undefined = undefined;
102102

103103
const buttons = commands.map((command, index) => {
@@ -118,7 +118,7 @@ export class MainThreadMessageService implements MainThreadMessageServiceShape {
118118
cancelId = buttons.length - 1;
119119
}
120120

121-
return this._dialogService.show(severity, message, buttons, { cancelId })
122-
.then(result => result === commands.length ? undefined : commands[result].handle);
121+
const { choice } = await this._dialogService.show(severity, message, buttons, { cancelId });
122+
return choice === commands.length ? undefined : commands[choice].handle;
123123
}
124124
}

src/vs/workbench/browser/web.simpleservices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,9 @@ export class SimpleWindowsService implements IWindowsService {
632632
navigator.userAgent
633633
);
634634

635-
const result = await this.dialogService.show(Severity.Info, this.productService.nameLong, [localize('copy', "Copy"), localize('ok', "OK")], { detail });
635+
const { choice } = await this.dialogService.show(Severity.Info, this.productService.nameLong, [localize('copy', "Copy"), localize('ok', "OK")], { detail });
636636

637-
if (result === 0) {
637+
if (choice === 0) {
638638
this.clipboardService.writeText(detail);
639639
}
640640
}

src/vs/workbench/contrib/cli/node/cli.contribution.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ class InstallAction extends Action {
101101
return new Promise<void>((resolve, reject) => {
102102
const buttons = [nls.localize('ok', "OK"), nls.localize('cancel2', "Cancel")];
103103

104-
this.dialogService.show(Severity.Info, nls.localize('warnEscalation', "Code will now prompt with 'osascript' for Administrator privileges to install the shell command."), buttons, { cancelId: 1 }).then(choice => {
105-
switch (choice) {
104+
this.dialogService.show(Severity.Info, nls.localize('warnEscalation', "Code will now prompt with 'osascript' for Administrator privileges to install the shell command."), buttons, { cancelId: 1 }).then(result => {
105+
switch (result.choice) {
106106
case 0 /* OK */:
107107
const command = 'osascript -e "do shell script \\"mkdir -p /usr/local/bin && ln -sf \'' + getSource() + '\' \'' + this.target + '\'\\" with administrator privileges"';
108108

@@ -165,23 +165,22 @@ class UninstallAction extends Action {
165165
}
166166

167167
private deleteSymlinkAsAdmin(): Promise<void> {
168-
return new Promise<void>((resolve, reject) => {
168+
return new Promise<void>(async (resolve, reject) => {
169169
const buttons = [nls.localize('ok', "OK"), nls.localize('cancel2', "Cancel")];
170170

171-
this.dialogService.show(Severity.Info, nls.localize('warnEscalationUninstall', "Code will now prompt with 'osascript' for Administrator privileges to uninstall the shell command."), buttons, { cancelId: 1 }).then(choice => {
172-
switch (choice) {
173-
case 0 /* OK */:
174-
const command = 'osascript -e "do shell script \\"rm \'' + this.target + '\'\\" with administrator privileges"';
175-
176-
promisify(cp.exec)(command, {})
177-
.then(undefined, _ => Promise.reject(new Error(nls.localize('cantUninstall', "Unable to uninstall the shell command '{0}'.", this.target))))
178-
.then(resolve, reject);
179-
break;
180-
case 1 /* Cancel */:
181-
reject(new Error(nls.localize('aborted', "Aborted")));
182-
break;
183-
}
184-
});
171+
const { choice } = await this.dialogService.show(Severity.Info, nls.localize('warnEscalationUninstall', "Code will now prompt with 'osascript' for Administrator privileges to uninstall the shell command."), buttons, { cancelId: 1 });
172+
switch (choice) {
173+
case 0 /* OK */:
174+
const command = 'osascript -e "do shell script \\"rm \'' + this.target + '\'\\" with administrator privileges"';
175+
176+
promisify(cp.exec)(command, {})
177+
.then(undefined, _ => Promise.reject(new Error(nls.localize('cantUninstall', "Unable to uninstall the shell command '{0}'.", this.target))))
178+
.then(resolve, reject);
179+
break;
180+
case 1 /* Cancel */:
181+
reject(new Error(nls.localize('aborted', "Aborted")));
182+
break;
183+
}
185184
});
186185
}
187186
}

src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class DebugEditorContribution implements IDebugEditorContribution {
168168
}
169169

170170
private registerListeners(): void {
171-
this.toDispose.push(this.editor.onMouseDown((e: IEditorMouseEvent) => {
171+
this.toDispose.push(this.editor.onMouseDown(async (e: IEditorMouseEvent) => {
172172
const data = e.target.detail as IMarginData;
173173
const model = this.editor.getModel();
174174
if (!e.target.position || !model || e.target.type !== MouseTargetType.GUTTER_GLYPH_MARGIN || data.isAfterLines || !this.marginFreeFromNonDebugDecorations(e.target.position.lineNumber)) {
@@ -213,18 +213,18 @@ export class DebugEditorContribution implements IDebugEditorContribution {
213213
logPoint ? nls.localize('message', "message") : nls.localize('condition', "condition")
214214
);
215215

216-
this.dialogService.show(severity.Info, disable ? disabling : enabling, [
216+
const { choice } = await this.dialogService.show(severity.Info, disable ? disabling : enabling, [
217217
nls.localize('removeLogPoint', "Remove {0}", breakpointType),
218218
nls.localize('disableLogPoint', "{0} {1}", disable ? nls.localize('disable', "Disable") : nls.localize('enable', "Enable"), breakpointType),
219219
nls.localize('cancel', "Cancel")
220-
], { cancelId: 2 }).then(choice => {
221-
if (choice === 0) {
222-
breakpoints.forEach(bp => this.debugService.removeBreakpoints(bp.getId()));
223-
}
224-
if (choice === 1) {
225-
breakpoints.forEach(bp => this.debugService.enableOrDisableBreakpoints(!disable, bp));
226-
}
227-
});
220+
], { cancelId: 2 });
221+
222+
if (choice === 0) {
223+
breakpoints.forEach(bp => this.debugService.removeBreakpoints(bp.getId()));
224+
}
225+
if (choice === 1) {
226+
breakpoints.forEach(bp => this.debugService.enableOrDisableBreakpoints(!disable, bp));
227+
}
228228
} else {
229229
breakpoints.forEach(bp => this.debugService.removeBreakpoints(bp.getId()));
230230
}

src/vs/workbench/contrib/debug/browser/debugService.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -670,16 +670,15 @@ export class DebugService implements IDebugService {
670670
return Promise.resolve(config);
671671
}
672672

673-
private showError(message: string, errorActions: ReadonlyArray<IAction> = []): Promise<void> {
673+
private async showError(message: string, errorActions: ReadonlyArray<IAction> = []): Promise<void> {
674674
const configureAction = this.instantiationService.createInstance(debugactions.ConfigureAction, debugactions.ConfigureAction.ID, debugactions.ConfigureAction.LABEL);
675675
const actions = [...errorActions, configureAction];
676-
return this.dialogService.show(severity.Error, message, actions.map(a => a.label).concat(nls.localize('cancel', "Cancel")), { cancelId: actions.length }).then(choice => {
677-
if (choice < actions.length) {
678-
return actions[choice].run();
679-
}
676+
const { choice } = await this.dialogService.show(severity.Error, message, actions.map(a => a.label).concat(nls.localize('cancel', "Cancel")), { cancelId: actions.length });
677+
if (choice < actions.length) {
678+
return actions[choice].run();
679+
}
680680

681-
return undefined;
682-
});
681+
return undefined;
683682
}
684683

685684
//---- task management

src/vs/workbench/contrib/files/browser/views/explorerViewer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ export class FileDragAndDrop implements ITreeDragAndDrop<ExplorerItem> {
630630
: localize('dropFolder', "Do you want to copy '{0}' or add '{0}' as a folder to the workspace?", basename(folders[0].uri));
631631
}
632632

633-
const choice = await this.dialogService.show(Severity.Info, message, buttons);
633+
const { choice } = await this.dialogService.show(Severity.Info, message, buttons);
634634
if (choice === buttons.length - 3) {
635635
return this.workspaceEditingService.addFolders(folders);
636636
}

0 commit comments

Comments
 (0)