/// <summary> /// Adds a directory to the project hierarchy with the specified parent. /// </summary> protected void AddDirectory(HierarchyNode parent, bool isSearchPath, string subfolder) { var existing = parent.FindChild(Path.GetFileName(subfolder)); if (existing == null) { FolderNode folderNode = CreateFolderNode(subfolder); parent.AddChild(folderNode); CreateHierarchy(folderNode, subfolder, isSearchPath); } }
/// <summary> /// Adds a file to the project hierarchy with the specified parent. /// </summary> /// <param name="parent"></param> /// <param name="isSearchPath"></param> /// <param name="file"></param> protected void AddFile(HierarchyNode parent, bool isSearchPath, string file) { var existing = parent.FindChild(file); if (existing == null) { FileNode fileNode = CreateFileNode(file); //Files in search path are not considered memebers of the project itself fileNode.SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, isSearchPath); parent.AddChild(fileNode); } }
private static void AddNonMemberFileItems(WixProjectNode project, IList <string> fileList) { if (fileList == null) { throw new ArgumentNullException("fileList"); } foreach (string fileKey in fileList) { HierarchyNode parentNode = project; string[] pathItems = fileKey.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }); if (String.Equals(fileKey, project.ProjectFile, StringComparison.OrdinalIgnoreCase)) { continue; } WixFolderNode topFolderNode = null; foreach (string fileOrDir in pathItems) { string childNodeId = Path.Combine(parentNode.VirtualNodeName, fileOrDir); FileInfo fileOrDirInfo = new FileInfo(Path.Combine(project.ProjectFolder, childNodeId)); if ((fileOrDirInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { break; } HierarchyNode childNode = parentNode.FindChild(childNodeId); if (childNode == null) { if (topFolderNode == null) { topFolderNode = parentNode as WixFolderNode; if (topFolderNode != null && (!topFolderNode.IsNonMemberItem) && topFolderNode.IsExpanded) { topFolderNode = null; } } ProjectElement element = new ProjectElement(project, null, true); element.Rename(childNodeId); element.SetMetadata(ProjectFileConstants.Name, childNodeId); childNode = project.CreateFileNode(element); parentNode.AddChild(childNode); break; } parentNode = childNode; } if (topFolderNode != null) { topFolderNode.CollapseFolder(); } } }
private static void AddNonMemberFolderItems(XProjectNode project, IList <string> folderList) { if (folderList == null) { throw new ArgumentNullException("folderList"); } foreach (string folderKey in folderList) { HierarchyNode parentNode = project; string[] folders = folderKey.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); XFolderNode topFolderNode = null; foreach (string folder in folders) { string childNodeId = Path.Combine(parentNode.VirtualNodeName, folder); FileInfo folderInfo = new FileInfo(Path.Combine(project.ProjectFolder, childNodeId)); if ((folderInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { break; } HierarchyNode childNode = parentNode.FindChild(childNodeId); if (childNode == null) { if (topFolderNode == null) { topFolderNode = parentNode as XFolderNode; if (topFolderNode != null && (!topFolderNode.IsNonMemberItem) && topFolderNode.IsExpanded) { topFolderNode = null; } } ProjectElement element = new ProjectElement(project, null, true); childNode = project.CreateFolderNode(childNodeId, element); parentNode.AddChild(childNode); } parentNode = childNode; } ThreadHelper.ThrowIfNotOnUIThread(); if (topFolderNode != null) { topFolderNode.CollapseFolder(); } } }
private static void AddNonMemberFileItems(ProjectNode project, IEnumerable<string> fileList) { ErrorHelper.ThrowIsNull(fileList, "fileList"); foreach (string fileKey in fileList) { HierarchyNode parentNode = project; string[] pathItems = fileKey.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }); if (StringComparer.OrdinalIgnoreCase.Equals(fileKey, project.ProjectFile)) continue; NemerleFolderNode topFolderNode = null; foreach (string fileOrDir in pathItems) { string childNodeId = Path.Combine(parentNode.VirtualNodeName, fileOrDir); FileInfo fileOrDirInfo = new FileInfo(Path.Combine(project.ProjectFolder, childNodeId)); if ((fileOrDirInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) break; HierarchyNode childNode = parentNode.FindChild(childNodeId); if (childNode == null) { if (topFolderNode == null) { topFolderNode = parentNode as NemerleFolderNode; if (topFolderNode != null && (!topFolderNode.IsNonMemberItem) && topFolderNode.IsExpanded) topFolderNode = null; } ProjectElement element = new ProjectElement(project, null, true); element.Rename(childNodeId); element.SetMetadata(ProjectFileConstants.Name, childNodeId); childNode = project.CreateFileNode(element); parentNode.AddChild(childNode); break; } parentNode = childNode; } if (topFolderNode != null) topFolderNode.CollapseFolder(); } }
private static void AddNonMemberFolderItems(ProjectNode project, IEnumerable<string> folderList) { ErrorHelper.ThrowIsNull(folderList, "folderList"); foreach (string folderKey in folderList) { HierarchyNode parentNode = project; string[] folders = folderKey.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); NemerleFolderNode topFolderNode = null; foreach (string folder in folders) { string childNodeId = Path.Combine(parentNode.VirtualNodeName, folder); FileInfo folderInfo = new FileInfo(Path.Combine(project.ProjectFolder, childNodeId)); if ((folderInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) break; HierarchyNode childNode = parentNode.FindChild(childNodeId); if (childNode == null) { if (topFolderNode == null) { topFolderNode = parentNode as NemerleFolderNode; if (topFolderNode != null && (!topFolderNode.IsNonMemberItem) && topFolderNode.IsExpanded) topFolderNode = null; } ProjectElement element = new ProjectElement(project, null, true); childNode = project.CreateFolderNode(childNodeId, element); parentNode.AddChild(childNode); } parentNode = childNode; } if (topFolderNode != null) topFolderNode.CollapseFolder(); } }
private bool TryFindParentFileNode(HierarchyNode root, string child, out HierarchyNode parent) { parent = null; var childName = Path.GetFileName(child); var childDirectory = Path.GetDirectoryName(child); // the standart layout, used for most file types (aspx, ashx, master, xaml etc) // + - page.aspx // | + - page.aspx.n // | + - page.aspx.designer.n var parentName = Path.GetFileNameWithoutExtension(childName); while (parentName.IndexOf('.') > 0 && parent == null) { parent = root.FindChild(Path.Combine(childDirectory, parentName)); parentName = Path.GetFileNameWithoutExtension(parentName); } if (parent == null) { // Windows forms layout: // + - form.n // | + - form.designer.n var childNameWithoutExtension = Path.GetFileNameWithoutExtension(child); // look for suffix position (".Designer", etc) var suffixIndex = childNameWithoutExtension.LastIndexOf(root.NameRelationSeparator); if (suffixIndex < 0) return false; parentName = string.Format("{0}.n", childNameWithoutExtension.Substring(0, suffixIndex)); var parentPath = Path.Combine(childDirectory, parentName); parent = root.FindChild(parentPath); } return parent != null; }
/// <summary> /// Adds a folder into the project recursing and adding any sub-files and sub-directories. /// /// The user can be prompted to overwrite the existing files if the folder already exists /// in the project. They will be initially prompted to overwrite - if they answer no t /// we'll set promptOverwrite to false and when we recurse we won't prompt. If they say /// yes then we'll set it to true and we will prompt for individual files. /// </summary> private int AddDirectory(VSADDRESULT[] result, HierarchyNode n, string file, bool? promptOverwrite) { // need to recursively add all of the directory contents var fullPath = Path.Combine(GetBaseDirectoryForAddingFiles(n), Path.GetFileName(file)); HierarchyNode targetFolder = n.FindChild(fullPath, false); if (targetFolder == null) { var newChild = CreateFolderNode(fullPath); n.AddChild(newChild); targetFolder = newChild; } else if (promptOverwrite == null) { var res = MessageBox.Show( String.Format( @"This folder already contains a folder called '{0}'. If the files in the existing folder have the same names as files in the folder you are copying, do you want to replace the existing files?", Path.GetFileName(file)), "Merge Folders", MessageBoxButtons.YesNoCancel ); // yes means prompt for each file // no means don't prompt for any of the files // cancel means forget what I'm doing switch (res) { case DialogResult.Cancel: result[0] = VSADDRESULT.ADDRESULT_Cancel; return (int)OleConstants.OLECMDERR_E_CANCELED; case DialogResult.No: promptOverwrite = false; return VSConstants.S_OK; case DialogResult.Yes: promptOverwrite = true; break; } } // add the files... var dirFiles = Directory.GetFiles(file); Guid empty = Guid.Empty; var subRes = AddItemWithSpecificInternal( targetFolder.ID, VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE, null, (uint)dirFiles.Length, dirFiles, IntPtr.Zero, 0, ref empty, null, ref empty, result, promptOverwrite: promptOverwrite ); if (ErrorHandler.Failed(subRes)) { return subRes; } // add any subdirectories... var subDirs = Directory.GetDirectories(file); return AddItemWithSpecificInternal( targetFolder.ID, VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE, null, (uint)subDirs.Length, subDirs, IntPtr.Zero, 0, ref empty, null, ref empty, result, promptOverwrite: promptOverwrite ); }
protected override void AddNewFileNodeToHierarchy(HierarchyNode parentNode, string fileName) { // We have to take care of Dependant Files here // So any .Designer.prg, or .Xaml.Prg is depending from a parent which has the same prefix name // then we must set that parent as parentNode; Utilities.ArgumentNotNull("parentNode", parentNode); Dictionary<string, string> Dependencies = new Dictionary<string, string>(); Dependencies.Add(".designer.prg", ".prg"); Dependencies.Add(".xaml.prg", ".xaml"); Dependencies.Add(".vh", ".prg"); // Check if we can find the Parent int dotPos = fileName.IndexOf("."); string parentFile = fileName.Substring(0, dotPos); string extension = fileName.Substring(dotPos).ToLower(); // if ( Dependencies.ContainsKey(extension) ) { // HierarchyNode newParent = parentNode.FindChild(parentFile + Dependencies[extension]); if (newParent != null) { parentNode = newParent; // Ok, is it a XSharp node or something else ? var xsharpParent = parentNode as XSharpFileNode; if (xsharpParent != null) { xsharpParent.UpdateHasDesigner(); } } } // there are other possible parents. For Example Window1.prg is the parent of Window1.Windows.vnfrm // In this case the children are a VOBinary, Header or NativeResource switch (XSharpFileNode.GetFileType(fileName)) { case XSharpFileType.Header: case XSharpFileType.NativeResource: case XSharpFileType.VOFieldSpec: case XSharpFileType.VOForm: case XSharpFileType.VODBServer: case XSharpFileType.VOMenu: case XSharpFileType.VOOrder: case XSharpFileType.VOIndex: // dependent file HierarchyNode newParent = parentNode.FindChild(parentFile + ".prg"); if (newParent != null) { parentNode = newParent; } break; } base.AddNewFileNodeToHierarchy(parentNode, fileName); }
private static void SetBoldStartup(HierarchyNode parent) { string startupFile; CommonProjectNode comProj = (CommonProjectNode)parent.ProjectMgr; HierarchyNode startupItem; if (!comProj._boldedStartupItem && (startupFile = comProj.GetStartupFile()) != null && (startupItem = parent.FindChild(CommonUtils.GetAbsoluteFilePath(comProj.ProjectFolder, startupFile), false)) != null) { // we're expanding the parent of the comProj.BoldStartupItem(startupItem); } }