diff --git a/src/vs/editor/standalone/browser/simpleServices.ts b/src/vs/editor/standalone/browser/simpleServices.ts index 3feb60de1c3..0454d044852 100644 --- a/src/vs/editor/standalone/browser/simpleServices.ts +++ b/src/vs/editor/standalone/browser/simpleServices.ts @@ -257,6 +257,10 @@ export class SimpleDialogService implements IDialogService { return TPromise.wrap(window.confirm(messageText)); } + + public show(severity: Severity, message: string, buttons: string[], cancelId?: number): TPromise { + return TPromise.as(0); + } } export class SimpleNotificationService implements INotificationService { diff --git a/src/vs/platform/dialogs/common/choiceIpc.ts b/src/vs/platform/dialogs/common/choiceIpc.ts index e5329e9643e..893cc42cfd6 100644 --- a/src/vs/platform/dialogs/common/choiceIpc.ts +++ b/src/vs/platform/dialogs/common/choiceIpc.ts @@ -20,9 +20,9 @@ export class ChoiceChannel implements IChoiceChannel { constructor( @IChoiceService private choiceService: IChoiceService) { } - call(command: string, args?: [Severity, string, string[], number, boolean]): TPromise { + call(command: string, args?: [Severity, string, string[]]): TPromise { switch (command) { - case 'choose': return this.choiceService.choose(args[0], args[1], args[2], args[3], args[4]); + case 'choose': return this.choiceService.choose(args[0], args[1], args[2]); } return TPromise.wrapError(new Error('invalid command')); } @@ -34,7 +34,7 @@ export class ChoiceChannelClient implements IChoiceService { constructor(private channel: IChoiceChannel) { } - choose(severity: Severity, message: string, options: string[], cancelId?: number, modal?: boolean): TPromise { - return this.channel.call('choose', [severity, message, options, cancelId, modal]); + choose(severity: Severity, message: string, options: string[]): TPromise { + return this.channel.call('choose', [severity, message, options]); } } \ No newline at end of file diff --git a/src/vs/platform/dialogs/common/dialogs.ts b/src/vs/platform/dialogs/common/dialogs.ts index 803d3563db0..5d517913c91 100644 --- a/src/vs/platform/dialogs/common/dialogs.ts +++ b/src/vs/platform/dialogs/common/dialogs.ts @@ -46,6 +46,15 @@ export interface IDialogService { * Ask the user for confirmation with a modal dialog. */ confirm(confirmation: IConfirmation): TPromise; + + /** + * Present a modal dialog to the user. + * + * @returns A promise with the selected choice index. If the user refused to choose, + * then a promise with index of `cancelId` option is returned. If there is no such + * option then promise with index `0` is returned. + */ + show(severity: Severity, message: string, buttons: string[], cancelId?: number): TPromise; } export const IChoiceService = createDecorator('choiceService'); @@ -75,15 +84,9 @@ export interface IChoiceService { * appear less choices appear when the `modal` option is set to `false`. In that case, * the choices prominent. * - * @param when `modal` is true, this will block the user until chooses. - * * @returns A promise with the selected choice index. The promise is cancellable * which hides the message. The promise can return an error, meaning that * the user refused to choose. - * - * When `modal` is true and user refused to choose, then promise with index of - * `Cancel` option is returned. If there is no such option then promise with - * `0` index is returned. */ - choose(severity: Severity, message: string, choices: Choice[], cancelId?: number, modal?: boolean): TPromise; + choose(severity: Severity, message: string, choices: Choice[]): TPromise; } \ No newline at end of file diff --git a/src/vs/platform/extensionManagement/node/extensionManagementService.ts b/src/vs/platform/extensionManagement/node/extensionManagementService.ts index 6c1d2abb5e5..08609884b22 100644 --- a/src/vs/platform/extensionManagement/node/extensionManagementService.ts +++ b/src/vs/platform/extensionManagement/node/extensionManagementService.ts @@ -33,7 +33,7 @@ import pkg from 'vs/platform/node/package'; import { isMacintosh } from 'vs/base/common/platform'; import { ILogService } from 'vs/platform/log/common/log'; import { ExtensionsManifestCache } from 'vs/platform/extensionManagement/node/extensionsManifestCache'; -import { IChoiceService } from 'vs/platform/dialogs/common/dialogs'; +import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import Severity from 'vs/base/common/severity'; import { ExtensionsLifecycle } from 'vs/platform/extensionManagement/node/extensionLifecycle'; import { toErrorMessage } from 'vs/base/common/errorMessage'; @@ -126,7 +126,7 @@ export class ExtensionManagementService extends Disposable implements IExtension constructor( @IEnvironmentService environmentService: IEnvironmentService, - @IChoiceService private choiceService: IChoiceService, + @IDialogService private dialogService: IDialogService, @IExtensionGalleryService private galleryService: IExtensionGalleryService, @ILogService private logService: ILogService ) { @@ -190,11 +190,11 @@ export class ExtensionManagementService extends Disposable implements IExtension const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, { id: getGalleryExtensionIdFromLocal(local) }) && semver.gt(local.manifest.version, manifest.version))[0]; if (newer) { const message = nls.localize('installingOutdatedExtension', "A newer version of this extension is already installed. Would you like to override this with the older version?"); - const options = [ + const buttons = [ nls.localize('override', "Override"), nls.localize('cancel', "Cancel") ]; - return this.choiceService.choose(Severity.Info, message, options, 1, true) + return this.dialogService.show(Severity.Info, message, buttons, 1) .then(value => { if (value === 0) { return this.uninstall(newer, true).then(() => true); @@ -539,13 +539,13 @@ export class ExtensionManagementService extends Disposable implements IExtension } const message = nls.localize('uninstallDependeciesConfirmation', "Would you like to uninstall '{0}' only or its dependencies also?", extension.manifest.displayName || extension.manifest.name); - const options = [ + const buttons = [ nls.localize('uninstallOnly', "Only"), nls.localize('uninstallAll', "All"), nls.localize('cancel', "Cancel") ]; this.logService.info('Requesting for confirmation to uninstall extension with dependencies', extension.identifier.id); - return this.choiceService.choose(Severity.Info, message, options, 2, true) + return this.dialogService.show(Severity.Info, message, buttons, 2) .then(value => { if (value === 0) { return this.uninstallWithDependencies(extension, [], installed); @@ -565,12 +565,12 @@ export class ExtensionManagementService extends Disposable implements IExtension } const message = nls.localize('uninstallConfirmation', "Are you sure you want to uninstall '{0}'?", extension.manifest.displayName || extension.manifest.name); - const options = [ + const buttons = [ nls.localize('ok', "OK"), nls.localize('cancel', "Cancel") ]; this.logService.info('Requesting for confirmation to uninstall extension', extension.identifier.id); - return this.choiceService.choose(Severity.Info, message, options, 1, true) + return this.dialogService.show(Severity.Info, message, buttons, 1) .then(value => { if (value === 0) { return this.uninstallWithDependencies(extension, [], installed); diff --git a/src/vs/workbench/api/electron-browser/mainThreadMessageService.ts b/src/vs/workbench/api/electron-browser/mainThreadMessageService.ts index 569ee9fb1ad..5f768179b11 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadMessageService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadMessageService.ts @@ -10,7 +10,7 @@ import { Action, IAction } from 'vs/base/common/actions'; import { MainThreadMessageServiceShape, MainContext, IExtHostContext, MainThreadMessageOptions } from '../node/extHost.protocol'; import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers'; import { IExtensionDescription } from 'vs/workbench/services/extensions/common/extensions'; -import { IChoiceService } from 'vs/platform/dialogs/common/dialogs'; +import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { once } from 'vs/base/common/event'; import { ICommandService } from 'vs/platform/commands/common/commands'; @@ -24,7 +24,7 @@ export class MainThreadMessageService implements MainThreadMessageServiceShape { extHostContext: IExtHostContext, @INotificationService private readonly _notificationService: INotificationService, @ICommandService private readonly _commandService: ICommandService, - @IChoiceService private readonly _choiceService: IChoiceService, + @IDialogService private readonly _dialogService: IDialogService, @IEnvironmentService private readonly _environmentService: IEnvironmentService ) { // @@ -101,7 +101,7 @@ export class MainThreadMessageService implements MainThreadMessageServiceShape { private _showModalMessage(severity: Severity, message: string, commands: { title: string; isCloseAffordance: boolean; handle: number; }[]): Thenable { let cancelId: number | undefined = void 0; - const options = commands.map((command, index) => { + const buttons = commands.map((command, index) => { if (command.isCloseAffordance === true) { cancelId = index; } @@ -110,16 +110,16 @@ export class MainThreadMessageService implements MainThreadMessageServiceShape { }); if (cancelId === void 0) { - if (options.length > 0) { - options.push(nls.localize('cancel', "Cancel")); + if (buttons.length > 0) { + buttons.push(nls.localize('cancel', "Cancel")); } else { - options.push(nls.localize('ok', "OK")); + buttons.push(nls.localize('ok', "OK")); } - cancelId = options.length - 1; + cancelId = buttons.length - 1; } - return this._choiceService.choose(severity, message, options, cancelId, true) + return this._dialogService.show(severity, message, buttons, cancelId) .then(result => result === commands.length ? undefined : commands[result].handle); } } diff --git a/src/vs/workbench/parts/cli/electron-browser/cli.contribution.ts b/src/vs/workbench/parts/cli/electron-browser/cli.contribution.ts index 65588037906..b163f2be06b 100644 --- a/src/vs/workbench/parts/cli/electron-browser/cli.contribution.ts +++ b/src/vs/workbench/parts/cli/electron-browser/cli.contribution.ts @@ -17,7 +17,7 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { SyncActionDescriptor } from 'vs/platform/actions/common/actions'; import product from 'vs/platform/node/product'; import { INotificationService } from 'vs/platform/notification/common/notification'; -import { IChoiceService, Choice } from 'vs/platform/dialogs/common/dialogs'; +import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import Severity from 'vs/base/common/severity'; import { ILogService } from 'vs/platform/log/common/log'; @@ -47,7 +47,7 @@ class InstallAction extends Action { id: string, label: string, @INotificationService private notificationService: INotificationService, - @IChoiceService private choiceService: IChoiceService, + @IDialogService private dialogService: IDialogService, @ILogService private logService: ILogService ) { super(id, label); @@ -103,9 +103,9 @@ class InstallAction extends Action { private createBinFolder(): TPromise { return new TPromise((c, e) => { - const choices: Choice[] = [nls.localize('ok', "OK"), nls.localize('cancel2', "Cancel")]; + const buttons = [nls.localize('ok', "OK"), nls.localize('cancel2', "Cancel")]; - this.choiceService.choose(Severity.Info, nls.localize('warnEscalation', "Code will now prompt with 'osascript' for Administrator privileges to install the shell command."), choices, 1, true).then(choice => { + this.dialogService.show(Severity.Info, nls.localize('warnEscalation', "Code will now prompt with 'osascript' for Administrator privileges to install the shell command."), buttons, 1).then(choice => { switch (choice) { case 0 /* OK */: const command = 'osascript -e "do shell script \\"mkdir -p /usr/local/bin && chown \\" & (do shell script (\\"whoami\\")) & \\" /usr/local/bin\\" with administrator privileges"'; diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index c67c9fc6f9d..5947107e5bc 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -51,7 +51,7 @@ import { IBroadcastService, IBroadcast } from 'vs/platform/broadcast/electron-br import { IRemoteConsoleLog, parse, getFirstFrame } from 'vs/base/node/console'; import { Source } from 'vs/workbench/parts/debug/common/debugSource'; import { TaskEvent, TaskEventKind } from 'vs/workbench/parts/tasks/common/tasks'; -import { IChoiceService } from 'vs/platform/dialogs/common/dialogs'; +import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { IAction, Action } from 'vs/base/common/actions'; import { normalizeDriveLetter } from 'vs/base/common/labels'; @@ -91,7 +91,7 @@ export class DebugService implements debug.IDebugService { @IViewletService private viewletService: IViewletService, @IPanelService private panelService: IPanelService, @INotificationService private notificationService: INotificationService, - @IChoiceService private choiceService: IChoiceService, + @IDialogService private dialogService: IDialogService, @IPartService private partService: IPartService, @IWindowService private windowService: IWindowService, @IBroadcastService private broadcastService: IBroadcastService, @@ -972,7 +972,7 @@ export class DebugService implements debug.IDebugService { private showError(message: string, actions: IAction[] = []): TPromise { const configureAction = this.instantiationService.createInstance(debugactions.ConfigureAction, debugactions.ConfigureAction.ID, debugactions.ConfigureAction.LABEL); actions.push(configureAction); - return this.choiceService.choose(severity.Error, message, actions.map(a => a.label).concat(nls.localize('cancel', "Cancel")), actions.length, true).then(choice => { + return this.dialogService.show(severity.Error, message, actions.map(a => a.label).concat(nls.localize('cancel', "Cancel")), actions.length).then(choice => { if (choice < actions.length) { return actions[choice].run(); } diff --git a/src/vs/workbench/parts/extensions/node/extensionsWorkbenchService.ts b/src/vs/workbench/parts/extensions/node/extensionsWorkbenchService.ts index 3a5d1364c8e..9e76dd3e097 100644 --- a/src/vs/workbench/parts/extensions/node/extensionsWorkbenchService.ts +++ b/src/vs/workbench/parts/extensions/node/extensionsWorkbenchService.ts @@ -35,7 +35,7 @@ import { ExtensionsInput } from 'vs/workbench/parts/extensions/common/extensions import product from 'vs/platform/node/product'; import { ILogService } from 'vs/platform/log/common/log'; import { IProgressService2, ProgressLocation } from 'vs/platform/progress/common/progress'; -import { IChoiceService } from 'vs/platform/dialogs/common/dialogs'; +import { IChoiceService, IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { INotificationService } from 'vs/platform/notification/common/notification'; interface IExtensionStateProvider { @@ -371,6 +371,7 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService { @IConfigurationService private configurationService: IConfigurationService, @ITelemetryService private telemetryService: ITelemetryService, @INotificationService private notificationService: INotificationService, + @IDialogService private dialogService: IDialogService, @IChoiceService private choiceService: IChoiceService, @IURLService urlService: IURLService, @IExtensionEnablementService private extensionEnablementService: IExtensionEnablementService, @@ -687,11 +688,11 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService { private promptForDependenciesAndEnable(extension: IExtension, dependencies: IExtension[], enablementState: EnablementState, enable: boolean): TPromise { const message = nls.localize('enableDependeciesConfirmation', "Enabling '{0}' also enables its dependencies. Would you like to continue?", extension.displayName); - const options = [ + const buttons = [ nls.localize('enable', "Yes"), nls.localize('doNotEnable', "No") ]; - return this.choiceService.choose(Severity.Info, message, options, 1, true) + return this.dialogService.show(Severity.Info, message, buttons, 1) .then(value => { if (value === 0) { return this.checkAndSetEnablement(extension, dependencies, enablementState, enable); @@ -702,12 +703,12 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService { private promptForDependenciesAndDisable(extension: IExtension, dependencies: IExtension[], enablementState: EnablementState, enable: boolean): TPromise { const message = nls.localize('disableDependeciesConfirmation', "Would you like to disable '{0}' only or its dependencies also?", extension.displayName); - const options = [ + const buttons = [ nls.localize('disableOnly', "Only"), nls.localize('disableAll', "All"), nls.localize('cancel', "Cancel") ]; - return this.choiceService.choose(Severity.Info, message, options, 2, true) + return this.dialogService.show(Severity.Info, message, buttons, 2) .then(value => { if (value === 0) { return this.checkAndSetEnablement(extension, [], enablementState, enable); diff --git a/src/vs/workbench/parts/extensions/test/electron-browser/extensionsWorkbenchService.test.ts b/src/vs/workbench/parts/extensions/test/electron-browser/extensionsWorkbenchService.test.ts index cfb7f0a4d82..8914e11186d 100644 --- a/src/vs/workbench/parts/extensions/test/electron-browser/extensionsWorkbenchService.test.ts +++ b/src/vs/workbench/parts/extensions/test/electron-browser/extensionsWorkbenchService.test.ts @@ -35,7 +35,7 @@ import { ILogService, NullLogService } from 'vs/platform/log/common/log'; import { IWindowService } from 'vs/platform/windows/common/windows'; import { IProgressService2 } from 'vs/platform/progress/common/progress'; import { ProgressService2 } from 'vs/workbench/services/progress/browser/progressService2'; -import { IChoiceService } from 'vs/platform/dialogs/common/dialogs'; +import { IChoiceService, IDialogService } from 'vs/platform/dialogs/common/dialogs'; suite('ExtensionsWorkbenchService Test', () => { @@ -77,12 +77,14 @@ suite('ExtensionsWorkbenchService Test', () => { instantiationService.stub(IExtensionTipsService, 'getKeymapRecommendations', () => []); instantiationService.stub(IChoiceService, { choose: () => null }); + instantiationService.stub(IDialogService, { show: () => TPromise.as(0) }); }); setup(() => { instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', []); instantiationService.stubPromise(IExtensionManagementService, 'getExtensionsReport', []); instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage()); + instantiationService.stub(IDialogService, { show: () => TPromise.as(0) }); instantiationService.stubPromise(IChoiceService, 'choose', 0); (instantiationService.get(IExtensionEnablementService)).reset(); }); @@ -854,7 +856,7 @@ suite('ExtensionsWorkbenchService Test', () => { .then(() => instantiationService.get(IExtensionEnablementService).setEnablement(extensionC, EnablementState.Enabled)) .then(() => { instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [extensionA, extensionB, extensionC]); - instantiationService.stubPromise(IChoiceService, 'choose', 1); + instantiationService.stubPromise(IDialogService, 'show', 1); testObject = instantiationService.createInstance(ExtensionsWorkbenchService); return testObject.setEnablement(testObject.local[0], EnablementState.Disabled) @@ -909,7 +911,7 @@ suite('ExtensionsWorkbenchService Test', () => { .then(() => instantiationService.get(IExtensionEnablementService).setEnablement(extensionC, EnablementState.Enabled)) .then(() => { instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [extensionA, extensionB, extensionC]); - instantiationService.stubPromise(IChoiceService, 'choose', 1); + instantiationService.stubPromise(IDialogService, 'show', 1); testObject = instantiationService.createInstance(ExtensionsWorkbenchService); return testObject.setEnablement(testObject.local[0], EnablementState.Disabled).then(() => assert.fail('Should fail'), error => assert.ok(true)); }); @@ -925,7 +927,7 @@ suite('ExtensionsWorkbenchService Test', () => { .then(() => instantiationService.get(IExtensionEnablementService).setEnablement(extensionC, EnablementState.Disabled)) .then(() => { instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [extensionA, extensionB, extensionC]); - instantiationService.stubPromise(IChoiceService, 'choose', 1); + instantiationService.stubPromise(IDialogService, 'show', 1); testObject = instantiationService.createInstance(ExtensionsWorkbenchService); @@ -947,7 +949,7 @@ suite('ExtensionsWorkbenchService Test', () => { .then(() => instantiationService.get(IExtensionEnablementService).setEnablement(extensionC, EnablementState.Enabled)) .then(() => { instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [extensionA, extensionB, extensionC]); - instantiationService.stubPromise(IChoiceService, 'choose', 1); + instantiationService.stubPromise(IDialogService, 'show', 1); testObject = instantiationService.createInstance(ExtensionsWorkbenchService); @@ -969,7 +971,7 @@ suite('ExtensionsWorkbenchService Test', () => { .then(() => instantiationService.get(IExtensionEnablementService).setEnablement(extensionC, EnablementState.Enabled)) .then(() => { instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [extensionA, extensionB, extensionC]); - instantiationService.stubPromise(IChoiceService, 'choose', 1); + instantiationService.stubPromise(IDialogService, 'show', 1); testObject = instantiationService.createInstance(ExtensionsWorkbenchService); @@ -988,7 +990,7 @@ suite('ExtensionsWorkbenchService Test', () => { .then(() => instantiationService.get(IExtensionEnablementService).setEnablement(extensionC, EnablementState.Enabled)) .then(() => { instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [extensionA, extensionB, extensionC]); - instantiationService.stubPromise(IChoiceService, 'choose', 1); + instantiationService.stubPromise(IDialogService, 'show', 1); testObject = instantiationService.createInstance(ExtensionsWorkbenchService); diff --git a/src/vs/workbench/parts/update/electron-browser/update.ts b/src/vs/workbench/parts/update/electron-browser/update.ts index bdea885df04..1fcf1cf7712 100644 --- a/src/vs/workbench/parts/update/electron-browser/update.ts +++ b/src/vs/workbench/parts/update/electron-browser/update.ts @@ -26,7 +26,7 @@ import { IUpdateService, State as UpdateState, StateType, IUpdate } from 'vs/pla import * as semver from 'semver'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { INotificationService } from 'vs/platform/notification/common/notification'; -import { IChoiceService } from 'vs/platform/dialogs/common/dialogs'; +import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { IWindowService } from 'vs/platform/windows/common/windows'; import { ReleaseNotesManager } from './releaseNotesEditor'; @@ -239,7 +239,7 @@ export class UpdateContribution implements IGlobalActivity { @ICommandService private commandService: ICommandService, @IInstantiationService private instantiationService: IInstantiationService, @INotificationService private notificationService: INotificationService, - @IChoiceService private choiceService: IChoiceService, + @IDialogService private dialogService: IDialogService, @IUpdateService private updateService: IUpdateService, @IWorkbenchEditorService editorService: IWorkbenchEditorService, @IActivityService private activityService: IActivityService, @@ -313,12 +313,11 @@ export class UpdateContribution implements IGlobalActivity { } private onUpdateNotAvailable(): void { - this.choiceService.choose( + this.dialogService.show( severity.Info, nls.localize('noUpdatesAvailable', "There are currently no updates available."), [nls.localize('ok', "OK")], - 0, - true + 0 ); } diff --git a/src/vs/workbench/services/dialogs/electron-browser/dialogs.ts b/src/vs/workbench/services/dialogs/electron-browser/dialogs.ts index c33af8bfcbe..5007c8fcd9a 100644 --- a/src/vs/workbench/services/dialogs/electron-browser/dialogs.ts +++ b/src/vs/workbench/services/dialogs/electron-browser/dialogs.ts @@ -93,32 +93,15 @@ export class DialogService implements IChoiceService, IDialogService { return opts; } - public choose(severity: Severity, message: string, choices: Choice[], cancelId?: number, modal: boolean = false): TPromise { - if (modal) { - return this.doChooseWithDialog(severity, message, choices, cancelId); - } - - return this.doChooseWithNotification(severity, message, choices); - } - - private doChooseWithDialog(severity: Severity, message: string, choices: Choice[], cancelId?: number): TPromise { + public show(severity: Severity, message: string, buttons: string[], cancelId?: number): TPromise { const type: 'none' | 'info' | 'error' | 'question' | 'warning' = severity === Severity.Info ? 'question' : severity === Severity.Error ? 'error' : severity === Severity.Warning ? 'warning' : 'none'; - const stringChoices: string[] = []; - choices.forEach(choice => { - if (typeof choice === 'string') { - stringChoices.push(choice); - } else { - stringChoices.push(choice.label); - } - }); - - const { options, buttonIndexMap } = this.massageMessageBoxOptions({ message, buttons: stringChoices, type, cancelId }); + const { options, buttonIndexMap } = this.massageMessageBoxOptions({ message, buttons, type, cancelId }); return this.windowService.showMessageBox(options).then(result => buttonIndexMap[result.button]); } - private doChooseWithNotification(severity: Severity, message: string, choices: Choice[]): TPromise { + public choose(severity: Severity, message: string, choices: Choice[]): TPromise { let handle: INotificationHandle; const promise = new TPromise((c, e) => { diff --git a/src/vs/workbench/test/electron-browser/api/extHostMessagerService.test.ts b/src/vs/workbench/test/electron-browser/api/extHostMessagerService.test.ts index c4e0481d82c..4f471f38864 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostMessagerService.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostMessagerService.test.ts @@ -8,13 +8,17 @@ import * as assert from 'assert'; import { MainThreadMessageService } from 'vs/workbench/api/electron-browser/mainThreadMessageService'; import { TPromise as Promise, TPromise } from 'vs/base/common/winjs.base'; -import { IChoiceService } from 'vs/platform/dialogs/common/dialogs'; +import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { INotificationService, INotification, NoOpNotification, INotificationHandle } from 'vs/platform/notification/common/notification'; import { ICommandService } from 'vs/platform/commands/common/commands'; -const emptyChoiceService = new class implements IChoiceService { +const emptyDialogService = new class implements IDialogService { _serviceBrand: 'choiceService'; - choose(severity, message, options, modal): never { + show(severity, message, options): never { + throw new Error('not implemented'); + } + + confirm(...opts): never { throw new Error('not implemented'); } }; @@ -73,7 +77,7 @@ suite('ExtHostMessageService', function () { let service = new MainThreadMessageService(null, new EmptyNotificationService(notification => { assert.equal(notification.actions.primary.length, 1); setImmediate(() => notification.actions.primary[0].run()); - }), emptyCommandService, emptyChoiceService, null); + }), emptyCommandService, emptyDialogService, null); return service.$showMessage(1, 'h', {}, [{ handle: 42, title: 'a thing', isCloseAffordance: true }]).then(handle => { assert.equal(handle, 42); @@ -83,14 +87,14 @@ suite('ExtHostMessageService', function () { suite('modal', () => { test('calls choice service', () => { const service = new MainThreadMessageService(null, emptyNotificationService, emptyCommandService, { - choose(severity, message, options, modal) { + show(severity, message, options) { assert.equal(severity, 1); assert.equal(message, 'h'); assert.equal(options.length, 2); assert.equal(options[1], 'Cancel'); return Promise.as(0); } - } as IChoiceService, null); + } as IDialogService, null); return service.$showMessage(1, 'h', { modal: true }, [{ handle: 42, title: 'a thing', isCloseAffordance: false }]).then(handle => { assert.equal(handle, 42); @@ -99,10 +103,10 @@ suite('ExtHostMessageService', function () { test('returns undefined when cancelled', () => { const service = new MainThreadMessageService(null, emptyNotificationService, emptyCommandService, { - choose(severity, message, options, modal) { + show(severity, message, options) { return Promise.as(1); } - } as IChoiceService, null); + } as IDialogService, null); return service.$showMessage(1, 'h', { modal: true }, [{ handle: 42, title: 'a thing', isCloseAffordance: false }]).then(handle => { assert.equal(handle, undefined); @@ -111,11 +115,11 @@ suite('ExtHostMessageService', function () { test('hides Cancel button when not needed', () => { const service = new MainThreadMessageService(null, emptyNotificationService, emptyCommandService, { - choose(severity, message, options, modal) { + show(severity, message, options) { assert.equal(options.length, 1); return Promise.as(0); } - } as IChoiceService, null); + } as IDialogService, null); return service.$showMessage(1, 'h', { modal: true }, [{ handle: 42, title: 'a thing', isCloseAffordance: true }]).then(handle => { assert.equal(handle, 42); diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index c72151054a2..d8c9721d668 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -264,8 +264,8 @@ export function workbenchInstantiationService(): IInstantiationService { instantiationService.stub(IThemeService, new TestThemeService()); instantiationService.stub(IHashService, new TestHashService()); instantiationService.stub(IChoiceService, { - choose: (severity, message, options, cancelId): TPromise => { - return TPromise.as(cancelId); + choose: (severity, message, options): TPromise => { + return TPromise.as(0); } } as IChoiceService); @@ -340,6 +340,10 @@ export class TestDialogService implements IDialogService { public confirm(confirmation: IConfirmation): Promise { return TPromise.as({ confirmed: false }); } + + public show(severity: Severity, message: string, buttons: string[], cancelId?: number): Promise { + return TPromise.as(0); + } } export class TestPartService implements IPartService {