Skip to content

Commit 8ad298f

Browse files
authored
Merge pull request #28 from rsaz/feature/22-command-main-menu-vscode
Feature/22 command main menu vscode
2 parents 89bd618 + facbf67 commit 8ad298f

File tree

9 files changed

+491
-193
lines changed

9 files changed

+491
-193
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"Creational",
2929
"designpattern",
3030
"forminline",
31+
"mauilib",
3132
"minwebapi",
3233
"mstest",
3334
"netcoreapp",

media/addProject.js

Lines changed: 106 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,143 @@
22
// It cannot access the main VS Code APIs directly.
33

44
(function () {
5-
65
// vscode api
76
const vscode = acquireVsCodeApi();
87

98
// 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");
1414

15-
document.addEventListener("DOMContentLoaded", function(event) {
15+
document.addEventListener("DOMContentLoaded", function (event) {
16+
populateTemplateSelect(projectGroupSelect.value);
1617
buttonCreateProject.disabled = "true";
1718
buttonCreateProject.style.backgroundColor = "#3C3C3C";
1819
fieldValidation();
1920
});
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+
21112
function fieldValidation() {
22-
if (project.value === "") {
113+
if (project.value === "") {
23114
buttonCreateProject.disabled = true;
24115
} else {
25116
buttonCreateProject.disabled = false;
26117
buttonCreateProject.style.backgroundColor = "#0E639C";
27118
}
28119
}
29120

30-
template.addEventListener('keydown'| 'click', ()=>{
121+
template.addEventListener("keydown" | "click", () => {
31122
project.focus();
32123
});
33124

34-
project.addEventListener('change', () => {
125+
project.addEventListener("change", () => {
35126
fieldValidation();
36127
solution.value = project.value;
37128
});
38129

39130
// create console project
40-
buttonCreateProject.addEventListener('click', () => {
131+
buttonCreateProject.addEventListener("click", () => {
41132
let frameworkSelected = framework.options[framework.selectedIndex].value;
42-
133+
43134
// verify if project has white spaces
44-
let projectTrimmed = (project.value).replace(/\s/g, "");
135+
let projectTrimmed = project.value.replace(/\s/g, "");
45136

46137
vscode.postMessage({
47-
command: 'addProject',
138+
command: "addProject",
48139
template: template.options[template.selectedIndex].value,
49140
project: projectTrimmed,
50-
framework: frameworkSelected
141+
framework: frameworkSelected,
51142
});
52143
});
53-
54144
})();

media/index.html

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,28 @@
1111
<h1>Add the Project Details</h1>
1212
<br/>
1313
<br/>
14+
<h3>Select the project type</h3>
15+
<select id="project-group-select" name="project-group">
16+
<option value="api">API</option>
17+
<option value="blazor">Blazor</option>
18+
<option value="cloud">Cloud</option>
19+
<option value="console">Console</option>
20+
<option value="desktop">Desktop</option>
21+
<option value="extensions">Extensions</option>
22+
<option value="game">Game</option>
23+
<option value="iot">IoT</option>
24+
<option value="lib">Libraries</option>
25+
<option value="machinelearning">Machine Learning</option>
26+
<option value="maui">MAUI</option>
27+
<option value="mobile">Mobile</option>
28+
<option value="test">Test</option>
29+
<option value="web">Web</option>
30+
</select>
31+
<br/>
32+
<br/>
1433
<h3>Select the project template</h3>
1534
<select id="custom-select" name="project-type">
16-
<option value="blazorserver">Blazor Server App</option>
17-
<option value="blazorwasm">Blazor WebAssembly App</option>
18-
<option value="console" selected="selected">Console Application</option>
19-
<option value="classlib">Class Library</option>
20-
<option value="web">ASP.NET Core Empty</option>
21-
<option value="mvc">ASP.NET Core MVC</option>
22-
<option value="webapp">ASP.NET Core MVC Razor Page</option>
23-
<option value="angular">ASP.NET Core MVC Angular SPA</option>
24-
<option value="react">ASP.NET Core MVC React SPA</option>
25-
<option value="reactredux">ASP.NET Core MVC React/Redux SPA</option>
26-
<option value="webapi">ASP.NET Core Web API</option>
27-
<option value="minwebapi">Minimal Web API</option>
28-
<option value="grpc">ASP.NET Core GRPC Services</option>
29-
<option value="razorclasslib">Razor Class Library</option>
30-
<option value="mstest">MSTest Project</option>
31-
<option value="nunit">NUnit Test Project</option>
32-
<option value="xunit">xUnit Test Project</option>
35+
<!-- Dynamically filled options -->
3336
</select>
3437
</br>
3538
</br>

package.json

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,75 @@
5858
},
5959
{
6060
"command": "csharp-snippet-productivity.createClass",
61-
"title": "Create Class"
61+
"title": "Create Class",
62+
"category": "C# Toolbox"
6263
},
6364
{
6465
"command": "csharp-snippet-productivity.createInterface",
65-
"title": "Create Interface"
66+
"title": "Create Interface",
67+
"category": "C# Toolbox"
6668
},
6769
{
6870
"command": "csharp-snippet-productivity.createStruct",
69-
"title": "Create Struct"
71+
"title": "Create Struct",
72+
"category": "C# Toolbox"
7073
},
7174
{
7275
"command": "csharp-snippet-productivity.createRecord",
73-
"title": "Create Record"
76+
"title": "Create Record",
77+
"category": "C# Toolbox"
7478
},
7579
{
7680
"command": "csharp-snippet-productivity.addProjectToSolution",
77-
"title": "Add Project"
81+
"title": "Add Project",
82+
"category": "C# Toolbox"
83+
},
84+
{
85+
"command": "csharp-snippet-productivity.scaffoldResources",
86+
"title": "Scaffold Resources",
87+
"category": "C# Toolbox"
88+
}
89+
],
90+
"keybindings": [
91+
{
92+
"command": "csharp-snippet-productivity.createProject",
93+
"key": "ctrl+alt+/ p"
94+
},
95+
{
96+
"command": "csharp-snippet-productivity.addProjectToSolution",
97+
"key": "ctrl+alt+/ a"
98+
},
99+
{
100+
"command": "csharp-snippet-productivity.createClass",
101+
"key": "ctrl+alt+/ c",
102+
"when": "!editorReadonly"
103+
},
104+
{
105+
"command": "csharp-snippet-productivity.createInterface",
106+
"key": "ctrl+alt+/ i",
107+
"when": "!editorReadonly"
108+
},
109+
{
110+
"command": "csharp-snippet-productivity.createStruct",
111+
"key": "ctrl+alt+/ s",
112+
"when": "!editorReadonly"
113+
},
114+
{
115+
"command": "csharp-snippet-productivity.createRecord",
116+
"key": "ctrl+alt+/ r",
117+
"when": "!editorReadonly"
118+
},
119+
{
120+
"command": "csharp-snippet-productivity.scaffoldResources",
121+
"key": "ctrl+alt+/ ctrl+e",
122+
"when": "!editorReadonly"
78123
}
79124
],
80125
"menus": {
81126
"explorer/context": [
82127
{
83128
"submenu": "cSharp.subMenu",
84-
"group": "navigation@-1"
129+
"group": "navigation@1"
85130
}
86131
],
87132
"cSharp.subMenu": [
@@ -99,6 +144,9 @@
99144
},
100145
{
101146
"command": "csharp-snippet-productivity.addProjectToSolution"
147+
},
148+
{
149+
"command": "csharp-snippet-productivity.scaffoldResources"
102150
}
103151
],
104152
"commandPalette": [
@@ -108,23 +156,27 @@
108156
},
109157
{
110158
"command": "csharp-snippet-productivity.createClass",
111-
"when": "false"
159+
"when": "true"
112160
},
113161
{
114162
"command": "csharp-snippet-productivity.createInterface",
115-
"when": "false"
163+
"when": "true"
116164
},
117165
{
118166
"command": "csharp-snippet-productivity.createStruct",
119-
"when": "false"
167+
"when": "true"
120168
},
121169
{
122170
"command": "csharp-snippet-productivity.createRecord",
123-
"when": "false"
171+
"when": "true"
124172
},
125173
{
126174
"command": "csharp-snippet-productivity.addProjectToSolution",
127-
"when": "false"
175+
"when": "true"
176+
},
177+
{
178+
"command": "csharp-snippet-productivity.scaffoldResources",
179+
"when": "true"
128180
}
129181
]
130182
},

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { CommandRegister } from "./CommandRegister";
55
* This method is called when the extension is activated
66
*/
77
export function activate(context: vscode.ExtensionContext) {
8-
const commands = CommandRegister.getInstance(context);
9-
commands.initializeCommands();
8+
const commands = CommandRegister.getInstance(context);
9+
commands.initializeCommands();
1010
}
1111

1212
/**

0 commit comments

Comments
 (0)