|
2 | 2 | // It cannot access the main VS Code APIs directly. |
3 | 3 |
|
4 | 4 | (function () { |
5 | | - |
6 | 5 | // vscode api |
7 | 6 | const vscode = acquireVsCodeApi(); |
8 | 7 |
|
9 | 8 | // Html elements bindings |
10 | | - const buttonCreateProject = document.getElementById('create-project-button'); |
11 | | - const template = document.getElementById('custom-select'); |
12 | | - const project = document.getElementById('projectName'); |
13 | | - const framework = document.getElementById('custom-select2'); |
| 9 | + const buttonCreateProject = document.getElementById("create-project-button"); |
| 10 | + const template = document.getElementById("custom-select"); |
| 11 | + const project = document.getElementById("projectName"); |
| 12 | + const framework = document.getElementById("custom-select2"); |
| 13 | + const projectGroupSelect = document.getElementById("project-group-select"); |
14 | 14 |
|
15 | | - document.addEventListener("DOMContentLoaded", function(event) { |
| 15 | + document.addEventListener("DOMContentLoaded", function (event) { |
| 16 | + populateTemplateSelect(projectGroupSelect.value); |
16 | 17 | buttonCreateProject.disabled = "true"; |
17 | 18 | buttonCreateProject.style.backgroundColor = "#3C3C3C"; |
18 | 19 | fieldValidation(); |
19 | 20 | }); |
20 | | - |
| 21 | + |
| 22 | + /* Project group select */ |
| 23 | + const projectGroupToTemplates = { |
| 24 | + api: [ |
| 25 | + { templateName: ".NET Core Web API", shortName: "webapi" }, |
| 26 | + { templateName: ".NET Core Web API (native AOT)", shortName: "webapiaot" }, |
| 27 | + { templateName: "API Controller", shortName: "apicontroller" }, |
| 28 | + ], |
| 29 | + blazor: [ |
| 30 | + { templateName: ".NET MAUI Blazor Hybrid App", shortName: "maui-blazor" }, |
| 31 | + { templateName: "Blazor Server App", shortName: "blazorserver" }, |
| 32 | + { templateName: "Blazor Server App Empty", shortName: "blazorserver-empty" }, |
| 33 | + { templateName: "Blazor Web App", shortName: "blazor" }, |
| 34 | + { templateName: "Blazor WebAssembly App Empty", shortName: "blazorwasm-empty" }, |
| 35 | + { templateName: "Blazor WebAssembly Standalone App", shortName: "blazorwasm" }, |
| 36 | + ], |
| 37 | + cloud: [], // No specific templates for cloud in the given list |
| 38 | + console: [{ templateName: "Console App", shortName: "console" }], |
| 39 | + desktop: [ |
| 40 | + { templateName: "Windows Forms App", shortName: "winforms" }, |
| 41 | + { templateName: "Windows Forms Class Library", shortName: "winformslib" }, |
| 42 | + { templateName: "Windows Forms Control Library", shortName: "winformscontrollib" }, |
| 43 | + { templateName: "WPF Application", shortName: "wpf" }, |
| 44 | + { templateName: "WPF Class Library", shortName: "wpflib" }, |
| 45 | + { templateName: "WPF Custom Control Library", shortName: "wpfcustomcontrollib" }, |
| 46 | + { templateName: "WPF User Control Library", shortName: "wpfusercontrollib" }, |
| 47 | + ], |
| 48 | + extensions: [], // No specific templates for extensions in the given list |
| 49 | + game: [], // No specific templates for game in the given list |
| 50 | + iot: [], // No specific templates for IoT in the given list |
| 51 | + lib: [ |
| 52 | + { templateName: "Class Library", shortName: "classlib" }, |
| 53 | + { templateName: ".NET MAUI Class Library", shortName: "mauilib" }, |
| 54 | + { templateName: "Android Class Library", shortName: "androidlib" }, |
| 55 | + { templateName: "iOS Class Library", shortName: "ioslib" }, |
| 56 | + { templateName: "Mac Catalyst Class Library", shortName: "maccatalystlib" }, |
| 57 | + { templateName: "Razor Class Library", shortName: "razorclasslib" }, |
| 58 | + ], |
| 59 | + machinelearning: [], // No specific templates for machine learning in the given list |
| 60 | + maui: [ |
| 61 | + { templateName: ".NET MAUI App", shortName: "maui" }, |
| 62 | + { templateName: ".NET MAUI ContentPage (C#)", shortName: "maui-page-csharp" }, |
| 63 | + { templateName: ".NET MAUI ContentPage (XAML)", shortName: "maui-page-xaml" }, |
| 64 | + { templateName: ".NET MAUI ContentView (C#)", shortName: "maui-view-csharp" }, |
| 65 | + { templateName: ".NET MAUI ContentView (XAML)", shortName: "maui-view-xaml" }, |
| 66 | + { templateName: ".NET MAUI ResourceDictionary (XAML)", shortName: "maui-dict-xaml" }, |
| 67 | + ], |
| 68 | + mobile: [ |
| 69 | + { templateName: "Android Application", shortName: "android" }, |
| 70 | + { templateName: "Android Wear Application", shortName: "androidwear" }, |
| 71 | + { templateName: "iOS Application", shortName: "ios" }, |
| 72 | + { templateName: "iOS Tabbed Application", shortName: "ios-tabbed" }, |
| 73 | + ], |
| 74 | + test: [ |
| 75 | + { templateName: "MSTest Test Project", shortName: "mstest" }, |
| 76 | + { templateName: "MSTest Playwright Test Project", shortName: "mstest-playwright" }, |
| 77 | + { templateName: "NUnit 3 Test Project", shortName: "nunit" }, |
| 78 | + { templateName: "NUnit 3 Test Item", shortName: "nunit-test" }, |
| 79 | + { templateName: "NUnit Playwright Test Project", shortName: "nunit-playwright" }, |
| 80 | + { templateName: "xUnit Test Project", shortName: "xunit" }, |
| 81 | + ], |
| 82 | + web: [ |
| 83 | + { templateName: "ASP.NET Core Empty", shortName: "web" }, |
| 84 | + { templateName: "ASP.NET Core gRPC Service", shortName: "grpc" }, |
| 85 | + { templateName: "ASP.NET Core Web App (Model-View-Controller)", shortName: "mvc" }, |
| 86 | + { templateName: "ASP.NET Core Web App (Razor Pages)", shortName: "webapp" }, |
| 87 | + { templateName: "ASP.NET Core with Angular", shortName: "angular" }, |
| 88 | + { templateName: "ASP.NET Core with React.js", shortName: "react" }, |
| 89 | + { templateName: "ASP.NET Core with React.js and Redux", shortName: "reactredux" }, |
| 90 | + { templateName: "Razor Component", shortName: "razorcomponent" }, |
| 91 | + { templateName: "Razor Page", shortName: "page" }, |
| 92 | + { templateName: "Razor View", shortName: "view" }, |
| 93 | + ], |
| 94 | + }; |
| 95 | + |
| 96 | + function populateTemplateSelect(group) { |
| 97 | + const templates = projectGroupToTemplates[group] || []; |
| 98 | + |
| 99 | + template.innerHTML = templates |
| 100 | + .map( |
| 101 | + (template) => |
| 102 | + `<option value="${template.shortName}">${template.templateName}</option>` |
| 103 | + ) |
| 104 | + .join(""); |
| 105 | + } |
| 106 | + |
| 107 | + /* Project group select */ |
| 108 | + projectGroupSelect.addEventListener("change", () => { |
| 109 | + populateTemplateSelect(projectGroupSelect.value); |
| 110 | + }); |
| 111 | + |
21 | 112 | function fieldValidation() { |
22 | | - if (project.value === "") { |
| 113 | + if (project.value === "") { |
23 | 114 | buttonCreateProject.disabled = true; |
24 | 115 | } else { |
25 | 116 | buttonCreateProject.disabled = false; |
26 | 117 | buttonCreateProject.style.backgroundColor = "#0E639C"; |
27 | 118 | } |
28 | 119 | } |
29 | 120 |
|
30 | | - template.addEventListener('keydown'| 'click', ()=>{ |
| 121 | + template.addEventListener("keydown" | "click", () => { |
31 | 122 | project.focus(); |
32 | 123 | }); |
33 | 124 |
|
34 | | - project.addEventListener('change', () => { |
| 125 | + project.addEventListener("change", () => { |
35 | 126 | fieldValidation(); |
36 | 127 | solution.value = project.value; |
37 | 128 | }); |
38 | 129 |
|
39 | 130 | // create console project |
40 | | - buttonCreateProject.addEventListener('click', () => { |
| 131 | + buttonCreateProject.addEventListener("click", () => { |
41 | 132 | let frameworkSelected = framework.options[framework.selectedIndex].value; |
42 | | - |
| 133 | + |
43 | 134 | // verify if project has white spaces |
44 | | - let projectTrimmed = (project.value).replace(/\s/g, ""); |
| 135 | + let projectTrimmed = project.value.replace(/\s/g, ""); |
45 | 136 |
|
46 | 137 | vscode.postMessage({ |
47 | | - command: 'addProject', |
| 138 | + command: "addProject", |
48 | 139 | template: template.options[template.selectedIndex].value, |
49 | 140 | project: projectTrimmed, |
50 | | - framework: frameworkSelected |
| 141 | + framework: frameworkSelected, |
51 | 142 | }); |
52 | 143 | }); |
53 | | - |
54 | 144 | })(); |
0 commit comments