Skip to content

Commit

Permalink
Merge pull request #1676 from paulvanbrenk/importIcon
Browse files Browse the repository at this point in the history
Add Icon to gutter for wizard and unbreak wizard
  • Loading branch information
paulvanbrenk committed Aug 25, 2017
2 parents dec280e + e074e55 commit e89868b
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Nodejs/Product/Nodejs/Guids.cs
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

// MUST match guids.h

Expand Down
30 changes: 30 additions & 0 deletions Nodejs/Product/Nodejs/Nodejs.csproj
Expand Up @@ -676,6 +676,36 @@
<ZipProject Include="ProjectTemplates\NodejsWebApp\Preview.png" />
<ZipProject Include="ProjectTemplates\AzureNodejsApp\Preview.png" />
<ZipProject Include="ProjectTemplates\NodejsConsoleApp\Preview.png" />
<Resource Include="..\Icons\NewProjectDialogIconsICO\JSAzureApplication.ico">
<Link>Resources\Icons\NewProjectDialogIconsICO\JSAzureApplication.ico</Link>
</Resource>
<Resource Include="..\Icons\NewProjectDialogIconsICO\JSConsole.ico">
<Link>Resources\Icons\NewProjectDialogIconsICO\JSConsole.ico</Link>
</Resource>
<Resource Include="..\Icons\NewProjectDialogIconsICO\JSWeb.ico">
<Link>Resources\Icons\NewProjectDialogIconsICO\JSWeb.ico</Link>
</Resource>
<Resource Include="..\Icons\NewProjectDialogIconsICO\JSWorker.ico">
<Link>Resources\Icons\NewProjectDialogIconsICO\JSWorker.ico</Link>
</Resource>
<Resource Include="..\Icons\NewProjectDialogIconsICO\NodeJSApplication.ico">
<Link>Resources\Icons\NewProjectDialogIconsICO\NodeJSApplication.ico</Link>
</Resource>
<Resource Include="..\Icons\NewProjectDialogIconsICO\NodeTSApplication.ico">
<Link>Resources\Icons\NewProjectDialogIconsICO\NodeTSApplication.ico</Link>
</Resource>
<Resource Include="..\Icons\NewProjectDialogIconsICO\TSAzureApplication.ico">
<Link>Resources\Icons\NewProjectDialogIconsICO\TSAzureApplication.ico</Link>
</Resource>
<Resource Include="..\Icons\NewProjectDialogIconsICO\TSConsole.ico">
<Link>Resources\Icons\NewProjectDialogIconsICO\TSConsole.ico</Link>
</Resource>
<Resource Include="..\Icons\NewProjectDialogIconsICO\TSWeb.ico">
<Link>Resources\Icons\NewProjectDialogIconsICO\TSWeb.ico</Link>
</Resource>
<Resource Include="..\Icons\NewProjectDialogIconsICO\TSWorker.ico">
<Link>Resources\Icons\NewProjectDialogIconsICO\TSWorker.ico</Link>
</Resource>
<Content Include="Credits.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
Expand Down
11 changes: 11 additions & 0 deletions Nodejs/Product/Nodejs/NodejsTools.vsct
Expand Up @@ -209,6 +209,17 @@
<CommandName>Attach Node.js Debugger</CommandName>
</Strings>
</Button>

<!-- This button is invoked by code in the Import Wizard. So it's invisible, but still very much needed. -->
<Button guid="guidNodeToolsCmdSet" id="cmdidImportWizard" priority="0x010" type="Button">
<CommandFlag>DefaultInvisible</CommandFlag>
<Strings>
<ButtonText>Import Existing &amp;Project...</ButtonText>
<MenuText>Import Existing &amp;Project...</MenuText>
<ToolTipText>Import Existing Project...</ToolTipText>
<CommandName>Import Existing Project...</CommandName>
</Strings>
</Button>
</Buttons>

<!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
Expand Down
101 changes: 50 additions & 51 deletions Nodejs/Product/ProjectWizard/ImportWizard.cs
@@ -1,10 +1,9 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using EnvDTE;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
Expand All @@ -15,74 +14,74 @@ namespace Microsoft.NodejsTools.ProjectWizard
{
public sealed class NewProjectFromExistingWizard : IWizard
{
public static Boolean IsAddNewProjectCmd { get; set; }
public static bool IsAddNewProjectCmd { get; set; }
public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem) { }
public void ProjectFinishedGenerating(EnvDTE.Project project) { }
public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem) { }
public void RunFinished() { }

public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
var dte = automationObject as DTE;
if (dte == null)
var provider = automationObject as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
if (provider == null)
{
var provider = automationObject as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
if (provider != null)
{
dte = new ServiceProvider(provider).GetService(typeof(DTE)) as DTE;
}
MessageBox.Show(ProjectWizardResources.ErrorNoDte, SR.ProductName);
throw new WizardBackoutException();
}

