From 40fb22a360294c1e59b62e86ee8fc76a9b55be76 Mon Sep 17 00:00:00 2001 From: David Feldhoff Date: Tue, 9 Mar 2021 16:21:25 +0100 Subject: [PATCH] Add setting "showConfirmations" #95 --- vscode-extension/package.json | 5 +++++ vscode-extension/src/App logic/Utils/config.ts | 3 +++ .../src/App logic/Utils/informationsOutput.ts | 11 +++++++---- .../src/Services/WebPanelCommandService.ts | 16 ++++++++-------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/vscode-extension/package.json b/vscode-extension/package.json index f802e6d..feebc04 100644 --- a/vscode-extension/package.json +++ b/vscode-extension/package.json @@ -104,6 +104,11 @@ ], "default": "Ask for confirmation", "description": "Specifies if you're asked if a helper function should be deleted if it's not used anymore after 1. a removal of a given/when/then, 2. a removal of a scenario, 3. a rename of a given/when/then if a helper function to the new naming already exists and you switch to using that one" + }, + "atddTestScriptor.showConfirmations": { + "type": "boolean", + "default": true, + "description": "Specifies if confirmations will show up on updating/removing elements in general." } } } diff --git a/vscode-extension/src/App logic/Utils/config.ts b/vscode-extension/src/App logic/Utils/config.ts index 3ef7295..0f8e354 100644 --- a/vscode-extension/src/App logic/Utils/config.ts +++ b/vscode-extension/src/App logic/Utils/config.ts @@ -39,6 +39,9 @@ export class Config { static getTestSrcFolder(): string | undefined { return this.getConfig().get('testDirectory'); } + static getShowConfirmations(uri: Uri | undefined): boolean { + return this.getConfig(uri).get('showConfirmations', true); + } private static getConfig(uri?: Uri): WorkspaceConfiguration { return workspace.getConfiguration(this.app, uri); } diff --git a/vscode-extension/src/App logic/Utils/informationsOutput.ts b/vscode-extension/src/App logic/Utils/informationsOutput.ts index 7bf8985..0a875f7 100644 --- a/vscode-extension/src/App logic/Utils/informationsOutput.ts +++ b/vscode-extension/src/App logic/Utils/informationsOutput.ts @@ -1,11 +1,14 @@ import * as vscode from 'vscode'; -// import { window } from 'vscode'; +import { Config } from './config'; export interface InformationOutput { - ask(question: string, options: string[]): Promise; + ask(question: string, options: string[], defaultOption: string): Promise; } export class VSCodeInformationOutput implements InformationOutput { - async ask(question: string, options: string[]): Promise { + async ask(question: string, options: string[], defaultOption: string): Promise { + if (options.length > 0 && !Config.getShowConfirmations(vscode.window.activeTextEditor?.document.uri)) + return defaultOption + switch (options.length) { case 0: vscode.window.showInformationMessage(question); @@ -28,7 +31,7 @@ export class TestInformationOutput implements InformationOutput { configure(question: string, response: string) { this.resultMap.set(question, response); } - async ask(question: string, options: string[]): Promise { + async ask(question: string, options: string[], defaultOption: string): Promise { this.askedQuestions.push({ question, options }) if (this.resultMap.has(question)) return this.resultMap.get(question); diff --git a/vscode-extension/src/Services/WebPanelCommandService.ts b/vscode-extension/src/Services/WebPanelCommandService.ts index 89207ee..dde6262 100644 --- a/vscode-extension/src/Services/WebPanelCommandService.ts +++ b/vscode-extension/src/Services/WebPanelCommandService.ts @@ -88,16 +88,16 @@ export class WebPanelCommandService { if ([MessageState.Deleted, MessageState.Modified].includes(entry.State)) { let response: string | undefined; if (entry.State == MessageState.Deleted) - response = await informationOutput.ask(confirmDeletion('this element'), [optionYes, optionNo]) + response = await informationOutput.ask(confirmDeletion('this element'), [optionYes, optionNo], optionYes) else - response = await informationOutput.ask(confirmUpdate('this element'), [optionYes, optionNo]) + response = await informationOutput.ask(confirmUpdate('this element'), [optionYes, optionNo], optionYes) if (response === optionYes) { let useNewProcedure: boolean = true; if (entry.State == MessageState.Modified) { if (await this.middlewareService.checkIfOldAndNewProcedureExists(entry)) { let optionKeepOld: string = 'Keep old'; let optionSwitchToNew: string = 'Switch to new one'; - response = await informationOutput.ask(askWhichProcedureToTake, [optionKeepOld, optionSwitchToNew]) + response = await informationOutput.ask(askWhichProcedureToTake, [optionKeepOld, optionSwitchToNew], optionSwitchToNew) if (response === optionKeepOld) useNewProcedure = false; } @@ -109,7 +109,7 @@ export class WebPanelCommandService { if (helperFunctionsWhichCouldBeDeleted.length == 1) { let responseHelperFunctionShouldBeDeleted: string | undefined; if (removalMode == Config.removalModeConfirmation) - responseHelperFunctionShouldBeDeleted = await informationOutput.ask(confirmDeletion('the procedure \'' + helperFunctionsWhichCouldBeDeleted[0].procedureName) + '\'', [optionYes, optionNo]); + responseHelperFunctionShouldBeDeleted = await informationOutput.ask(confirmDeletion('the procedure \'' + helperFunctionsWhichCouldBeDeleted[0].procedureName) + '\'', [optionYes, optionNo], optionYes); if (responseHelperFunctionShouldBeDeleted === optionYes || removalMode == Config.removalModeNoConfirmationButRemoval) proceduresToDelete = helperFunctionsWhichCouldBeDeleted; else @@ -126,7 +126,7 @@ export class WebPanelCommandService { if (entry.State == MessageState.Deleted) { let responseScenarioShouldBeDeleted: string | undefined if (!entry.internalCall) - responseScenarioShouldBeDeleted = await informationOutput.ask(confirmDeletion('this scenario'), [optionYes, optionNo]); + responseScenarioShouldBeDeleted = await informationOutput.ask(confirmDeletion('this scenario'), [optionYes, optionNo], optionYes); else responseScenarioShouldBeDeleted = optionYes if (responseScenarioShouldBeDeleted === optionYes) { @@ -137,7 +137,7 @@ export class WebPanelCommandService { for (let i = 1; i < proceduresWhichCouldBeDeleted.length; i++) { //i = 1 because scenario-Testprocedure is also inside this this array let responseHelperFunctionShouldBeDeleted: string | undefined; if (removalMode == Config.removalModeConfirmation) - responseHelperFunctionShouldBeDeleted = await informationOutput.ask(confirmDeletion('the procedure \'' + proceduresWhichCouldBeDeleted[i].procedureName) + '\'', [optionYes, optionNo]); + responseHelperFunctionShouldBeDeleted = await informationOutput.ask(confirmDeletion('the procedure \'' + proceduresWhichCouldBeDeleted[i].procedureName) + '\'', [optionYes, optionNo], optionYes); if (responseHelperFunctionShouldBeDeleted === optionYes || removalMode == Config.removalModeNoConfirmationButRemoval) { proceduresToDelete.push(proceduresWhichCouldBeDeleted[i]); } @@ -147,7 +147,7 @@ export class WebPanelCommandService { return { wantsToContinue: false, wantsProceduresToBeDeleted: [], updateProcedureCall: false }; } } else if (entry.State == MessageState.Modified) { - let responseScenarioShouldBeModified: string | undefined = await informationOutput.ask(confirmUpdate('this scenario'), [optionYes, optionNo]); + let responseScenarioShouldBeModified: string | undefined = await informationOutput.ask(confirmUpdate('this scenario'), [optionYes, optionNo], optionYes); if (responseScenarioShouldBeModified === optionNo) { return { wantsToContinue: false, wantsProceduresToBeDeleted: [], updateProcedureCall: false }; } @@ -155,7 +155,7 @@ export class WebPanelCommandService { return { wantsToContinue: true, wantsProceduresToBeDeleted: [], updateProcedureCall: true }; } else if (TypeChanged.Feature == entry.Type) { if (entry.State == MessageState.Deleted) { - let responseScenarioShouldBeDeleted: string | undefined = await informationOutput.ask(confirmDeletion('this feature'), [optionYes, optionNo]); + let responseScenarioShouldBeDeleted: string | undefined = await informationOutput.ask(confirmDeletion('this feature'), [optionYes, optionNo], optionYes); if (responseScenarioShouldBeDeleted == optionNo) return { wantsToContinue: false, wantsProceduresToBeDeleted: [], updateProcedureCall: false }; }