public VCFilter FindOrCreateFilter(VCProject parent, string name) { foreach (VCFilter f in parent.Filters) { if (f.Name.Equals(name)) { return(f); } } return(parent.AddFilter(name)); }
public VCFilter AddVCFilter() { try { if (this.GetVCFilter() == null) { VCProject vcproject = this.Project.Object as VCProject; return(vcproject.AddFilter(this.Name) as VCFilter); } } catch { } return(null); }
private VCFilter GetOrCreateTestFilter() { VCProject vcproj = (VCProject)project.GetExtObjectAs <Project>().Object; IVCCollection filters = (IVCCollection)vcproj.Filters; VCFilter filter = (VCFilter)filters.Item("Test Suites"); if (filter == null) { filter = (VCFilter)vcproj.AddFilter("Test Suites"); } return(filter); }
public bool SetupSliceFilter(EnvDTE.Project dteProject) { VCProject project = dteProject.Object as VCProject; foreach (VCFilter f in project.Filters) { if (f.Name.Equals("Slice Files")) { if (string.IsNullOrEmpty(f.Filter) || !f.Filter.Equals("ice")) { f.Filter = "ice"; return(true); } return(false); } } VCFilter filter = project.AddFilter("Slice Files"); filter.Filter = "ice"; return(true); }
/// <summary> /// </summary> protected VCFilter AddFilter(string path) { VCFilter filter = null; var name = string.Empty; var dirs = path.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); foreach (var dir in dirs) { name = Path.Combine(name, dir); var item = ((IVCCollection)Project.Filters).Item(name); if (item != null) { filter = item; continue; } filter = filter == null?Project.AddFilter(dir) : filter.AddFilter(dir); } return(filter); }
public static void addAddons(VCProject vcproject, String ofRoot, IEnumerable <String> addons) { VCFilter addonsFolder = null; try { addonsFolder = vcproject.AddFilter("addons"); }catch (Exception e) { IVCCollection filters = vcproject.Filters; foreach (var filter in filters) { if (filter is VCFilter) { if (((VCFilter)filter).Name == "addons") { addonsFolder = ((VCFilter)filter); break; } } } } if (addonsFolder != null) { foreach (var addon in addons) { VCFilter addonFolder = addonsFolder.AddFilter(addon); var addonObj = new Addon(ofRoot, addon, vcproject.ProjectDirectory); addonObj.addFilesToVCFilter(addonFolder); addonObj.addIncludePathsToVCProject(vcproject); addonObj.addLibsToVCProject(vcproject); } vcproject.Save(); } else { throw new Exception("Couldn't create or find addonsFolder"); } }
public static void addAddons(VCProject vcproject, String ofRoot, IEnumerable<String> addons) { VCFilter addonsFolder = null; try { addonsFolder = vcproject.AddFilter("addons"); }catch(Exception e) { IVCCollection filters = vcproject.Filters; foreach(var filter in filters) { if(filter is VCFilter) { if(((VCFilter)filter).Name == "addons") { addonsFolder = ((VCFilter)filter); break; } } } } if (addonsFolder != null) { foreach (var addon in addons) { VCFilter addonFolder = addonsFolder.AddFilter(addon); var addonObj = new Addon(ofRoot, addon, vcproject.ProjectDirectory); addonObj.addFilesToVCFilter(addonFolder); addonObj.addIncludePathsToVCProject(vcproject); addonObj.addLibsToVCProject(vcproject); } vcproject.Save(); } else { throw new Exception("Couldn't create or find addonsFolder"); } }
public void ProjectFinishedGenerating(Project project) { // --- FILTERS --- // VCProject vcproject = project as VCProject; // Retrieve filters _filterHeaderQuestion = null; _filterHeaderRead = null; _filterHeaderWrite = null; _filterSourceQuestion = null; _filterSourceRead = null; _filterSourceWrite = null; foreach (VCFilter filter in vcproject.Filters) { if (filter.Name == _filterStringHeaderQuestion) { _filterHeaderQuestion = filter; } else if (filter.Name == _filterStringHeaderRead) { _filterHeaderRead = filter; } else if (filter.Name == _filterStringHeaderWrite) { _filterHeaderWrite = filter; } else if (filter.Name == _filterStringSourceQuestion) { _filterSourceQuestion = filter; } else if (filter.Name == _filterStringSourceRead) { _filterSourceRead = filter; } else if (filter.Name == _filterStringSourceWrite) { _filterSourceWrite = filter; } } // If any filters didn't already exist, make them! if (_filterHeaderQuestion == null) { _filterHeaderQuestion = vcproject.AddFilter(_filterStringHeaderQuestion); } if (_filterHeaderRead == null) { _filterHeaderRead = vcproject.AddFilter(_filterStringHeaderRead); } if (_filterHeaderWrite == null) { _filterHeaderWrite = vcproject.AddFilter(_filterStringHeaderWrite); } if (_filterSourceQuestion == null) { _filterSourceQuestion = vcproject.AddFilter(_filterStringSourceQuestion); } if (_filterSourceRead == null) { _filterSourceRead = vcproject.AddFilter(_filterStringSourceRead); } if (_filterSourceWrite == null) { _filterSourceWrite = vcproject.AddFilter(_filterStringSourceWrite); } // Add files to filters _filterHeaderQuestion.AddFile(_mainHeaderFilePath); _filterHeaderRead.AddFile(_readHeaderFilePath); _filterHeaderWrite.AddFile(_writeHeaderFilePath); _filterSourceQuestion.AddFile(_mainSourceFilePath); _filterSourceRead.AddFile(_readSourceFilePath); _filterSourceWrite.AddFile(_writeSourceFilePath); }
public static ProjectItem AddFileToProject(this Project project, FileInfo newSourceFile, string itemType = null) { string root = project.FullName; if (string.IsNullOrEmpty(root)) { return(null); } // TODO should refactor bunch of stuff here, get this in another place etc... // Fetch the active project EnvDTE.DTE dte = (EnvDTE.DTE)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SDTE)); VCProject prj = (VCProject)dte.Solution.Projects.Item(1).Object; // Get the source root string sourceRoot = string.Empty; IVCCollection projectFiles = prj.Files as IVCCollection; foreach (VCFile prjFile in projectFiles) { // If it's an actual file if (prjFile.FullPath.Contains(".cpp") || prjFile.FullPath.Contains(".h")) { sourceRoot = string.Concat(prjFile.FullPath.TakeWhile((c, i) => c == newSourceFile.DirectoryName[i])); break; } } // This means that the project has no files atm, so we do not know // where the source files should be stored! if (sourceRoot == string.Empty) { MessageBox.Show("Can't find the source files location!"); return(null); } // We can add filters // Find folder string filePath = newSourceFile.DirectoryName.Replace(sourceRoot, ""); // Get rid of the path until source root Queue <string> filterQueue = new Queue <string>(filePath.Split('\\')); // Now add the missing filters ProjectItem item = project.ProjectItems.Item(filterQueue.Peek()); ProjectItem lastItem = item; VCFilter filter = null; IVCCollection projFilters = prj.Filters as IVCCollection; // Initialize filter foreach (VCFilter _filter in projFilters) { if (_filter.CanonicalName.Equals(filterQueue.Peek())) { filter = _filter; break; } } // Root filter if (item == null) { filter = (VCFilter)prj.AddFilter(filterQueue.Peek()); // Reload item item = project.ProjectItems.Item(filterQueue.Peek()); lastItem = item; } string newFilterCanonPath = filterQueue.Peek(); filterQueue.Dequeue(); while (filterQueue.Count > 0) { item = item.ProjectItems.Item(filterQueue.Peek()); if (item == null) { filter = (VCFilter)filter.AddFilter(filterQueue.Peek()); newFilterCanonPath = string.Join("\\", newFilterCanonPath, filterQueue.Peek()); prj.Save(); item = lastItem.ProjectItems.Item(filterQueue.Peek()); } else { newFilterCanonPath = string.Join("\\", newFilterCanonPath, filterQueue.Peek()); // Must update the filter foreach (VCFilter _filter in (IVCCollection)prj.Filters) { if (_filter.CanonicalName.Equals(newFilterCanonPath)) { filter = _filter; break; } } } prj.Save(); lastItem = item; filterQueue.Dequeue(); } //int indexOfProjectNameSubstr = filePath.IndexOf($"{project.Name}", StringComparison.OrdinalIgnoreCase); //string filterString = filePath.Substring(indexOfProjectNameSubstr + project.Name.Length + 1); // +1 for \\ //var filters = filterString.Split('\\'); //// Add multilevel filters //ProjectItem item = project.ProjectItems.Item(filters[0]); //ProjectItem lastItem = item; //EnvDTE.DTE dte = (EnvDTE.DTE)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SDTE)); //VCProject prj = (VCProject)dte.Solution.Projects.Item(1).Object; //if (item == null) //{ // // Top level dir // prj.AddFilter(filters[0]); // item = project.ProjectItems.Item(filters[0]); //} //for (int i = 1; i < filters.Length; i++) //{ // item = item.ProjectItems.Item(filters[i]); // if (item == null) // { // //string canonicalFilterName = Path.Combine(filters.Take(i + 1).ToArray()); // string canonicalFilterName = string.Join(Path.DirectorySeparatorChar.ToString(), filters.Take(i).ToArray()); // //prj.AddFilter(canonicalFilterName); // foreach (VCFilter fltr in prj.Filters) // { // if (fltr.CanonicalName == canonicalFilterName) // { // // to i + 1 to add the next filter // for (int j = i; j < filters.Length; j++) // { // if (fltr.CanAddFilter(filters[i])) // { // fltr.AddFilter(filters[j]); // } // } // } // } // prj.Save(); // item = lastItem.ProjectItems.Item(filters[i]); // } // lastItem = item; //} //filter.AddFile(newSourceFile.FullName); lastItem.ProjectItems.AddFromFile(newSourceFile.FullName); lastItem.SetItemType(itemType); return(item); }