-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.ts
118 lines (103 loc) · 3.73 KB
/
sample.ts
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import {
ConfirmationDialog,
DialogValues,
handleMultiStepInput,
InputBox,
LoadingQuickPick,
OpenDialog,
QuickPick,
} from "../../src";
import * as vscode from "vscode";
/**
* This method contains an example of various inputs you can give during the multi step input.
*
* All of those examples are referenced in the `README.md` file.
*
* If there is any change in the methods calls, then you need to adjust the `README.md`.
*/
export async function generateExampleMultiStepInput(): Promise<void> {
const components = [
new InputBox({
name: "userName",
inputBoxOptions: {
placeHolder: "Give any user name",
ignoreFocusOut: true,
},
}),
new LoadingQuickPick({
name: "foodPreferenceLoading",
placeHolder: "Select your food preference",
generateItems: () => [
{ label: "Meat", description: "Eat any kind of meat" },
{ label: "Fish", description: "Eat any kind of fish" },
{ label: "Vegetarian", description: "Eat no meat and fish, but animal products like milk" },
{ label: "Vegan", description: "Eat no animal products" },
],
// long running function to reload the items
reloadItems: async () => {
const foodPreferences: string[] = await queryWebsiteForFoodPreferences();
return foodPreferences.map((pPreference) => {
const item: vscode.QuickPickItem = {
label: pPreference,
};
return item;
});
},
reloadTooltip: "Reload food preferences",
}),
new OpenDialog({
name: "chooseAnyFile",
openDialogOptions: { openLabel: "Select any file" },
}),
new OpenDialog({
name: "chooseTextFile",
openDialogOptions: {
openLabel: "Select any text file",
filters: {
Text: ["txt"],
},
},
}),
new QuickPick({
name: "foodPreference",
placeHolder: "Select your food preference",
ignoreFocusOut: true,
generateItems: () => [
{ label: "Meat", description: "Eat any kind of meat" },
{ label: "Fish", description: "Eat any kind of fish" },
{ label: "Vegetarian", description: "Eat no meat and fish, but animal products like milk" },
{ label: "Vegan", description: "Eat no animal products" },
],
}),
new ConfirmationDialog({
name: "Confirmation",
message: "My message",
detail: (dialogValues: DialogValues) => `Detail: ${dialogValues.inputValues.size}`,
confirmButtonName: "Confirm Delete",
}),
];
const result = await handleMultiStepInput("Demonstration for inputs", components);
if (result) {
// now, handle the result
const userName = result.inputValues.get("userName")?.[0];
const foodPreferenceLoading = result.inputValues.get("foodPreferenceLoading")?.[0];
const chooseAnyFile = result.inputValues.get("chooseAnyFile")?.[0];
const chooseTextFile = result.inputValues.get("chooseTextFile")?.[0];
const foodPreference = result.inputValues.get("foodPreference")?.[0];
// confirmation is also a string, because the boolean of it is transformed
const confirmation = result.inputValues.get("Confirmation")?.[0];
if (userName && foodPreferenceLoading && chooseAnyFile && chooseTextFile && foodPreference && confirmation) {
console.log("all inputs are there");
// now, you can do specific things with your results
}
}
}
/**
* Simulates a dummy query to a website. This does not call anything, just wait 2 seconds.
*
* @returns a array of food preferences
*/
async function queryWebsiteForFoodPreferences(): Promise<string[]> {
await new Promise((r) => setTimeout(r, 2000));
return ["cow", "pig", "chicken", "salmon", "shrimp", "egg", "cheese", "potato", "salad"];
}