diff --git a/src/commands/newFile.ts b/src/commands/newFile.ts index c073ab7b..950622be 100644 --- a/src/commands/newFile.ts +++ b/src/commands/newFile.ts @@ -838,11 +838,50 @@ ClassMethod %OnDashboardAction(pAction As %String, pContext As %ZEN.proxyObject) clsUri = DocumentContentProvider.getUri(`${cls}.cls`, undefined, undefined, undefined, wsFolder.uri); } else { // Ask the user for the URI - clsUri = await vscode.window.showSaveDialog({ - defaultUri: getLocalUri(cls, wsFolder), // Use the export settings to determine the default URI - filters: { - Classes: ["cls"], - }, + const localUri = getLocalUri(cls, wsFolder); + clsUri = await new Promise((resolve) => { + const inputBox = vscode.window.createInputBox(); + inputBox.ignoreFocusOut = true; + inputBox.buttons = [{ iconPath: new vscode.ThemeIcon("save-as"), tooltip: "Show 'Save As' dialog" }]; + inputBox.prompt = `The path is relative to the workspace folder root (${wsFolder.uri.toString(true)}). Intermediate folders that do not exist will be created. Click the 'Save As' icon to open the standard save dialog instead.`; + inputBox.title = "Enter a file path for the new class"; + inputBox.value = localUri.path.slice(wsFolder.uri.path.length); + inputBox.valueSelection = [inputBox.value.length, inputBox.value.length]; + let showingSave = false; + inputBox.onDidTriggerButton(() => { + // User wants to use the save dialog + showingSave = true; + inputBox.hide(); + vscode.window + .showSaveDialog({ + defaultUri: localUri, + filters: { + Classes: ["cls"], + }, + }) + .then( + (u) => resolve(u), + () => resolve(undefined) + ); + }); + inputBox.onDidAccept(() => { + if (typeof inputBox.validationMessage != "string") { + resolve( + wsFolder.uri.with({ + path: `${wsFolder.uri.path}${!wsFolder.uri.path.endsWith("/") ? "/" : ""}${inputBox.value.replace(/^\/+/, "")}`, + }) + ); + inputBox.hide(); + } + }); + inputBox.onDidHide(() => { + if (!showingSave) resolve(undefined); + inputBox.dispose(); + }); + inputBox.onDidChangeValue((value) => { + inputBox.validationMessage = value.endsWith(".cls") ? undefined : "File extension must be .cls"; + }); + inputBox.show(); }); }