Skip to content

Commit 6644ca8

Browse files
committed
Tidy up prompts, placeholders; replace "." with "~" in server name
1 parent 2cd8950 commit 6644ca8

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

src/commands/importFromRegistry.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async function loadRegistryData(config, serverDefinitions, serversMissingUsernam
8282

8383
const originalName: string = serverName.split("\\").pop().trim();
8484
// Enforce the rules from package.json on the server name
85-
const name = originalName.toLowerCase().replace(/[^a-z0-9-._~]/g, "~");
85+
const name = originalName.toLowerCase().replace(/[^a-z0-9-_~]/g, "~");
8686
const getProperty = (property: string) => getStringRegKey(cmd, hkeyLocalMachine, path, property);
8787

8888
if (name !== "" && !config.has("servers." + name)) {
@@ -122,26 +122,30 @@ async function promptForUsernames(serverDefinitions: any, serversMissingUsername
122122
let serverName = serversMissingUsernames.splice(0,1)[0];
123123
let username = await vscode.window.showInputBox({
124124
ignoreFocusOut: true,
125-
placeHolder: "Username",
125+
placeHolder: "Enter a username. Leave empty to be prompted at connect time.",
126126
prompt: `Username for server '${serverName}'`,
127-
validateInput: ((value) => {
128-
return value.length > 0 ? "" : "Mandatory field";
129-
}),
130127
});
131128
if (username === undefined) {
129+
// Was cancelled
132130
return false;
133131
}
132+
if (username === '') {
133+
// If unspecified, actually set to undefined to leave it empty in serverDefinitions
134+
username = undefined;
135+
}
134136
serverDefinitions[serverName].username = username;
135137
if (serversMissingUsernames.length > 0) {
138+
const reuseMessage = (username === undefined) ? `Prompt for username at connect time for all of them` : `Use '${username}' as the username for all of them`;
136139
const items = [
137-
`Enter usernames individually for ${serversMissingUsernames.length} more server(s)`,
138-
`Use username '${username}' for all servers that don't already have a username configured`,
140+
`Enter a username individually for each of them`,
141+
reuseMessage,
139142
`Cancel import`].map((label) => {
140143
return { label };
141144
});
142145
const result = await vscode.window.showQuickPick(items, {
143146
canPickMany: false,
144-
ignoreFocusOut: true
147+
ignoreFocusOut: true,
148+
placeHolder: `${serversMissingUsernames.length} more servers lack a username. What do you want to do?`
145149
});
146150
if (result === undefined || result.label === items[2].label) {
147151
return false;
@@ -172,23 +176,35 @@ async function promptForUsernames(serverDefinitions: any, serversMissingUsername
172176

173177
async function promptForPasswords(serverDefinitions: any, newServerNames: string[]): Promise<void> {
174178
let reusePassword;
175-
let password;
176-
for (const serverName of newServerNames) {
179+
let password : string | undefined = '';
180+
const promptServerNames = new Array();
181+
// Only prompt for servers with a username specified, of course.
182+
newServerNames.forEach(name => {
183+
if (serverDefinitions[name].username !== undefined) {
184+
promptServerNames.push(name);
185+
}
186+
});
187+
for (const serverName of promptServerNames) {
177188
if (!reusePassword) {
178189
password = await vscode.window.showInputBox({
179190
ignoreFocusOut: true,
180191
password: true,
181-
placeHolder: "Password to store in keychain",
182-
prompt: `For connection to InterSystems server '${serverName}'
192+
placeHolder: "Enter password to store in keychain. Leave empty to be prompted at connect time.",
193+
prompt: `Password for connection to InterSystems server '${serverName}'
183194
as ${serverDefinitions[serverName].username}`
184195
});
185196

186-
if (!password) {
197+
if (password === undefined) {
187198
return;
188199
}
200+
201+
if (password === '') {
202+
password = undefined;
203+
}
189204
}
190205

191-
if ((reusePassword === undefined) && (newServerNames.length > 1)) {
206+
if ((reusePassword === undefined) && (promptServerNames.length > 1)) {
207+
const placeHolder = (password === undefined) ? `Enter password later for remaining ${promptServerNames.length - 1} server(s)?` : `Store the same password for remaining ${promptServerNames.length - 1} server(s)?`
192208
const items = [
193209
`No`,
194210
`Yes`,
@@ -198,7 +214,7 @@ async function promptForPasswords(serverDefinitions: any, newServerNames: string
198214
const result = await vscode.window.showQuickPick(items, {
199215
canPickMany: false,
200216
ignoreFocusOut: true,
201-
placeHolder: `Store the same password for remaining ${newServerNames.length - 1} server(s)?`
217+
placeHolder
202218
});
203219
if (result === undefined || result.label === items[2].label) {
204220
return;

0 commit comments

Comments
 (0)