Skip to content

Commit e89868b

Browse files
authored
Merge pull request #1676 from paulvanbrenk/importIcon
Add Icon to gutter for wizard and unbreak wizard
2 parents dec280e + e074e55 commit e89868b

File tree

6 files changed

+112
-60
lines changed

6 files changed

+112
-60
lines changed

Nodejs/Product/Nodejs/Guids.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

33
// MUST match guids.h
44

Nodejs/Product/Nodejs/Nodejs.csproj

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,36 @@
676676
<ZipProject Include="ProjectTemplates\NodejsWebApp\Preview.png" />
677677
<ZipProject Include="ProjectTemplates\AzureNodejsApp\Preview.png" />
678678
<ZipProject Include="ProjectTemplates\NodejsConsoleApp\Preview.png" />
679+
<Resource Include="..\Icons\NewProjectDialogIconsICO\JSAzureApplication.ico">
680+
<Link>Resources\Icons\NewProjectDialogIconsICO\JSAzureApplication.ico</Link>
681+
</Resource>
682+
<Resource Include="..\Icons\NewProjectDialogIconsICO\JSConsole.ico">
683+
<Link>Resources\Icons\NewProjectDialogIconsICO\JSConsole.ico</Link>
684+
</Resource>
685+
<Resource Include="..\Icons\NewProjectDialogIconsICO\JSWeb.ico">
686+
<Link>Resources\Icons\NewProjectDialogIconsICO\JSWeb.ico</Link>
687+
</Resource>
688+
<Resource Include="..\Icons\NewProjectDialogIconsICO\JSWorker.ico">
689+
<Link>Resources\Icons\NewProjectDialogIconsICO\JSWorker.ico</Link>
690+
</Resource>
691+
<Resource Include="..\Icons\NewProjectDialogIconsICO\NodeJSApplication.ico">
692+
<Link>Resources\Icons\NewProjectDialogIconsICO\NodeJSApplication.ico</Link>
693+
</Resource>
694+
<Resource Include="..\Icons\NewProjectDialogIconsICO\NodeTSApplication.ico">
695+
<Link>Resources\Icons\NewProjectDialogIconsICO\NodeTSApplication.ico</Link>
696+
</Resource>
697+
<Resource Include="..\Icons\NewProjectDialogIconsICO\TSAzureApplication.ico">
698+
<Link>Resources\Icons\NewProjectDialogIconsICO\TSAzureApplication.ico</Link>
699+
</Resource>
700+
<Resource Include="..\Icons\NewProjectDialogIconsICO\TSConsole.ico">
701+
<Link>Resources\Icons\NewProjectDialogIconsICO\TSConsole.ico</Link>
702+
</Resource>
703+
<Resource Include="..\Icons\NewProjectDialogIconsICO\TSWeb.ico">
704+
<Link>Resources\Icons\NewProjectDialogIconsICO\TSWeb.ico</Link>
705+
</Resource>
706+
<Resource Include="..\Icons\NewProjectDialogIconsICO\TSWorker.ico">
707+
<Link>Resources\Icons\NewProjectDialogIconsICO\TSWorker.ico</Link>
708+
</Resource>
679709
<Content Include="Credits.txt">
680710
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
681711
<IncludeInVSIX>true</IncludeInVSIX>

Nodejs/Product/Nodejs/NodejsTools.vsct

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@
209209
<CommandName>Attach Node.js Debugger</CommandName>
210210
</Strings>
211211
</Button>
212+
213+
<!-- This button is invoked by code in the Import Wizard. So it's invisible, but still very much needed. -->
214+
<Button guid="guidNodeToolsCmdSet" id="cmdidImportWizard" priority="0x010" type="Button">
215+
<CommandFlag>DefaultInvisible</CommandFlag>
216+
<Strings>
217+
<ButtonText>Import Existing &amp;Project...</ButtonText>
218+
<MenuText>Import Existing &amp;Project...</MenuText>
219+
<ToolTipText>Import Existing Project...</ToolTipText>
220+
<CommandName>Import Existing Project...</CommandName>
221+
</Strings>
222+
</Button>
212223
</Buttons>
213224

