Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Nodejs/Product/InteractiveWindow/InteractiveWindow.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,13 @@
<IDSymbol name="cmdidReplSearchHistoryNext" value="0x010A"/>
<IDSymbol name="cmdidReplSearchHistoryPrevious" value="0x010B"/>

<!-- Groups -->
<!-- Groups -->
<IDSymbol name="ConsoleMenuGroup" value="0x1050" />
<IDSymbol name="ConsoleMenuEditGroup" value="0x1051" />
<IDSymbol name="ConsoleMenuClearGroup" value="0x1052" />
<IDSymbol name="CodeFileGroup" value="0x1053" />
<IDSymbol name="replToolbarGroup" value="0x1054"/>
<IDSymbol name="MyNewGroup" value="0x1055"/>

<!-- Menus -->
<IDSymbol name="menuIdReplToolbar" value="0x2000"/>
Expand Down
8 changes: 8 additions & 0 deletions Nodejs/Product/Nodejs/Nodejs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@
<Compile Include="Outlining\JavaScriptOutliningTaggerProvider.cs" />
<Compile Include="Project\AzureToolsContracts.cs" />
<Compile Include="Project\DependencyNodeProperties.cs" />
<Compile Include="Project\NewFileMenuGroup\NewFileUtilities.cs" />
<Compile Include="Project\NewFileMenuGroup\NewFileNameForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Project\NewFileMenuGroup\NewFileNameForm.Designer.cs">
<DependentUpon>NewFileNameForm.cs</DependentUpon>
</Compile>
<Compile Include="Project\LocalModulesNode.cs" />
<Compile Include="Project\NodejsFolderNode.cs" />
<Compile Include="Project\NodejsProjectImageName.cs" />
Expand Down Expand Up @@ -730,6 +737,7 @@
<EmbeddedResource Include="Options\NodejsGeneralOptionsControl.resx">
<DependentUpon>NodejsGeneralOptionsControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Project\NewFileNameForm.resx" />
<EmbeddedResource Include="Project\NodejsGeneralPropertyPageControl.resx">
<DependentUpon>NodejsGeneralPropertyPageControl.cs</DependentUpon>
</EmbeddedResource>
Expand Down
1 change: 1 addition & 0 deletions Nodejs/Product/Nodejs/NodejsConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class NodejsConstants {

internal const string JavaScript = "JavaScript";
internal const string CSS = "CSS";
internal const string HTML = "HTML";
internal const string Nodejs = "Node.js";

internal const string IssueTrackerUrl = "https://go.microsoft.com/fwlink/?LinkId=507637";
Expand Down
39 changes: 38 additions & 1 deletion Nodejs/Product/Nodejs/NodejsTools.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<Group guid="guidSHLMainMenu" id="IDG_VS_MNUDES_PROPERTIES" priority="0x0800">
<Parent guid="guidNodeToolsNpmCmdSet" id="NpmMenu"/>
</Group>

<Group guid="guidNodeToolsCmdSet" id="AddNewFileGroup" priority="0x0900">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CSCD_PROJECT_ADD"/>
</Group>
</Groups>

<Menus>
Expand Down Expand Up @@ -87,6 +91,34 @@
<CommandFlag>DynamicVisibility</CommandFlag>
If you do not want an image next to your command, remove the Icon node or set it to <Icon guid="guidOfficeIcon" id="msotcidNoIcon" /> -->

<Button guid="guidNodeToolsCmdSet" id="cmdidAddNewJavaScriptFileCommand" priority="0x0550" type="Button">
<Parent guid="guidNodeToolsCmdSet" id="AddNewFileGroup"/>
<Strings>
<ButtonText>JavaScript File...</ButtonText>
</Strings>
</Button>

<Button guid="guidNodeToolsCmdSet" id="cmdidAddNewTypeScriptFileCommand" priority="0x0551" type="Button">
<Parent guid="guidNodeToolsCmdSet" id="AddNewFileGroup"/>
<Strings>
<ButtonText>TypeScript File...</ButtonText>
</Strings>
</Button>

<Button guid="guidNodeToolsCmdSet" id="cmdidAddNewHTMLFileCommand" priority="0x0552" type="Button">
<Parent guid="guidNodeToolsCmdSet" id="AddNewFileGroup"/>
<Strings>
<ButtonText>HTML File...</ButtonText>
</Strings>
</Button>

<Button guid="guidNodeToolsCmdSet" id="cmdidAddNewCSSFileCommand" priority="0x0553" type="Button">
<Parent guid="guidNodeToolsCmdSet" id="AddNewFileGroup"/>
<Strings>
<ButtonText>CSS File...</ButtonText>
</Strings>
</Button>

<Button guid="guidNodeToolsCmdSet" id="cmdidSetAsNodejsStartupFile" priority="0x0300" type="Button">
<Parent guid="guidNodeToolsCmdSet" id="CodeFileGroup"/>
<CommandFlag>DynamicVisibility</CommandFlag>
Expand Down Expand Up @@ -363,7 +395,11 @@
<IDSymbol name="cmdidAzureExplorerAttachNodejsDebugger" value="0x0207" />
<IDSymbol name="cmdidDiagnostics" value="0x0208" />
<IDSymbol name="cmdidSetAsContent" value="0x0209" />
<IDSymbol name="cmdidSetAsCompile" value="0x0210" />
<IDSymbol name="cmdidSetAsCompile" value="0x0210" />
<IDSymbol name="cmdidAddNewJavaScriptFileCommand" value="0x0211" />
<IDSymbol name="cmdidAddNewTypeScriptFileCommand" value="0x0212" />
<IDSymbol name="cmdidAddNewHTMLFileCommand" value="0x0213" />
<IDSymbol name="cmdidAddNewCSSFileCommand" value="0x0214" />

<!-- Shared commands, defined in CommonConstants.cs -->
<IDSymbol name="cmdidAddExistingFolder" value="0x10001" />
Expand All @@ -375,6 +411,7 @@
<IDSymbol name="RemoteDebugProxyGroup" value="0x1011" />
<IDSymbol name="CodeFileGroup" value="0x1012" />
<IDSymbol name="AzureExplorerCommandsGroup" value="0x1015" />
<IDSymbol name="AddNewFileGroup" value="0x1016"/>

<!-- Menus -->
<IDSymbol name="ToolsMenu" value ="0x2001" />
Expand Down
4 changes: 4 additions & 0 deletions Nodejs/Product/Nodejs/PkgCmdId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class PkgCmdId {
public const int cmdidDiagnostics = 0x208;
public const int cmdidSetAsContent = 0x209;
public const int cmdidSetAsCompile = 0x210;
public const int cmdidAddNewJavaScriptFileCommand = 0x211;
public const int cmdidAddNewTypeScriptFileCommand = 0x212;
public const int cmdidAddNewHTMLFileCommand = 0x213;
public const int cmdidAddNewCSSFileCommand = 0x214;

public const int cmdidNpmManageModules = 0x300;
public const int cmdidNpmInstallModules = 0x301;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions Nodejs/Product/Nodejs/Project/NewFileMenuGroup/NewFileNameForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//*********************************************************//
// Copyright (c) Microsoft. All rights reserved.
//
// Apache 2.0 License
//
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//
//*********************************************************//

using System;
using System.Windows.Forms;

namespace Microsoft.NodejsTools.Project
{
public partial class NewFileNameForm : Form
{
public NewFileNameForm(string initialFileName)
{
InitializeComponent();

TextBox.Text = initialFileName;
}

public TextBox TextBox
{
get {
return textBox;
}
}

private void TextBox_TextChanged(object sender, EventArgs e)
{
if (TextBox.Text.Trim().Length == 0) {
okButton.Enabled = false;
}
else {
okButton.Enabled = true;
}
}
}
}
104 changes: 104 additions & 0 deletions Nodejs/Product/Nodejs/Project/NewFileMenuGroup/NewFileUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using System.Diagnostics;
using Microsoft.VisualStudio.Shell.Interop;


namespace Microsoft.NodejsTools.Project.NewFileMenuGroup
{
internal static class NewFileUtilities
{
public static string GetTemplateFile(string fileType)
{
string templateFileName = null;

switch (fileType) {
case NodejsConstants.JavaScript:
templateFileName = "EmptyJs.js";
break;
case NodejsConstants.TypeScript:
templateFileName = "EmptyTs.ts";
break;
case NodejsConstants.HTML:
templateFileName = "EmptyHTML.html";
break;
case NodejsConstants.CSS:
templateFileName = "EmptyCSS.css";
break;
}

if (templateFileName == null) {
Debug.Fail(String.Format("Invalid file type: {0}", fileType));
}

return NodejsToolsInstallPath.GetFile("FileTemplates\\NewItem\\" + templateFileName);
}

private static string GetInitialName(string fileType)
{
string name = null;

switch (fileType) {
case NodejsConstants.JavaScript:
name = "JavaScript.js";
break;
case NodejsConstants.TypeScript:
name = "TypeScript.ts";
break;
case NodejsConstants.HTML:
name = "HTML.html";
break;
case NodejsConstants.CSS:
name = "CSS.css";
break;
}

if (name == null) {
Debug.Fail(String.Format("Invalid file type: {0}", fileType));
}

return name;
}

private static void CreateNewFile(NodejsProjectNode projectNode, uint containerId, string fileType)
{
using (var dialog = new NewFileNameForm(GetInitialName(fileType))) {
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
string itemName = dialog.TextBox.Text;

VSADDRESULT[] pResult = new VSADDRESULT[1];
projectNode.AddItem(
containerId, // Identifier of the container folder.
VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE, // Indicate that we want to create this new file by cloning a template file.
itemName,
1, // Number of templates in the next parameter. Must be 1 if using VSADDITEMOP_CLONEFILE.
new string[] { GetTemplateFile(fileType) }, // Array contains the template file path.
IntPtr.Zero, // Handle to the Add Item dialog box. Must be Zero if using VSADDITEMOP_CLONEFILE.
pResult
);

// TODO: Do we need to check if result[0] = VSADDRESULT.ADDRESULT_Success here?
}
}
}

internal static void CreateNewJavaScriptFile(NodejsProjectNode projectNode, uint containerId)
{
CreateNewFile(projectNode, containerId, NodejsConstants.JavaScript);
}

internal static void CreateNewTypeScriptFile(NodejsProjectNode projectNode, uint containerId)
{
CreateNewFile(projectNode, containerId, NodejsConstants.TypeScript);
}

internal static void CreateNewHTMLFile(NodejsProjectNode projectNode, uint containerId)
{
CreateNewFile(projectNode, containerId, NodejsConstants.HTML);
}

internal static void CreateNewCSSFile(NodejsProjectNode projectNode, uint containerId)
{
CreateNewFile(projectNode, containerId, NodejsConstants.CSS);
}
}
}
Loading