void AddParentFolder(string virtualName, string relativeDirectoryPath, Dictionary <string, DirectoryNode> directoryNodeList) { if (relativeDirectoryPath.Length == 0 || string.Compare(virtualName, 0, relativeDirectoryPath, 0, relativeDirectoryPath.Length, StringComparison.OrdinalIgnoreCase) == 0) { // virtualName is a file in this folder, so we have to add its containing folder // to the project int pos = virtualName.IndexOf('/', relativeDirectoryPath.Length + 1); if (pos < 0) { return; } string subFolderName = virtualName.Substring(relativeDirectoryPath.Length, pos - relativeDirectoryPath.Length); DirectoryNode node; if (directoryNodeList.TryGetValue(subFolderName, out node)) { if (node.FileNodeStatus == FileNodeStatus.None) { node.FileNodeStatus = FileNodeStatus.InProject; } } else { node = new DirectoryNode(Path.Combine(Directory, subFolderName), FileNodeStatus.Missing); node.InsertSorted(this); directoryNodeList[subFolderName] = node; } } }
void AddDirectoryNodeTo(TreeNode parentNode, string directory) { var directoryNode = new DirectoryNode(directory, FileNodeStatus.InProject); directoryNode.InsertSorted(parentNode); }
protected override void Initialize() { if (removeMe != null) { Nodes.Remove(removeMe); removeMe = null; } LoggingService.Info("Initialize DirectoryNode " + Directory); Dictionary <string, FileNode> fileNodeDictionary = new Dictionary <string, FileNode>(StringComparer.OrdinalIgnoreCase); Dictionary <FileNode, string> dependendFileDictionary = new Dictionary <FileNode, string>(); Dictionary <string, DirectoryNode> directoryNodeList = new Dictionary <string, DirectoryNode>(StringComparer.OrdinalIgnoreCase); // Add files found in file system if (System.IO.Directory.Exists(Directory)) { foreach (string subDirectory in System.IO.Directory.GetDirectories(Directory)) { if (Path.GetFileName(subDirectory) != ".svn") { DirectoryNode newDirectoryNode = DirectoryNodeFactory.CreateDirectoryNode(this, Project, subDirectory); newDirectoryNode.InsertSorted(this); directoryNodeList[Path.GetFileName(subDirectory)] = newDirectoryNode; } } foreach (string file in System.IO.Directory.GetFiles(Directory)) { FileNode fileNode = new FileNode(file); fileNodeDictionary[Path.GetFileName(file)] = fileNode; fileNode.InsertSorted(this); } } if (Nodes.Count == 0) { SetClosedImage(); } string relativeDirectoryPath = this.RelativePath; if (relativeDirectoryPath.Length > 0) { relativeDirectoryPath = relativeDirectoryPath.Replace('\\', '/') + '/'; } // Add project items foreach (ProjectItem item in Project.Items) { if (item.ItemType == ItemType.WebReferenceUrl) { DirectoryNode node; if (directoryNodeList.TryGetValue(Path.GetFileName(item.FileName), out node)) { if (node.FileNodeStatus == FileNodeStatus.None) { node.FileNodeStatus = FileNodeStatus.InProject; } node.ProjectItem = item; } continue; } FileProjectItem fileItem = item as FileProjectItem; if (fileItem == null) { continue; } string virtualName = fileItem.VirtualName.Replace('\\', '/'); if (virtualName.EndsWith("/")) { virtualName = virtualName.Substring(0, virtualName.Length - 1); } string fileName = Path.GetFileName(virtualName); if (!string.Equals(virtualName, relativeDirectoryPath + fileName, StringComparison.OrdinalIgnoreCase)) { AddParentFolder(virtualName, relativeDirectoryPath, directoryNodeList); continue; } if (item.ItemType.IsFolder()) { DirectoryNode node; if (directoryNodeList.TryGetValue(fileName, out node)) { if (node.FileNodeStatus == FileNodeStatus.None) { node.FileNodeStatus = FileNodeStatus.InProject; } node.ProjectItem = item; } else { node = DirectoryNodeFactory.CreateDirectoryNode(item, FileNodeStatus.Missing); node.InsertSorted(this); directoryNodeList[fileName] = node; } } else { FileNode node; if (fileItem.IsLink) { node = new FileNode(fileItem.FileName, FileNodeStatus.InProject); node.InsertSorted(this); fileNodeDictionary[fileName] = node; } else { if (fileNodeDictionary.TryGetValue(fileName, out node)) { if (node.FileNodeStatus == FileNodeStatus.None) { node.FileNodeStatus = FileNodeStatus.InProject; } } else { node = new FileNode(fileItem.FileName, FileNodeStatus.Missing); node.InsertSorted(this); fileNodeDictionary[fileName] = node; } } node.ProjectItem = fileItem; if (fileItem != null && fileItem.DependentUpon != null && fileItem.DependentUpon.Length > 0) { dependendFileDictionary[node] = fileItem.DependentUpon; } } } // Insert 'code behind files' foreach (KeyValuePair <FileNode, string> pair in dependendFileDictionary) { string fileName = Path.GetFileName(pair.Value); if (!fileNodeDictionary.ContainsKey(fileName)) { continue; } AbstractProjectBrowserTreeNode parentNode = fileNodeDictionary[fileName]; pair.Key.Parent.Nodes.Remove(pair.Key); if (NodeIsParent(parentNode, pair.Key)) { // is pair.Key a parent of parentNode? // if yes, we have a parent cycle - break it by adding one node to the directory pair.Key.InsertSorted(this); } else { pair.Key.InsertSorted(parentNode); if (pair.Key.FileNodeStatus != FileNodeStatus.Missing) { pair.Key.FileNodeStatus = FileNodeStatus.BehindFile; } } } base.Initialize(); }
void AddParentFolder(string virtualName, string relativeDirectoryPath, Dictionary<string, DirectoryNode> directoryNodeList) { if (relativeDirectoryPath.Length == 0 || string.Compare(virtualName, 0, relativeDirectoryPath, 0, relativeDirectoryPath.Length, StringComparison.OrdinalIgnoreCase) == 0) { // virtualName is a file in this folder, so we have to add its containing folder // to the project int pos = virtualName.IndexOf('/', relativeDirectoryPath.Length + 1); if (pos < 0) return; string subFolderName = virtualName.Substring(relativeDirectoryPath.Length, pos - relativeDirectoryPath.Length); DirectoryNode node; if (directoryNodeList.TryGetValue(subFolderName, out node)) { if (node.FileNodeStatus == FileNodeStatus.None) { node.FileNodeStatus = FileNodeStatus.InProject; } } else { node = new DirectoryNode(Path.Combine(Directory, subFolderName), FileNodeStatus.Missing); node.InsertSorted(this); directoryNodeList[subFolderName] = node; } } }