Skip to content

Commit

Permalink
Add (if needed) additionalIncludeDirectories instead of overriding them
Browse files Browse the repository at this point in the history
  • Loading branch information
Dllieu committed Aug 25, 2016
1 parent 6138d97 commit 9982b70
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 47 deletions.
32 changes: 16 additions & 16 deletions GenerateFilter/GenerateFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ private GenerateFilter(Package package)
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, CommandId);
//var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
var menuItem = new OleMenuCommand(this.MenuItemCallback, menuCommandID);
menuItem.BeforeQueryStatus += OnBeforeQueryStatus;

Expand Down Expand Up @@ -145,19 +144,12 @@ static private void SetAdditionalIncludeDirectories(Project project, Dictionary<
{
if (!filesPerItemType.ContainsKey("ClInclude"))
return;

var stringBuilder = new StringBuilder();
var hashSet = new HashSet<string>();

var includePaths = new HashSet<string> { @"$(StlIncludeDirectories)" };
foreach (var file in filesPerItemType["ClInclude"])
{
var directoryName = GetRelativePathIfNeeded(projectPath, Path.GetDirectoryName(file));
if (!hashSet.Contains(directoryName))
{
stringBuilder.Append(directoryName + ';');
hashSet.Add(directoryName);
}
includePaths.Add(GetRelativePathIfNeeded(projectPath, Path.GetDirectoryName(file)));
}
stringBuilder.Append(@"$(StlIncludeDirectories);");

var vcProject = project.Object as VCProject;
foreach (VCConfiguration vcConfiguration in vcProject.Configurations)
Expand All @@ -167,10 +159,19 @@ static private void SetAdditionalIncludeDirectories(Project project, Dictionary<
var compilerTool = genericTool as VCCLCompilerTool;
if (compilerTool != null)
{
var includeDirectories = stringBuilder.ToString();
// Avoid updating AdditionalIncludeDirectories when applicable to avoid reloading the project
if (includeDirectories != compilerTool.AdditionalIncludeDirectories)
compilerTool.AdditionalIncludeDirectories = includeDirectories;
if (compilerTool.AdditionalIncludeDirectories == null)
compilerTool.AdditionalIncludeDirectories = string.Empty;

var sss = compilerTool.AdditionalIncludeDirectories;
var currentAdditionalIncludeDirectories = new HashSet<string>(compilerTool.AdditionalIncludeDirectories.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
var pathsToAdd = new StringBuilder();
foreach (var includePath in includePaths)
// Avoid updating AdditionalIncludeDirectories when applicable to avoid reloading the project
if (!currentAdditionalIncludeDirectories.Contains(includePath))
pathsToAdd.Append(includePath + ';');

if (pathsToAdd.Length > 0)
compilerTool.AdditionalIncludeDirectories = pathsToAdd.ToString() + compilerTool.AdditionalIncludeDirectories;
}
}
}
Expand Down Expand Up @@ -387,7 +388,6 @@ private void MenuItemCallback(object sender, EventArgs e)
var projectFilename = project.FileName;
var projectPath = Path.GetDirectoryName(projectFilename);
SetAdditionalIncludeDirectories(project, filesPerItemType, projectPath);
// Check if user is prompted? (what if he made his own change and want to discard them? i.e. can use project.Saved first)
project.DTE.ExecuteCommand("Project.UnloadProject");

var xmlSettings = new XmlWriterSettings() { Indent = true };
Expand Down
14 changes: 9 additions & 5 deletions GenerateFilter/GenerateFilter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@
</ItemGroup>
<ItemGroup>
<None Include="Key.snk" />
<Content Include="LICENSE">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<None Include="packages.config" />
<Content Include="Resources\LICENSE">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<None Include="packages.config" />
<None Include="Resources\LICENSE" />
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
Expand All @@ -76,11 +74,16 @@
<SubType>Designer</SubType>
</VSCTCompile>
<Content Include="index.html" />
<Content Include="Resources\GenerateFilterPackage.ico" />
<Content Include="Resources\GenerateFilterPackage.ico">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="Resources\GenerateFilter.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="Resources\PreviewImage.png">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="stylesheet.css" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -194,6 +197,7 @@
<EmbeddedResource Include="VSPackage.resx">
<MergeWithCTO>true</MergeWithCTO>
<ManifestResourceName>VSPackage</ManifestResourceName>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
21 changes: 0 additions & 21 deletions GenerateFilter/LICENSE

This file was deleted.

Binary file modified GenerateFilter/Resources/GenerateFilterPackage.ico
Binary file not shown.
Binary file added GenerateFilter/Resources/PreviewImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions GenerateFilter/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="VisualStudioCppExtensions.Company.5fdbeaec-89c7-4773-997c-f46757c67a2d" Version="1.0" Language="en-US" Publisher="Stephane Molina" />
<Identity Id="VisualStudioCppExtensions.Company.5fdbeaec-89c7-4773-997c-f46757c67a2d" Version="1.1" Language="en-US" Publisher="Stephane Molina" />
<DisplayName>Generate C++ Filters</DisplayName>
<Description xml:space="preserve">Simple Extension which provide the ability to generate C++ project filters to replicate the folder hierarchy of existing underlying sources / headers</Description>
<License>LICENSE</License>
<Icon>GenerateFilter.ico</Icon>
<Tags>c++;folder;import</Tags>
<Description xml:space="preserve">Simple Extension which provide the ability to generate C++ project filters to replicate the folder hierarchy of underlying sources</Description>
<License>Resources\LICENSE</License>
<Icon>Resources\GenerateFilter.ico</Icon>
<PreviewImage>Resources\PreviewImage.png</PreviewImage>
<Tags>c++;folder;import;filter</Tags>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[14.0]" />
Expand Down

0 comments on commit 9982b70

Please sign in to comment.