-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathSelectScriptDSLStep.ts
More file actions
83 lines (78 loc) · 3.52 KB
/
SelectScriptDSLStep.ts
File metadata and controls
83 lines (78 loc) · 3.52 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
79
80
81
82
83
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as vscode from "vscode";
import { selectTestFrameworkStep } from "./SelectTestFrameworkStep";
import { specifyProjectNameStep } from "./SpecifyProjectNameStep";
import { IProjectCreationMetadata, IProjectCreationStep, ProjectType, StepResult } from "./types";
import { createQuickInputButtons, switchToAdvancedLabel, updateTotalSteps } from "./utils";
export class SelectScriptDSLStep implements IProjectCreationStep {
public async run(metadata: IProjectCreationMetadata): Promise<StepResult> {
const disposables: vscode.Disposable[] = [];
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const selectScriptDSLPromise = new Promise<StepResult>(async (resolve, _reject) => {
const pickBox = vscode.window.createQuickPick<vscode.QuickPickItem>();
pickBox.title = `Create Gradle project: Select script DSL (${metadata.steps.length + 1}/${
metadata.totalSteps
})`;
pickBox.placeholder = "Select build script DSL ...";
pickBox.matchOnDescription = true;
pickBox.ignoreFocusOut = true;
pickBox.items = this.getScriptDSLPickItems();
pickBox.buttons = createQuickInputButtons(metadata);
disposables.push(
pickBox.onDidAccept(() => {
const selectedScriptDSL = pickBox.selectedItems[0];
if (selectedScriptDSL) {
switch (selectedScriptDSL.label) {
case "Groovy":
metadata.scriptDSL = "groovy";
break;
case "Kotlin":
metadata.scriptDSL = "kotlin";
break;
default:
resolve(StepResult.STOP);
}
metadata.steps.push(selectScriptDSLStep);
if (!metadata.isAdvanced || metadata.projectType === ProjectType.JAVA_GRADLE_PLUGIN) {
metadata.nextStep = specifyProjectNameStep;
} else {
metadata.nextStep = selectTestFrameworkStep;
}
resolve(StepResult.NEXT);
}
}),
pickBox.onDidTriggerButton((item) => {
if (item === vscode.QuickInputButtons.Back) {
resolve(StepResult.PREVIOUS);
} else if (item.tooltip === switchToAdvancedLabel) {
metadata.isAdvanced = true;
updateTotalSteps(metadata);
resolve(StepResult.RESTART);
}
}),
pickBox.onDidHide(() => {
resolve(StepResult.STOP);
})
);
disposables.push(pickBox);
pickBox.show();
});
try {
return await selectScriptDSLPromise;
} finally {
disposables.forEach((d) => d.dispose());
}
}
private getScriptDSLPickItems(): vscode.QuickPickItem[] {
const result: vscode.QuickPickItem[] = [];
result.push({
label: "Groovy",
});
result.push({
label: "Kotlin",
});
return result;
}
}
export const selectScriptDSLStep = new SelectScriptDSLStep();