bool addingNewProject = false;
if (dte == null)
using (var serviceProvider = new ServiceProvider(provider))
{
MessageBox.Show(ProjectWizardResources.ImportWizzardCouldNotStartNotAutomationObjectErrorMessage, SR.ProductName);
}
else
{
// https://nodejstools.codeplex.com/workitem/462
// we need to make sure our package is loaded before invoking our command
Guid packageGuid = new Guid(Guids.NodejsPackageString);
IVsPackage package;
((IVsShell)Package.GetGlobalService(typeof(SVsShell))).LoadPackage(
ref packageGuid,
out package
);
var hr = EnsurePackageLoaded(serviceProvider);
if (ErrorHandler.Failed(hr))
{
MessageBox.Show(string.Format(ProjectWizardResources.ImportWizardCouldNotStartFailedToLoadPackage, hr), SR.ProductName);
throw new WizardBackoutException();
}
var uiShell = (IVsUIShell)serviceProvider.GetService(typeof(SVsUIShell));

System.Threading.Tasks.Task.Factory.StartNew(() =>
string directory;
var projName = replacementsDictionary["$projectname$"];
if (!replacementsDictionary.TryGetValue("$specifiedsolutionname$", out var solnName) || string.IsNullOrWhiteSpace(solnName))
{
// Create directory is unchecked, destinationdirectory is the
// directory name the user entered plus the project name, we want
// to remove the solution directory.
directory = Path.GetDirectoryName(replacementsDictionary["$destinationdirectory$"]);
}
else
{
string projName = replacementsDictionary["$projectname$"];
string solnName = replacementsDictionary["$specifiedsolutionname$"];
string directory;
if (string.IsNullOrWhiteSpace(solnName))
{
// Create directory is unchecked, destinationdirectory is the
// directory name the user entered plus the project name, we want
// to remove the solution directory.
directory = Path.GetDirectoryName(replacementsDictionary["$destinationdirectory$"]);
}
else
{
// Create directory is checked, the destinationdirectory is the
// directory the user entered plus the project name plus the
// solution name.
directory = Path.GetDirectoryName(replacementsDictionary["$destinationdirectory$"]);
}
// Create directory is checked, the destinationdirectory is the
// directory the user entered plus the project name plus the
// solution name - we want to remove both extra folders
directory = Path.GetDirectoryName(Path.GetDirectoryName(replacementsDictionary["$destinationdirectory$"]));
}

var context = addingNewProject ?
(int)VSConstants.VSStd97CmdID.AddExistingProject :
(int)VSConstants.VSStd97CmdID.OpenProject;
object inObj = projName + "|" + directory + "|" + context, outObj = null;
dte.Commands.Raise(Guids.NodejsCmdSet.ToString("B"), (int)PkgCmdId.cmdidImportWizard, ref inObj, ref outObj);
});
var context = IsAddNewProjectCmd ? (int)VSConstants.VSStd97CmdID.AddExistingProject : (int)VSConstants.VSStd97CmdID.OpenProject;

object inObj = projName + "|" + directory + "|" + context;
var guid = Guids.NodejsCmdSet;
hr = uiShell.PostExecCommand(ref guid, (uint)PkgCmdId.cmdidImportWizard, 0, ref inObj);
if (ErrorHandler.Failed(hr))
{
MessageBox.Show(string.Format(ProjectWizardResources.ImportWizardCouldNotStartUnexpectedError, hr), SR.ProductName);
}
}
addingNewProject = IsAddNewProjectCmd;

throw new WizardCancelledException();
}

public bool ShouldAddProjectItem(string filePath)
private static int EnsurePackageLoaded(IServiceProvider serviceProvider)
{
return false;
var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell));
var pkgGuid = new Guid(Guids.NodejsPackageString);

if (ErrorHandler.Failed(shell.IsPackageLoaded(ref pkgGuid, out var pkg)) || pkg == null)
{
return shell.LoadPackage(ref pkgGuid, out pkg);
}
return VSConstants.S_OK;
}

public bool ShouldAddProjectItem(string filePath) => false;
}
}
17 changes: 13 additions & 4 deletions Nodejs/Product/ProjectWizard/ProjectWizardResources.Designer.cs

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

11 changes: 7 additions & 4 deletions Nodejs/Product/ProjectWizard/ProjectWizardResources.resx
Expand Up @@ -117,9 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ErrorNoDte" xml:space="preserve">
<value>Unable to start wizard: no automation object available.</value>
</data>
<data name="AzureToolsInstallInstructions" xml:space="preserve">
<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>
</data>
Expand All @@ -145,7 +142,13 @@ Some manual steps will be required to configure your project.</value>
<value>&amp;Download and install now
You will need to restart Visual Studio after installation.</value>
</data>
<data name="ImportWizzardCouldNotStartNotAutomationObjectErrorMessage" xml:space="preserve">
<data name="ImportWizardCouldNotStartFailedToLoadPackage" xml:space="preserve">
<value>Unable to start wizard: failed to load Node Tools support Package (0x{0:X08})</value>
</data>
<data name="ImportWizardCouldNotStartUnexpectedError" xml:space="preserve">
<value>Unable to start wizard: Unexpected error 0x{0:X08}</value>
</data>
<data name="ErrorNoDte" xml:space="preserve">
<value>Unable to start wizard: no automation object available.</value>
</data>
</root>

0 comments on commit e89868b

Please sign in to comment.