-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathSpecifyProjectNameStep.ts
More file actions
66 lines (61 loc) · 2.95 KB
/
SpecifyProjectNameStep.ts
File metadata and controls
66 lines (61 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as vscode from "vscode";
import { specifySourcePackageNameStep } from "./SpecifySourcePackageNameStep";
import { IProjectCreationMetadata, IProjectCreationStep, StepResult } from "./types";
import { createQuickInputButtons, switchToAdvancedLabel, updateTotalSteps } from "./utils";
export class SpecifyProjectNameStep implements IProjectCreationStep {
public async run(metadata: IProjectCreationMetadata): Promise<StepResult> {
const disposables: vscode.Disposable[] = [];
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const specifyProjectNamePromise = new Promise<StepResult>(async (resolve, _reject) => {
const inputBox = vscode.window.createInputBox();
inputBox.title = `Create Gradle project: Specify project name (${metadata.steps.length + 1}/${
metadata.totalSteps
})`;
inputBox.prompt = "Input name of your project.";
inputBox.placeholder = "e.g. " + metadata.projectName;
inputBox.value = metadata.projectName;
inputBox.ignoreFocusOut = true;
inputBox.validationMessage = this.isValidProjectName(metadata.projectName);
inputBox.buttons = createQuickInputButtons(metadata);
disposables.push(
inputBox.onDidChangeValue(() => {
inputBox.validationMessage = this.isValidProjectName(inputBox.value);
}),
inputBox.onDidAccept(async () => {
if (inputBox.validationMessage) {
return;
}
metadata.projectName = inputBox.value;
metadata.steps.push(specifyProjectNameStep);
metadata.nextStep = !metadata.isAdvanced ? undefined : specifySourcePackageNameStep;
resolve(StepResult.NEXT);
}),
inputBox.onDidTriggerButton((item) => {
if (item === vscode.QuickInputButtons.Back) {
resolve(StepResult.PREVIOUS);
} else if (item.tooltip === switchToAdvancedLabel) {
metadata.isAdvanced = true;
updateTotalSteps(metadata);
resolve(StepResult.RESTART);
}
}),
inputBox.onDidHide(() => {
resolve(StepResult.STOP);
})
);
disposables.push(inputBox);
inputBox.show();
});
try {
return await specifyProjectNamePromise;
} finally {
disposables.forEach((d) => d.dispose());
}
}
private isValidProjectName(value: string): string | undefined {
return value.length > 0 ? undefined : "Invalid Project Name.";
}
}
export const specifyProjectNameStep = new SpecifyProjectNameStep();