|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | -import { nonNullValue, type IActionContext, type IAzureQuickPickItem } from "@microsoft/vscode-azext-utils"; |
| 6 | +import { UserCancelledError, nonNullValue, type IActionContext, type IAzureQuickPickItem, type IAzureQuickPickOptions } from "@microsoft/vscode-azext-utils"; |
7 | 7 | import { basename, relative } from "path"; |
8 | 8 | import { RelativePattern, Uri, workspace, type OpenDialogOptions, type WorkspaceFolder } from "vscode"; |
9 | 9 | import { browseItem, dockerfileGlobPattern, envFileGlobPattern } from "../constants"; |
@@ -80,11 +80,38 @@ export async function selectWorkspaceFile( |
80 | 80 | }); |
81 | 81 | } |
82 | 82 |
|
83 | | - const input: string | undefined = (await context.ui.showQuickPick(quickPicks, { placeHolder })).data; |
84 | | - if (input === skipForNow) { |
85 | | - return undefined; |
86 | | - } else { |
87 | | - return input || (await context.ui.showOpenDialog(options))[0].fsPath; |
| 83 | + return await quickPickWithBrowse(context, quickPicks, { placeHolder }, options, skipForNow); |
| 84 | +} |
| 85 | + |
| 86 | +/** |
| 87 | + * Shows a quick pick that includes a "Browse..." option. If the user selects "Browse..." and then |
| 88 | + * cancels the native file picker dialog, re-prompts the quick pick instead of exiting the wizard. |
| 89 | + * |
| 90 | + * @param skipValue - If the selected item's data matches this value, returns `undefined` (used for "Skip for now") |
| 91 | + */ |
| 92 | +export async function quickPickWithBrowse( |
| 93 | + context: IActionContext, |
| 94 | + picks: IAzureQuickPickItem<string | undefined>[], |
| 95 | + quickPickOptions: IAzureQuickPickOptions, |
| 96 | + openDialogOptions: OpenDialogOptions, |
| 97 | + skipValue?: string, |
| 98 | +): Promise<string | undefined> { |
| 99 | + while (true) { |
| 100 | + const input: string | undefined = (await context.ui.showQuickPick(picks, quickPickOptions)).data; |
| 101 | + if (input === skipValue) { |
| 102 | + return undefined; |
| 103 | + } else if (input) { |
| 104 | + return input; |
| 105 | + } else { |
| 106 | + try { |
| 107 | + return (await context.ui.showOpenDialog(openDialogOptions))[0].fsPath; |
| 108 | + } catch (e) { |
| 109 | + if (e instanceof UserCancelledError) { |
| 110 | + continue; |
| 111 | + } |
| 112 | + throw e; |
| 113 | + } |
| 114 | + } |
88 | 115 | } |
89 | 116 | } |
90 | 117 |
|
|
0 commit comments