Skip to content

Improve UI for selecting the URI of a new local class created via command #1545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions src/commands/newFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vscode.Uri>((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();
});
}

Expand Down