-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathSelectProjectTypeStep.ts
More file actions
78 lines (73 loc) · 3.18 KB
/
Copy pathSelectProjectTypeStep.ts
File metadata and controls
78 lines (73 loc) · 3.18 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
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as vscode from "vscode";
import { selectScriptDSLStep } from "./SelectScriptDSLStep";
import { IProjectCreationMetadata, IProjectCreationStep, ProjectType, StepResult } from "./types";
import { updateTotalSteps } from "./utils";
export class SelectProjectTypeStep implements IProjectCreationStep {
public async run(metadata: IProjectCreationMetadata): Promise<StepResult> {
const disposables: vscode.Disposable[] = [];
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const selectProjectTypePromise = new Promise<StepResult>(async (resolve, _reject) => {
const pickBox = vscode.window.createQuickPick<vscode.QuickPickItem>();
pickBox.title = `Create Gradle project: Select project type (${metadata.steps.length + 1}/${
metadata.totalSteps
})`;
pickBox.placeholder = "Select project type ...";
pickBox.matchOnDescription = true;
pickBox.ignoreFocusOut = true;
pickBox.items = this.getProjectTypePickItems();
disposables.push(
pickBox.onDidAccept(async () => {
const selectedType = pickBox.selectedItems[0];
if (selectedType) {
switch (selectedType.label) {
case "application":
metadata.projectType = ProjectType.JAVA_APPLICATION;
break;
case "library":
metadata.projectType = ProjectType.JAVA_LIBRARY;
break;
case "Gradle plugin":
metadata.projectType = ProjectType.JAVA_GRADLE_PLUGIN;
break;
default:
resolve(StepResult.STOP);
}
updateTotalSteps(metadata);
metadata.steps.push(selectProjectTypeStep);
metadata.nextStep = selectScriptDSLStep;
resolve(StepResult.NEXT);
}
}),
pickBox.onDidHide(() => {
resolve(StepResult.STOP);
})
);
disposables.push(pickBox);
pickBox.show();
});
try {
return await selectProjectTypePromise;
} finally {
disposables.forEach((d) => d.dispose());
}
}
private getProjectTypePickItems(): vscode.QuickPickItem[] {
const result: vscode.QuickPickItem[] = [];
result.push({
label: "application",
description: "A command-line application implemented in Java",
});
result.push({
label: "library",
description: "A Java library",
});
result.push({
label: "Gradle plugin",
description: "A Gradle plugin implemented in Java",
});
return result;
}
}
export const selectProjectTypeStep = new SelectProjectTypeStep();