|
1 | 1 | import * as vscode from "vscode";
|
| 2 | +import * as path from "path"; |
2 | 3 | import { OpenDialogOptions, Uri, window, QuickPickItem } from "vscode";
|
3 |
| -import { MP_SERVER_LABELS, MP_VERSION_LABELS } from "../constants"; |
4 |
| -import { trimCapitalizeFirstLetter } from "./util"; |
| 4 | +import { MP_SERVER_LABELS, MP_VERSION_LABELS, CONFIRM_OPTIONS } from "../constants"; |
| 5 | +import { trimCapitalizeFirstLetter, exists } from "./util"; |
5 | 6 |
|
6 | 7 | export async function askForGroupID(): Promise<string | undefined> {
|
7 | 8 | return await vscode.window.showInputBox({
|
@@ -160,3 +161,32 @@ export async function askForFolder(customOptions: OpenDialogOptions): Promise<Ur
|
160 | 161 |
|
161 | 162 | return undefined;
|
162 | 163 | }
|
| 164 | + |
| 165 | +export async function askForTargetFolder(artifactId: string): Promise<Uri | undefined> { |
| 166 | + const customOptions: OpenDialogOptions = { |
| 167 | + openLabel: "Generate into this folder", |
| 168 | + }; |
| 169 | + |
| 170 | + const targetFolder = await askForFolder(customOptions); |
| 171 | + |
| 172 | + if (targetFolder && (await exists(path.join(targetFolder.fsPath, artifactId)))) { |
| 173 | + const selection = await askConfirmation( |
| 174 | + `Folder ${artifactId} already exists inside the ${targetFolder.fsPath} folder. Contents of the ${artifactId} folder and the generated MicroProfile Starter Project will be merged. Are you sure you want to generate into this folder?` |
| 175 | + ); |
| 176 | + if (selection === CONFIRM_OPTIONS.YES) { |
| 177 | + return targetFolder; |
| 178 | + } else if (selection === CONFIRM_OPTIONS.NO) { |
| 179 | + return await askForTargetFolder(artifactId); |
| 180 | + } |
| 181 | + return undefined; |
| 182 | + } |
| 183 | + |
| 184 | + return targetFolder; |
| 185 | +} |
| 186 | + |
| 187 | +export async function askConfirmation(message: string): Promise<string | undefined> { |
| 188 | + return await vscode.window.showWarningMessage( |
| 189 | + message, |
| 190 | + ...[CONFIRM_OPTIONS.YES, CONFIRM_OPTIONS.NO] |
| 191 | + ); |
| 192 | +} |
0 commit comments