├── .gitignore
├── GenerateCppFiltersExtension.sln
├── GenerateCppFiltersExtension
├── GenerateCppFilters.cs
├── GenerateCppFiltersExtension.csproj
├── GenerateCppFiltersPackage.cs
├── GenerateCppFiltersPackage.vsct
├── Key.snk
├── Properties
│ └── AssemblyInfo.cs
├── Resources
│ ├── GenerateCppFilters.ico
│ ├── GenerateCppFiltersPackage.ico
│ ├── LICENSE
│ ├── PreviewImage.png
│ ├── VCProjectEngine_14.0.dll
│ └── VCProjectEngine_15.0.dll
├── VSPackage.resx
├── packages.config
└── source.extension.vsixmanifest
├── README.md
├── appveyor.yml
└── images
├── usage_project_generate_filter_confirmation.png
├── usage_project_generate_filter_result.png
├── usage_project_generate_filter_save_change.png
├── usage_project_no_filter.png
└── usage_project_right_click.png
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 | *.VC.VC.opendb
85 |
86 | # Visual Studio profiler
87 | *.psess
88 | *.vsp
89 | *.vspx
90 | *.sap
91 |
92 | # TFS 2012 Local Workspace
93 | $tf/
94 |
95 | # Guidance Automation Toolkit
96 | *.gpState
97 |
98 | # ReSharper is a .NET coding add-in
99 | _ReSharper*/
100 | *.[Rr]e[Ss]harper
101 | *.DotSettings.user
102 |
103 | # JustCode is a .NET coding add-in
104 | .JustCode
105 |
106 | # TeamCity is a build add-in
107 | _TeamCity*
108 |
109 | # DotCover is a Code Coverage Tool
110 | *.dotCover
111 |
112 | # NCrunch
113 | _NCrunch_*
114 | .*crunch*.local.xml
115 | nCrunchTemp_*
116 |
117 | # MightyMoose
118 | *.mm.*
119 | AutoTest.Net/
120 |
121 | # Web workbench (sass)
122 | .sass-cache/
123 |
124 | # Installshield output folder
125 | [Ee]xpress/
126 |
127 | # DocProject is a documentation generator add-in
128 | DocProject/buildhelp/
129 | DocProject/Help/*.HxT
130 | DocProject/Help/*.HxC
131 | DocProject/Help/*.hhc
132 | DocProject/Help/*.hhk
133 | DocProject/Help/*.hhp
134 | DocProject/Help/Html2
135 | DocProject/Help/html
136 |
137 | # Click-Once directory
138 | publish/
139 |
140 | # Publish Web Output
141 | *.[Pp]ublish.xml
142 | *.azurePubxml
143 | # TODO: Comment the next line if you want to checkin your web deploy settings
144 | # but database connection strings (with potential passwords) will be unencrypted
145 | *.pubxml
146 | *.publishproj
147 |
148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
149 | # checkin your Azure Web App publish settings, but sensitive information contained
150 | # in these scripts will be unencrypted
151 | PublishScripts/
152 |
153 | # NuGet Packages
154 | *.nupkg
155 | # The packages folder can be ignored because of Package Restore
156 | **/packages/*
157 | # except build/, which is used as an MSBuild target.
158 | !**/packages/build/
159 | # Uncomment if necessary however generally it will be regenerated when needed
160 | #!**/packages/repositories.config
161 | # NuGet v3's project.json files produces more ignoreable files
162 | *.nuget.props
163 | *.nuget.targets
164 |
165 | # Microsoft Azure Build Output
166 | csx/
167 | *.build.csdef
168 |
169 | # Microsoft Azure Emulator
170 | ecf/
171 | rcf/
172 |
173 | # Windows Store app package directories and files
174 | AppPackages/
175 | BundleArtifacts/
176 | Package.StoreAssociation.xml
177 | _pkginfo.txt
178 |
179 | # Visual Studio cache files
180 | # files ending in .cache can be ignored
181 | *.[Cc]ache
182 | # but keep track of directories ending in .cache
183 | !*.[Cc]ache/
184 |
185 | # Others
186 | ClientBin/
187 | ~$*
188 | *~
189 | *.dbmdl
190 | *.dbproj.schemaview
191 | *.pfx
192 | *.publishsettings
193 | node_modules/
194 | orleans.codegen.cs
195 |
196 | # Since there are multiple workflows, uncomment next line to ignore bower_components
197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
198 | #bower_components/
199 |
200 | # RIA/Silverlight projects
201 | Generated_Code/
202 |
203 | # Backup & report files from converting an old project file
204 | # to a newer Visual Studio version. Backup files are not needed,
205 | # because we have git ;-)
206 | _UpgradeReport_Files/
207 | Backup*/
208 | UpgradeLog*.XML
209 | UpgradeLog*.htm
210 |
211 | # SQL Server files
212 | *.mdf
213 | *.ldf
214 |
215 | # Business Intelligence projects
216 | *.rdl.data
217 | *.bim.layout
218 | *.bim_*.settings
219 |
220 | # Microsoft Fakes
221 | FakesAssemblies/
222 |
223 | # GhostDoc plugin setting file
224 | *.GhostDoc.xml
225 |
226 | # Node.js Tools for Visual Studio
227 | .ntvs_analysis.dat
228 |
229 | # Visual Studio 6 build log
230 | *.plg
231 |
232 | # Visual Studio 6 workspace options file
233 | *.opt
234 |
235 | # Visual Studio LightSwitch build output
236 | **/*.HTMLClient/GeneratedArtifacts
237 | **/*.DesktopClient/GeneratedArtifacts
238 | **/*.DesktopClient/ModelManifest.xml
239 | **/*.Server/GeneratedArtifacts
240 | **/*.Server/ModelManifest.xml
241 | _Pvt_Extensions
242 |
243 | # Paket dependency manager
244 | .paket/paket.exe
245 | paket-files/
246 |
247 | # FAKE - F# Make
248 | .fake/
249 |
250 | # JetBrains Rider
251 | .idea/
252 | *.sln.iml
253 |
254 | # =========================
255 | # Operating System Files
256 | # =========================
257 |
258 | # OSX
259 | # =========================
260 |
261 | .DS_Store
262 | .AppleDouble
263 | .LSOverride
264 |
265 | # Thumbnails
266 | ._*
267 |
268 | # Files that might appear in the root of a volume
269 | .DocumentRevisions-V100
270 | .fseventsd
271 | .Spotlight-V100
272 | .TemporaryItems
273 | .Trashes
274 | .VolumeIcon.icns
275 |
276 | # Directories potentially created on remote AFP share
277 | .AppleDB
278 | .AppleDesktop
279 | Network Trash Folder
280 | Temporary Items
281 | .apdisk
282 |
283 | # Windows
284 | # =========================
285 |
286 | # Windows image file caches
287 | Thumbs.db
288 | ehthumbs.db
289 |
290 | # Folder config file
291 | Desktop.ini
292 |
293 | # Recycle Bin used on file shares
294 | $RECYCLE.BIN/
295 |
296 | # Windows Installer files
297 | *.cab
298 | *.msi
299 | *.msm
300 | *.msp
301 |
302 | # Windows shortcuts
303 | *.lnk
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26228.9
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenerateCppFiltersExtension", "GenerateCppFiltersExtension\GenerateCppFiltersExtension.csproj", "{18555A86-3A5F-4D33-8C12-01E288BDC30E}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6B724A13-034C-4ABA-884B-15B550A8274F}"
9 | ProjectSection(SolutionItems) = preProject
10 | appveyor.yml = appveyor.yml
11 | EndProjectSection
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Any CPU = Debug|Any CPU
16 | Release|Any CPU = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {18555A86-3A5F-4D33-8C12-01E288BDC30E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {18555A86-3A5F-4D33-8C12-01E288BDC30E}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {18555A86-3A5F-4D33-8C12-01E288BDC30E}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {18555A86-3A5F-4D33-8C12-01E288BDC30E}.Release|Any CPU.Build.0 = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(SolutionProperties) = preSolution
25 | HideSolutionNode = FALSE
26 | EndGlobalSection
27 | EndGlobal
28 |
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/GenerateCppFilters.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Copyright (c) Company. All rights reserved.
4 | //
5 | //------------------------------------------------------------------------------
6 |
7 | using System;
8 | using System.ComponentModel.Design;
9 | using Microsoft.VisualStudio.Shell;
10 | using Microsoft.VisualStudio.Shell.Interop;
11 | using Microsoft.Internal.VisualStudio.PlatformUI;
12 | using EnvDTE;
13 | using System.Collections.Generic;
14 | using System.IO;
15 | using System.Xml;
16 | using System.Reflection;
17 | using System.Text;
18 |
19 | namespace GenerateCppFiltersExtension
20 | {
21 | internal sealed class GenerateCppFilters
22 | {
23 | #region ATTRIBUTES
24 | public const int CommandId = 0x0100;
25 | public static readonly Guid CommandSet = new Guid("acd8036f-19ae-43b2-a2d6-11788cb282fe");
26 | private readonly Package package;
27 | #endregion
28 | #region CALLBACKS
29 | ///
30 | /// Only Display Generate Filter Button if we right click on a C++ Project
31 | ///
32 | void OnBeforeQueryStatus(object sender, EventArgs e)
33 | {
34 | var menuCommand = sender as OleMenuCommand;
35 | if (menuCommand == null)
36 | return;
37 |
38 | var shouldActivateButton = IsCppProject(GetActiveProject());
39 | menuCommand.Visible = shouldActivateButton;
40 | menuCommand.Enabled = shouldActivateButton;
41 | }
42 | #endregion
43 | ///
44 | /// Initializes a new instance of the class.
45 | /// Adds our command handlers for menu (commands must exist in the command table file)
46 | ///
47 | /// Owner package, not null.
48 | private GenerateCppFilters(Package package)
49 | {
50 | if (package == null)
51 | {
52 | throw new ArgumentNullException("package");
53 | }
54 |
55 | this.package = package;
56 |
57 | OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
58 | if (commandService != null)
59 | {
60 | var menuCommandID = new CommandID(CommandSet, CommandId);
61 | var menuItem = new OleMenuCommand(this.MenuItemCallback, menuCommandID);
62 | menuItem.BeforeQueryStatus += OnBeforeQueryStatus;
63 |
64 | commandService.AddCommand(menuItem);
65 | }
66 | }
67 |
68 | ///
69 | /// Gets the instance of the command.
70 | ///
71 | public static GenerateCppFilters Instance
72 | {
73 | get;
74 | private set;
75 | }
76 |
77 | ///
78 | /// Gets the service provider from the owner package.
79 | ///
80 | private IServiceProvider ServiceProvider
81 | {
82 | get
83 | {
84 | return this.package;
85 | }
86 | }
87 |
88 | ///
89 | /// Initializes the singleton instance of the command.
90 | ///
91 | /// Owner package, not null.
92 | public static void Initialize(Package package)
93 | {
94 | Instance = new GenerateCppFilters(package);
95 | }
96 |
97 | #region PROJECT UTILS
98 | internal static Project GetActiveProject()
99 | {
100 | var dte = Package.GetGlobalService(typeof(SDTE)) as DTE;
101 | return GetActiveProject(dte);
102 | }
103 |
104 | internal static Project GetActiveProject(DTE dte)
105 | {
106 | var activeSolutionProjects = dte.ActiveSolutionProjects as Array;
107 | if (activeSolutionProjects == null || activeSolutionProjects.Length == 0)
108 | return null;
109 |
110 | return activeSolutionProjects.GetValue(0) as Project;
111 | }
112 |
113 | private static bool IsCppProject(Project project)
114 | {
115 | return project != null
116 | && (project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageMC
117 | || project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageVC);
118 | }
119 |
120 | public IEnumerable Recurse(ProjectItems i)
121 | {
122 | if (i != null)
123 | {
124 | foreach (ProjectItem j in i)
125 | {
126 | foreach (ProjectItem k in Recurse(j))
127 | {
128 | yield return k;
129 | }
130 | }
131 | }
132 | }
133 |
134 | public IEnumerable Recurse(ProjectItem i)
135 | {
136 | yield return i;
137 | foreach (var j in Recurse(i.ProjectItems))
138 | {
139 | yield return j;
140 | }
141 | }
142 |
143 | static private string GetAssemblyLocalPathFrom(Type type)
144 | {
145 | string codebase = type.Assembly.CodeBase;
146 | var uri = new Uri(codebase, UriKind.Absolute);
147 | return uri.LocalPath;
148 | }
149 |
150 | static private void SetAdditionalIncludeDirectories(Project project, Dictionary> filesPerItemType, string projectPath)
151 | {
152 | if (!filesPerItemType.ContainsKey("ClInclude"))
153 | return;
154 |
155 | var includePaths = new HashSet { @"$(StlIncludeDirectories)" };
156 | foreach (var file in filesPerItemType["ClInclude"])
157 | {
158 | includePaths.Add(GetRelativePathIfNeeded(projectPath, Path.GetDirectoryName(file)));
159 | }
160 |
161 | string filterAssemblyInstallionPath = Path.GetDirectoryName(GetAssemblyLocalPathFrom(typeof(GenerateCppFiltersPackage)));
162 |
163 | DTE dte = (DTE)Package.GetGlobalService(typeof(DTE));
164 | if (dte.Version.StartsWith("14"))
165 | {
166 | Assembly.LoadFrom(Path.Combine(filterAssemblyInstallionPath, @"Resources\\VCProjectEngine_14.0.dll"));
167 | }
168 | else
169 | {
170 | Assembly.LoadFrom(Path.Combine(filterAssemblyInstallionPath, @"Resources\\VCProjectEngine_15.0.dll"));
171 | }
172 |
173 | dynamic vcProject = project.Object;
174 | foreach (dynamic vcConfiguration in vcProject.Configurations)
175 | {
176 | foreach (dynamic genericTool in vcConfiguration.Tools)
177 | {
178 | dynamic compilerTool = genericTool;
179 | if (compilerTool != null && compilerTool.GetType().FullName == "Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCCLCompilerToolShim")
180 | {
181 | // runtime
182 | if (compilerTool.AdditionalIncludeDirectories == null)
183 | compilerTool.AdditionalIncludeDirectories = string.Empty;
184 |
185 | var currentAdditionalIncludeDirectories = new HashSet(compilerTool.AdditionalIncludeDirectories.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
186 | var pathsToAdd = new StringBuilder();
187 | foreach (var includePath in includePaths)
188 | // Avoid updating AdditionalIncludeDirectories when applicable to avoid reloading the project
189 | if (!currentAdditionalIncludeDirectories.Contains(includePath))
190 | pathsToAdd.Append(includePath + ';');
191 |
192 | if (pathsToAdd.Length > 0)
193 | compilerTool.AdditionalIncludeDirectories = pathsToAdd.ToString() + compilerTool.AdditionalIncludeDirectories;
194 | }
195 | }
196 | }
197 | }
198 | #endregion
199 | #region ERROR BOX
200 | private void ErrorMessageBox(string errorMessage)
201 | {
202 | VsShellUtilities.ShowMessageBox(this.ServiceProvider,
203 | errorMessage,
204 | string.Empty,
205 | OLEMSGICON.OLEMSGICON_CRITICAL,
206 | OLEMSGBUTTON.OLEMSGBUTTON_OK,
207 | OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
208 | }
209 | #endregion
210 | #region PATH UTILS
211 | private static string FindCommonPath(Dictionary> filesPerItemType)
212 | {
213 | if (filesPerItemType == null || filesPerItemType.Count == 0)
214 | return string.Empty;
215 |
216 | var result = string.Empty;
217 | foreach (var entry in filesPerItemType)
218 | {
219 | foreach (var path in entry.Value)
220 | {
221 | if (path == null)
222 | return string.Empty;
223 |
224 | if (result == string.Empty)
225 | {
226 | result = Path.GetDirectoryName(path);
227 | continue;
228 | }
229 |
230 | var currentPath = Path.GetDirectoryName(path);
231 | var indexMaxEqual = 0;
232 | while (indexMaxEqual < result.Length
233 | && indexMaxEqual < currentPath.Length
234 | && result[indexMaxEqual] == currentPath[indexMaxEqual])
235 | {
236 | ++indexMaxEqual;
237 | }
238 |
239 | if (indexMaxEqual == 0)
240 | return string.Empty;
241 |
242 | if (indexMaxEqual == result.Length)
243 | continue;
244 |
245 | if (indexMaxEqual < result.Length)
246 | result = result.Substring(0, indexMaxEqual);
247 | }
248 | }
249 | return result;
250 | }
251 |
252 | private static HashSet GenerateUniquePathByFilter(string commonPath, Dictionary> filesPerItemType)
253 | {
254 | var result = new HashSet();
255 | foreach (var entry in filesPerItemType)
256 | foreach (var file in entry.Value)
257 | {
258 | var path = Path.GetDirectoryName(file);
259 | if (path.Length == commonPath.Length)
260 | continue;
261 |
262 | path = GetPathExtensionFromCommonPath(commonPath, path);
263 | result.Add(path);
264 | for (var i = path.LastIndexOf(Path.DirectorySeparatorChar); i != -1; i = path.LastIndexOf(Path.DirectorySeparatorChar, i - 1))
265 | result.Add(path.Substring(0, i));
266 | }
267 | return result;
268 | }
269 |
270 | static private string GetRelativePathIfNeeded(string parentPath, string file)
271 | {
272 | if (Path.GetPathRoot(parentPath) != Path.GetPathRoot(file))
273 | return file;
274 |
275 | var pathUri = new Uri(file);
276 |
277 | // Folders must end in a slash
278 | var formalizedUriParentPath = parentPath;
279 | if (!parentPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
280 | {
281 | formalizedUriParentPath += Path.DirectorySeparatorChar;
282 | }
283 |
284 | var folderUri = new Uri(formalizedUriParentPath);
285 | return Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString().Replace('/', Path.DirectorySeparatorChar));
286 | }
287 |
288 | ///
289 | /// predicate: commonPath.Length < path.Length
290 | ///
291 | private static string GetPathExtensionFromCommonPath(string commonPath, string path)
292 | {
293 | var shift = 0;
294 | if (path[commonPath.Length] == Path.DirectorySeparatorChar)
295 | shift = 1;
296 |
297 | return path.Substring(commonPath.Length + shift, path.Length - commonPath.Length - shift);
298 | }
299 | #endregion
300 | #region XML UTILS
301 | private static void WriteFilter(XmlWriter xmlWriter, HashSet filters)
302 | {
303 | if (filters == null || filters.Count == 0)
304 | return;
305 |
306 | xmlWriter.WriteStartElement("ItemGroup");
307 | foreach (var filter in filters)
308 | {
309 | xmlWriter.WriteStartElement("Filter");
310 | xmlWriter.WriteAttributeString("Include", filter);
311 |
312 | {
313 | xmlWriter.WriteStartElement("UniqueIdentifier");
314 | xmlWriter.WriteString("{" + Guid.NewGuid().ToString() + "}");
315 | xmlWriter.WriteEndElement();
316 | }
317 |
318 | xmlWriter.WriteEndElement();
319 | }
320 | xmlWriter.WriteEndElement();
321 | }
322 |
323 | private static void WriteSources(XmlWriter xmlWriter, string itemType, List files, string projectPath, string commonPath)
324 | {
325 | if (files == null || files.Count == 0)
326 | return;
327 |
328 | // Only write if one occurence
329 | xmlWriter.WriteStartElement("ItemGroup");
330 | foreach (var file in files)
331 | {
332 | var path = Path.GetDirectoryName(file);
333 | if (path.Length == commonPath.Length)
334 | continue;
335 |
336 | xmlWriter.WriteStartElement(itemType);
337 | xmlWriter.WriteAttributeString("Include", GetRelativePathIfNeeded(projectPath, file));
338 |
339 | {
340 | xmlWriter.WriteStartElement("Filter");
341 | xmlWriter.WriteString(GetPathExtensionFromCommonPath(commonPath, path));
342 | xmlWriter.WriteEndElement();
343 | }
344 |
345 | xmlWriter.WriteEndElement();
346 | }
347 | xmlWriter.WriteEndElement();
348 | }
349 | #endregion
350 |
351 | ///
352 | /// This function is the callback used to execute the command when the menu item is clicked.
353 | /// See the constructor to see how the menu item is associated with this function using
354 | /// OleMenuCommandService service and MenuCommand class.
355 | ///
356 | private void MenuItemCallback(object sender, EventArgs e)
357 | {
358 | Project project = GetActiveProject();
359 | if (!IsCppProject(project))
360 | {
361 | ErrorMessageBox("A C++ project must be selected to generate filter!");
362 | return;
363 | }
364 |
365 | if (VsShellUtilities.ShowMessageBox(this.ServiceProvider,
366 | string.Format("Generate filter per folder for '{0}'?\nExisting filters will be erased", project.UniqueName),
367 | string.Empty,
368 | OLEMSGICON.OLEMSGICON_WARNING,
369 | OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
370 | OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST) == DialogResult.Cancel)
371 | return;
372 |
373 | // ClCompile -> .cpp, .cc, .c, ...
374 | // ClInclude -> .h, .hxx, .hpp, ...
375 | // None -> Makefile, .gitignore, ...
376 | var filesPerItemType = new Dictionary /* Files FullPath */>();
377 | foreach (ProjectItem projectItem in Recurse(project.ProjectItems))
378 | {
379 | if (projectItem.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile)
380 | {
381 | try
382 | {
383 | var itemType = projectItem.Properties.Item("ItemType").Value as string;
384 | if (string.IsNullOrEmpty(itemType))
385 | continue;
386 |
387 | if (!filesPerItemType.ContainsKey(itemType))
388 | filesPerItemType.Add(itemType, new List());
389 |
390 | filesPerItemType[itemType].Add(projectItem.Properties.Item("FullPath").Value as string);
391 | }
392 | catch (Exception)
393 | {
394 | // nothing
395 | }
396 | }
397 | }
398 |
399 | var commonPath = FindCommonPath(filesPerItemType);
400 | if (string.IsNullOrEmpty(commonPath))
401 | {
402 | ErrorMessageBox("No common sub-path between files, cannot generate filter!");
403 | return;
404 | }
405 |
406 | // Keep for Post-Unloading
407 | var projectFilename = project.FileName;
408 | var projectPath = Path.GetDirectoryName(projectFilename);
409 | project.DTE.ExecuteCommand("Project.UnloadProject");
410 |
411 | var xmlSettings = new XmlWriterSettings() { Indent = true };
412 | using (var xmlWriter = XmlWriter.Create(projectFilename + ".filters", xmlSettings))
413 | {
414 | xmlWriter.WriteStartElement("Project");
415 | xmlWriter.WriteAttributeString("ToolsVersion", "4.0");
416 | xmlWriter.WriteAttributeString("Project", "xmlns", null, @"http://schemas.microsoft.com/developer/msbuild/2003");
417 |
418 | WriteFilter(xmlWriter, GenerateUniquePathByFilter(commonPath, filesPerItemType));
419 | foreach (var entry in filesPerItemType)
420 | WriteSources(xmlWriter, entry.Key, entry.Value, projectPath, commonPath);
421 |
422 | xmlWriter.WriteEndElement();
423 | }
424 | project.DTE.ExecuteCommand("Project.ReloadProject");
425 | }
426 | }
427 | }
428 |
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/GenerateCppFiltersExtension.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 15.0
6 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
7 |
8 |
9 | true
10 |
11 |
12 |
13 |
14 | 15.0
15 | False
16 |
17 |
18 | true
19 |
20 |
21 | Key.snk
22 |
23 |
24 | Resources\GenerateCppFilters.ico
25 |
26 |
27 |
28 | Debug
29 | AnyCPU
30 | 2.0
31 | {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
32 | {18555A86-3A5F-4D33-8C12-01E288BDC30E}
33 | Library
34 | Properties
35 | GenerateCppFiltersExtension
36 | GenerateCppFiltersExtension
37 | v4.6
38 | true
39 | true
40 | true
41 | true
42 | true
43 | false
44 |
45 |
46 | true
47 | full
48 | false
49 | bin\Debug\
50 | DEBUG;TRACE
51 | prompt
52 | 4
53 |
54 |
55 | pdbonly
56 | true
57 | bin\Release\
58 | TRACE
59 | prompt
60 | 4
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | true
71 |
72 |
73 |
74 | Designer
75 |
76 |
77 |
78 |
79 | Menus.ctmenu
80 | Designer
81 |
82 |
83 | true
84 |
85 |
86 | Always
87 | true
88 |
89 |
90 | true
91 |
92 |
93 | true
94 |
95 |
96 | true
97 |
98 |
99 |
100 |
101 | False
102 |
103 |
104 | False
105 |
106 |
107 | False
108 |
109 |
110 | False
111 |
112 |
113 |
114 |
115 |
116 | False
117 |
118 |
119 | ..\packages\Microsoft.VisualStudio.Imaging.14.3.25407\lib\net45\Microsoft.VisualStudio.Imaging.dll
120 |
121 |
122 | ..\packages\Microsoft.VisualStudio.OLE.Interop.7.10.6070\lib\Microsoft.VisualStudio.OLE.Interop.dll
123 |
124 |
125 | ..\packages\Microsoft.VisualStudio.Shell.14.0.14.3.25407\lib\Microsoft.VisualStudio.Shell.14.0.dll
126 |
127 |
128 | ..\packages\Microsoft.VisualStudio.Shell.Immutable.10.0.10.0.30319\lib\net40\Microsoft.VisualStudio.Shell.Immutable.10.0.dll
129 |
130 |
131 | ..\packages\Microsoft.VisualStudio.Shell.Immutable.11.0.11.0.50727\lib\net45\Microsoft.VisualStudio.Shell.Immutable.11.0.dll
132 |
133 |
134 | ..\packages\Microsoft.VisualStudio.Shell.Immutable.12.0.12.0.21003\lib\net45\Microsoft.VisualStudio.Shell.Immutable.12.0.dll
135 |
136 |
137 | ..\packages\Microsoft.VisualStudio.Shell.Immutable.14.0.14.3.25407\lib\net45\Microsoft.VisualStudio.Shell.Immutable.14.0.dll
138 |
139 |
140 | ..\packages\Microsoft.VisualStudio.Shell.Interop.7.10.6071\lib\Microsoft.VisualStudio.Shell.Interop.dll
141 |
142 |
143 | ..\packages\Microsoft.VisualStudio.Shell.Interop.10.0.10.0.30319\lib\Microsoft.VisualStudio.Shell.Interop.10.0.dll
144 | True
145 |
146 |
147 | ..\packages\Microsoft.VisualStudio.Shell.Interop.11.0.11.0.61030\lib\Microsoft.VisualStudio.Shell.Interop.11.0.dll
148 | True
149 |
150 |
151 | ..\packages\Microsoft.VisualStudio.Shell.Interop.12.0.12.0.30110\lib\Microsoft.VisualStudio.Shell.Interop.12.0.dll
152 | True
153 |
154 |
155 | ..\packages\Microsoft.VisualStudio.Shell.Interop.8.0.8.0.50727\lib\Microsoft.VisualStudio.Shell.Interop.8.0.dll
156 |
157 |
158 | ..\packages\Microsoft.VisualStudio.Shell.Interop.9.0.9.0.30729\lib\Microsoft.VisualStudio.Shell.Interop.9.0.dll
159 |
160 |
161 | ..\packages\Microsoft.VisualStudio.TextManager.Interop.7.10.6070\lib\Microsoft.VisualStudio.TextManager.Interop.dll
162 |
163 |
164 | ..\packages\Microsoft.VisualStudio.TextManager.Interop.8.0.8.0.50727\lib\Microsoft.VisualStudio.TextManager.Interop.8.0.dll
165 |
166 |
167 | ..\packages\Microsoft.VisualStudio.Threading.14.1.111\lib\net45\Microsoft.VisualStudio.Threading.dll
168 |
169 |
170 | ..\packages\Microsoft.VisualStudio.Utilities.14.3.25407\lib\net45\Microsoft.VisualStudio.Utilities.dll
171 |
172 |
173 | ..\packages\Microsoft.VisualStudio.Validation.14.1.111\lib\net45\Microsoft.VisualStudio.Validation.dll
174 |
175 |
176 | False
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 | true
188 | VSPackage
189 | Designer
190 |
191 |
192 |
193 |
194 |
195 |
196 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
197 |
198 |
199 |
200 |
201 |
202 |
209 |
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/GenerateCppFiltersPackage.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Copyright (c) Company. All rights reserved.
4 | //
5 | //------------------------------------------------------------------------------
6 |
7 | using System;
8 | using System.ComponentModel.Design;
9 | using System.Diagnostics;
10 | using System.Diagnostics.CodeAnalysis;
11 | using System.Globalization;
12 | using System.Runtime.InteropServices;
13 | using Microsoft.VisualStudio;
14 | using Microsoft.VisualStudio.OLE.Interop;
15 | using Microsoft.VisualStudio.Shell;
16 | using Microsoft.VisualStudio.Shell.Interop;
17 | using Microsoft.Win32;
18 |
19 | namespace GenerateCppFiltersExtension
20 | {
21 | ///
22 | /// This is the class that implements the package exposed by this assembly.
23 | ///
24 | ///
25 | ///
26 | /// The minimum requirement for a class to be considered a valid package for Visual Studio
27 | /// is to implement the IVsPackage interface and register itself with the shell.
28 | /// This package uses the helper classes defined inside the Managed Package Framework (MPF)
29 | /// to do it: it derives from the Package class that provides the implementation of the
30 | /// IVsPackage interface and uses the registration attributes defined in the framework to
31 | /// register itself and its components with the shell. These attributes tell the pkgdef creation
32 | /// utility what data to put into .pkgdef file.
33 | ///
34 | ///
35 | /// To get loaded into VS, the package must be referred by <Asset Type="Microsoft.VisualStudio.VsPackage" ...> in .vsixmanifest file.
36 | ///
37 | ///
38 | [PackageRegistration(UseManagedResourcesOnly = true)]
39 | [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
40 | [ProvideMenuResource("Menus.ctmenu", 1)]
41 | [Guid(GenerateCppFiltersPackage.PackageGuidString)]
42 | [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
43 | [ProvideAutoLoad(UIContextGuids.SolutionExists)]
44 | public sealed class GenerateCppFiltersPackage : Package
45 | {
46 | ///
47 | /// GenerateCppFiltersPackage GUID string.
48 | ///
49 | public const string PackageGuidString = "99d03761-6200-41ad-b2a1-638ae9e780e5";
50 |
51 | ///
52 | /// Initializes a new instance of the class.
53 | ///
54 | public GenerateCppFiltersPackage()
55 | {
56 | // Inside this method you can place any initialization code that does not require
57 | // any Visual Studio service because at this point the package object is created but
58 | // not sited yet inside Visual Studio environment. The place to do all the other
59 | // initialization is the Initialize method.
60 | }
61 |
62 | #region Package Members
63 |
64 | ///
65 | /// Initialization of the package; this method is called right after the package is sited, so this is the place
66 | /// where you can put all the initialization code that rely on services provided by VisualStudio.
67 | ///
68 | protected override void Initialize()
69 | {
70 | GenerateCppFilters.Initialize(this);
71 | base.Initialize();
72 | }
73 |
74 | #endregion
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/GenerateCppFiltersPackage.vsct:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/Key.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dllieu/VisualStudioCppExtensions/4c35aa1d79566cbdee79cee0c2806e1b36b8f764/GenerateCppFiltersExtension/Key.snk
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("GenerateCppFiltersExtension")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("GenerateCppFiltersExtension")]
13 | [assembly: AssemblyCopyright("")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // Version information for an assembly consists of the following four values:
23 | //
24 | // Major Version
25 | // Minor Version
26 | // Build Number
27 | // Revision
28 | //
29 | // You can specify all the values or you can default the Build and Revision Numbers
30 | // by using the '*' as shown below:
31 | // [assembly: AssemblyVersion("1.0.*")]
32 | [assembly: AssemblyVersion("1.0.0.0")]
33 | [assembly: AssemblyFileVersion("1.0.0.0")]
34 |
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/Resources/GenerateCppFilters.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dllieu/VisualStudioCppExtensions/4c35aa1d79566cbdee79cee0c2806e1b36b8f764/GenerateCppFiltersExtension/Resources/GenerateCppFilters.ico
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/Resources/GenerateCppFiltersPackage.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dllieu/VisualStudioCppExtensions/4c35aa1d79566cbdee79cee0c2806e1b36b8f764/GenerateCppFiltersExtension/Resources/GenerateCppFiltersPackage.ico
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/Resources/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Copyright (c) 2010-2016 Google, Inc. http://angularjs.org
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/Resources/PreviewImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dllieu/VisualStudioCppExtensions/4c35aa1d79566cbdee79cee0c2806e1b36b8f764/GenerateCppFiltersExtension/Resources/PreviewImage.png
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/Resources/VCProjectEngine_14.0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dllieu/VisualStudioCppExtensions/4c35aa1d79566cbdee79cee0c2806e1b36b8f764/GenerateCppFiltersExtension/Resources/VCProjectEngine_14.0.dll
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/Resources/VCProjectEngine_15.0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dllieu/VisualStudioCppExtensions/4c35aa1d79566cbdee79cee0c2806e1b36b8f764/GenerateCppFiltersExtension/Resources/VCProjectEngine_15.0.dll
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/VSPackage.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | GenerateCppFilters Extension
122 |
123 |
124 | GenerateCppFilters Visual Studio Extension Detailed Info
125 |
126 |
127 |
128 | Resources\GenerateCppFiltersPackage.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
129 |
130 |
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/GenerateCppFiltersExtension/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Generate C++ Filters
6 | Simple Extension which provide the ability to generate C++ project filters to replicate the folder hierarchy of underlying sources
7 | Resources\LICENSE
8 | Resources\GenerateCppFilters.ico
9 | Resources\PreviewImage.png
10 | c++;folder;import;filter
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Visual Studio C++ Plugin
2 |
3 | [](https://ci.appveyor.com/project/Dllieu/visualstudiocppextensions)
4 |
5 | ## About
6 | Custom plugins for Visual Studio 2015+:
7 | - **Generate C++ Project's Filters**
8 | - Simple Extension which provide the ability to generate C++ project filters to replicate the folder hierarchy of the underlying sources
9 | - It was originally made to browse easily C++ code hosted on a Linux machine while benefiting of the Visual Studio's features (e.g. GUI, Go to Definition / Declaration, Compile / Debug through SSH, ...)
10 |
11 |
12 |
13 |
14 |
15 |
16 | ## Installation
17 | - Download the ```*.vsix``` package from the **[latest release](https://github.com/Dllieu/VisualStudioCppExtensions/releases/latest)** or from **[Visual Studio gallery](https://visualstudiogallery.msdn.microsoft.com/5a3251d7-3228-4813-a67e-6b9cc83d0507)**
18 | - Double click on the downloaded package and follow the instructions
19 |
20 | ## Example Usage
21 | Open an existing C++ solution
22 |
23 | In the example below, I drag and dropped a folder into an empty C++ Project, all the files are imported but the whole project is *flat* as visual studio does not replicate the folder hierarchy of the files for C++ projects
24 |
25 |
26 |
27 |
28 |
29 | Right click on the project for which you want to generate the filters per folder, a menu ```Generate C++ Project Filters``` will appear (*only appearing when right-clicking on a C++ project*)
30 |
31 |
32 |
33 |
34 |
35 | Click on ```Generate C++ Project Filters```, a confirmation will be required to generate the filters
36 |
37 |
38 |
39 |
40 |
41 | Once the filters are generated, the extension will automatically reload the current project if needed. Accept the changes made by the extension by clicking yes
42 |
43 |
44 |
45 |
46 |
47 | As a result, your C++ project will have filters that replicate your C++ sources folder hierarchy
48 |
49 |
50 |
51 |
52 |
53 | ## Dependencies for developers
54 | If you are interested in enhancing this extension, you must install Visual Studio 2015 SDK
55 |
56 | ### Debug
57 | You have to change the debug settings for the VSIXProject to be able to debug it (```Properties -> Debug```)
58 | - Start external program : ```C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe```
59 | - Command line arguments: ```/rootsuffix EXP```
60 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: 1.50.{build}
2 |
3 | image: Visual Studio 2019
4 |
5 | before_build:
6 | - cmd: nuget restore
7 |
8 | configuration:
9 | - Release
10 |
11 | build:
12 | verbosity: minimal
13 |
14 | artifacts:
15 | - path: '**\*.vsix'
16 |
17 |
18 |
--------------------------------------------------------------------------------
/images/usage_project_generate_filter_confirmation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dllieu/VisualStudioCppExtensions/4c35aa1d79566cbdee79cee0c2806e1b36b8f764/images/usage_project_generate_filter_confirmation.png
--------------------------------------------------------------------------------
/images/usage_project_generate_filter_result.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dllieu/VisualStudioCppExtensions/4c35aa1d79566cbdee79cee0c2806e1b36b8f764/images/usage_project_generate_filter_result.png
--------------------------------------------------------------------------------
/images/usage_project_generate_filter_save_change.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dllieu/VisualStudioCppExtensions/4c35aa1d79566cbdee79cee0c2806e1b36b8f764/images/usage_project_generate_filter_save_change.png
--------------------------------------------------------------------------------
/images/usage_project_no_filter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dllieu/VisualStudioCppExtensions/4c35aa1d79566cbdee79cee0c2806e1b36b8f764/images/usage_project_no_filter.png
--------------------------------------------------------------------------------
/images/usage_project_right_click.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dllieu/VisualStudioCppExtensions/4c35aa1d79566cbdee79cee0c2806e1b36b8f764/images/usage_project_right_click.png
--------------------------------------------------------------------------------