Skip to content

Commit 35a7c1a

Browse files
authored
Fix New File Context Menu (#1343)
**Bug** **Fix** Remove the template lookup logic entirely and instead just create a blank file of the requested type
1 parent 5f7ea80 commit 35a7c1a

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

Nodejs/Product/Nodejs/Project/NewFileMenuGroup/NewFileUtilities.cs

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,12 @@
1717
using System;
1818
using System.Diagnostics;
1919
using System.Globalization;
20+
using System.IO;
2021
using Microsoft.VisualStudio.Shell.Interop;
2122

2223
namespace Microsoft.NodejsTools.Project.NewFileMenuGroup {
2324
internal static class NewFileUtilities {
24-
public static string GetTemplateFile(string fileType) {
25-
string templateFileName = null;
26-
27-
switch (fileType) {
28-
case NodejsConstants.JavaScript:
29-
templateFileName = "EmptyJs.js";
30-
break;
31-
case NodejsConstants.TypeScript:
32-
templateFileName = "EmptyTs.ts";
33-
break;
34-
case NodejsConstants.HTML:
35-
templateFileName = "EmptyHTML.html";
36-
break;
37-
case NodejsConstants.CSS:
38-
templateFileName = "EmptyCSS.css";
39-
break;
40-
}
41-
42-
if (templateFileName == null) {
43-
Debug.Fail(string.Format(CultureInfo.CurrentCulture, "Invalid file type: {0}", fileType));
44-
}
45-
46-
return NodejsToolsInstallPath.GetFile("FileTemplates\\NewItem\\" + templateFileName);
47-
}
48-
4925
private static string GetInitialName(string fileType) {
50-
5126
switch (fileType) {
5227
case NodejsConstants.JavaScript:
5328
return "JavaScript.js";
@@ -74,12 +49,9 @@ private static void CreateNewFile(NodejsProjectNode projectNode, uint containerI
7449
VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE, // Indicate that we want to create this new file by cloning a template file.
7550
itemName,
7651
1, // Number of templates in the next parameter. Must be 1 if using VSADDITEMOP_CLONEFILE.
77-
new string[] { GetTemplateFile(fileType) }, // Array contains the template file path.
52+
new string[] { Path.GetTempFileName() }, // Array contains the template file path.
7853
IntPtr.Zero, // Handle to the Add Item dialog box. Must be Zero if using VSADDITEMOP_CLONEFILE.
79-
pResult
80-
);
81-
82-
// TODO: Do we need to check if result[0] = VSADDRESULT.ADDRESULT_Success here?
54+
pResult);
8355
}
8456
}
8557
}

0 commit comments

Comments
 (0)