diff --git a/src/vs/platform/notification/common/notification.ts b/src/vs/platform/notification/common/notification.ts index 4a7adc958ac911316063f96625688a2a272a0a56..34e33e31894b710588c36a3ee5aa14d31306ebfe 100644 --- a/src/vs/platform/notification/common/notification.ts +++ b/src/vs/platform/notification/common/notification.ts @@ -320,8 +320,10 @@ export interface INotificationService { * Shows a prompt in the notification area with the provided choices. The prompt * is non-modal. If you want to show a modal dialog instead, use `IDialogService`. * - * @param onCancel will be called if the user closed the notification without picking - * any of the provided choices. + * @param severity the severity of the notification. Either `Info`, `Warning` or `Error`. + * @param message the message to show as status. + * @param choices options to be choosen from. + * @param options provides some optional configuration options. * * @returns a handle on the notification to e.g. hide it or update message, buttons, etc. */ diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index 9c04ad440354228d39e1391702315763c24db354..173c3f009c04f816db62336b84dc7559e8aa5757 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -1402,12 +1402,52 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } private executeTask(task: Task, resolver: ITaskResolver): Promise { - return ProblemMatcherRegistry.onReady().then(() => { - return this.editorService.saveAll().then(() => { // make sure all dirty editors are saved + enum SaveBeforeRunConfigOptions { + Always = 'always', + Never = 'never', + Prompt = 'prompt' + } + + const saveBeforeRunTaskConfig: SaveBeforeRunConfigOptions = this.configurationService.getValue('task.saveBeforeRun'); + + const execTask = async (task: Task, resolver: ITaskResolver): Promise => { + return ProblemMatcherRegistry.onReady().then(() => { let executeResult = this.getTaskSystem().run(task, resolver); return this.handleExecuteResult(executeResult); }); - }); + }; + + const saveAllEditorsAndExecTask = async (task: Task, resolver: ITaskResolver): Promise => { + return this.editorService.saveAll().then(() => { + return execTask(task, resolver); + }); + }; + + const promptAsk = async (task: Task, resolver: ITaskResolver): Promise => { + const dialogOptions = await this.dialogService.show( + Severity.Info, + nls.localize('TaskSystem.saveBeforeRun.prompt.title', 'Save all editors?'), + [nls.localize('saveBeforeRun.save', 'Save'), nls.localize('saveBeforeRun.dontSave', 'Don\'t save')], + { + detail: nls.localize('detail', "Do you want to save all editors before running the task?"), + cancelId: 1 + } + ); + + if (dialogOptions.choice === 0) { + return saveAllEditorsAndExecTask(task, resolver); + } else { + return execTask(task, resolver); + } + }; + + if (saveBeforeRunTaskConfig === SaveBeforeRunConfigOptions.Never) { + return execTask(task, resolver); + } else if (saveBeforeRunTaskConfig === SaveBeforeRunConfigOptions.Prompt) { + return promptAsk(task, resolver); + } else { + return saveAllEditorsAndExecTask(task, resolver); + } } private async handleExecuteResult(executeResult: ITaskExecuteResult): Promise { diff --git a/src/vs/workbench/contrib/tasks/browser/task.contribution.ts b/src/vs/workbench/contrib/tasks/browser/task.contribution.ts index 99b149e1417f11dff5cc6460c072cf00312daedf..194ab88599587025213eb92f7e922db98e51e40b 100644 --- a/src/vs/workbench/contrib/tasks/browser/task.contribution.ts +++ b/src/vs/workbench/contrib/tasks/browser/task.contribution.ts @@ -376,6 +376,20 @@ configurationRegistry.registerConfiguration({ type: 'boolean', description: nls.localize('task.quickOpen.skip', "Controls whether the task quick pick is skipped when there is only one task to pick from."), default: false - } + }, + 'task.saveBeforeRun': { + markdownDescription: nls.localize( + 'task.saveBeforeRun', + 'Configures whether all editor will be saved before running a task.' + ), + type: 'string', + enum: ['always', 'never', 'prompt'], + enumDescriptions: [ + nls.localize('task.saveBeforeRun.always', 'Always saves all editors before running.'), + nls.localize('task.saveBeforeRun.never', 'Never saves editors before running.'), + nls.localize('task.SaveBeforeRun.prompt', 'Prompts whether to save editors before running.'), + ], + default: 'always', + }, } });