214225
<!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

33
using System;
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Windows.Forms;
7-
using EnvDTE;
87
using Microsoft.VisualStudio;
98
using Microsoft.VisualStudio.Shell;
109
using Microsoft.VisualStudio.Shell.Interop;
@@ -15,74 +14,74 @@ namespace Microsoft.NodejsTools.ProjectWizard
1514
{
1615
public sealed class NewProjectFromExistingWizard : IWizard
1716
{
18-
public static Boolean IsAddNewProjectCmd { get; set; }
17+
public static bool IsAddNewProjectCmd { get; set; }
1918
public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem) { }
2019
public void ProjectFinishedGenerating(EnvDTE.Project project) { }
2120
public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem) { }
2221
public void RunFinished() { }
2322

2423
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
2524
{
26-
var dte = automationObject as DTE;
27-
if (dte == null)
25+
var provider = automationObject as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
26+
if (provider == null)
2827
{
29-
var provider = automationObject as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
30-
if (provider != null)
31-
{
32-
dte = new ServiceProvider(provider).GetService(typeof(DTE)) as DTE;
33-
}
28+
MessageBox.Show(ProjectWizardResources.ErrorNoDte, SR.ProductName);
29+
throw new WizardBackoutException();
3430
}
3531

36-
bool addingNewProject = false;
37-
if (dte == null)
32+
using (var serviceProvider = new ServiceProvider(provider))
3833
{
39-
MessageBox.Show(ProjectWizardResources.ImportWizzardCouldNotStartNotAutomationObjectErrorMessage, SR.ProductName);
40-
}
41-
else
42-
{
43-
// https://nodejstools.codeplex.com/workitem/462
44-
// we need to make sure our package is loaded before invoking our command
45-
Guid packageGuid = new Guid(Guids.NodejsPackageString);
46-
IVsPackage package;
47-
((IVsShell)Package.GetGlobalService(typeof(SVsShell))).LoadPackage(
48-
ref packageGuid,
49-
out package
50-
);
34+
var hr = EnsurePackageLoaded(serviceProvider);
35+
if (ErrorHandler.Failed(hr))
36+
{
37+
MessageBox.Show(string.Format(ProjectWizardResources.ImportWizardCouldNotStartFailedToLoadPackage, hr), SR.ProductName);
38+
throw new WizardBackoutException();
39+
}
40+
var uiShell = (IVsUIShell)serviceProvider.GetService(typeof(SVsUIShell));
5141

52-
System.Threading.Tasks.Task.Factory.StartNew(() =>
42+
string directory;
43+
var projName = replacementsDictionary["$projectname$"];
44+
if (!replacementsDictionary.TryGetValue("$specifiedsolutionname$", out var solnName) || string.IsNullOrWhiteSpace(solnName))
45+
{
46+
// Create directory is unchecked, destinationdirectory is the
47+
// directory name the user entered plus the project name, we want
48+
// to remove the solution directory.
49+
directory = Path.GetDirectoryName(replacementsDictionary["$destinationdirectory$"]);
50+
}
51+
else
5352
{
54-
string projName = replacementsDictionary["$projectname$"];
55-
string solnName = replacementsDictionary["$specifiedsolutionname$"];
56-
string directory;
57-
if (string.IsNullOrWhiteSpace(solnName))
58-
{
59-
// Create directory is unchecked, destinationdirectory is the
60-
// directory name the user entered plus the project name, we want
61-
// to remove the solution directory.
62-
directory = Path.GetDirectoryName(replacementsDictionary["$destinationdirectory$"]);
63-
}
64-
else
65-
{
66-
// Create directory is checked, the destinationdirectory is the
67-
// directory the user entered plus the project name plus the
68-
// solution name.
69-
directory = Path.GetDirectoryName(replacementsDictionary["$destinationdirectory$"]);
70-
}
53+
// Create directory is checked, the destinationdirectory is the
54+
// directory the user entered plus the project name plus the
55+
// solution name - we want to remove both extra folders
56+
directory = Path.GetDirectoryName(Path.GetDirectoryName(replacementsDictionary["$destinationdirectory$"]));
57+
}
7158

72-
var context = addingNewProject ?
73-
(int)VSConstants.VSStd97CmdID.AddExistingProject :
74-
(int)VSConstants.VSStd97CmdID.OpenProject;
75-
object inObj = projName + "|" + directory + "|" + context, outObj = null;
76-
dte.Commands.Raise(Guids.NodejsCmdSet.ToString("B"), (int)PkgCmdId.cmdidImportWizard, ref inObj, ref outObj);
77-
});
59+
var context = IsAddNewProjectCmd ? (int)VSConstants.VSStd97CmdID.AddExistingProject : (int)VSConstants.VSStd97CmdID.OpenProject;
60+
61+
object inObj = projName + "|" + directory + "|" + context;
62+
var guid = Guids.NodejsCmdSet;
63+
hr = uiShell.PostExecCommand(ref guid, (uint)PkgCmdId.cmdidImportWizard, 0, ref inObj);
64+
if (ErrorHandler.Failed(hr))
65+
{
66+
MessageBox.Show(string.Format(ProjectWizardResources.ImportWizardCouldNotStartUnexpectedError, hr), SR.ProductName);
67+
}
7868
}
79-
addingNewProject = IsAddNewProjectCmd;
69+
8070
throw new WizardCancelledException();
8171
}
8272

83-
public bool ShouldAddProjectItem(string filePath)
73+
private static int EnsurePackageLoaded(IServiceProvider serviceProvider)
8474
{
85-
return false;
75+
var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell));
76+
var pkgGuid = new Guid(Guids.NodejsPackageString);
77+
78+
if (ErrorHandler.Failed(shell.IsPackageLoaded(ref pkgGuid, out var pkg)) || pkg == null)
79+
{
80+
return shell.LoadPackage(ref pkgGuid, out pkg);
81+
}
82+
return VSConstants.S_OK;
8683
}
84+
85+
public bool ShouldAddProjectItem(string filePath) => false;
8786
}
8887
}

Nodejs/Product/ProjectWizard/ProjectWizardResources.Designer.cs

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Nodejs/Product/ProjectWizard/ProjectWizardResources.resx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120-
<data name="ErrorNoDte" xml:space="preserve">
121-
<value>Unable to start wizard: no automation object available.</value>
122-
</data>
123120
<data name="AzureToolsInstallInstructions" xml:space="preserve">
124121
<value>These tools are a free download for your version of Visual Studio that allow you to write, deploy and debug applications for Microsoft Azure in a range of programming languages.</value>
125122
</data>
@@ -145,7 +142,13 @@ Some manual steps will be required to configure your project.</value>
145142
<value>&amp;Download and install now
146143
You will need to restart Visual Studio after installation.</value>
147144
</data>
148-
<data name="ImportWizzardCouldNotStartNotAutomationObjectErrorMessage" xml:space="preserve">
145+
<data name="ImportWizardCouldNotStartFailedToLoadPackage" xml:space="preserve">
146+
<value>Unable to start wizard: failed to load Node Tools support Package (0x{0:X08})</value>
147+
</data>
148+
<data name="ImportWizardCouldNotStartUnexpectedError" xml:space="preserve">
149+
<value>Unable to start wizard: Unexpected error 0x{0:X08}</value>
150+
</data>
151+
<data name="ErrorNoDte" xml:space="preserve">
149152
<value>Unable to start wizard: no automation object available.</value>
150153
</data>
151154
</root>

0 commit comments

Comments
 (0)