/// <summary> /// Copies or moves a file node (and the corresponding file, if applicable) to this directory, /// discarding its DependentUpon value. /// </summary> /// <param name="fileNode">The file node to copy or move.</param> /// <param name="performMove">true to move the file node, false to copy it.</param> public void CopyFileHere(FileNode node, bool performMove) { if (node.FileNodeStatus == FileNodeStatus.None) { AddExistingItemsToProject.CopyFile(node.FileName, this, false); if (performMove) { FileService.RemoveFile(node.FileName, false); } } else if (node.IsLink) { string relFileName = FileUtility.GetRelativePath(Project.Directory, node.FileName); FileNode fileNode = new FileNode(node.FileName, FileNodeStatus.InProject); FileProjectItem fileProjectItem = new FileProjectItem(Project, Project.GetDefaultItemType(node.FileName)); fileProjectItem.Include = relFileName; fileProjectItem.SetEvaluatedMetadata("Link", Path.Combine(RelativePath, Path.GetFileName(node.FileName))); fileNode.ProjectItem = fileProjectItem; fileNode.InsertSorted(this); ProjectService.AddProjectItem(Project, fileProjectItem); if (performMove) { ProjectService.RemoveProjectItem(node.Project, node.ProjectItem); node.Remove(); } } else { CopyFileHere(node.FileName, performMove); } }
/// <summary> /// Create's a new FileProjectItem in this DirectoryNode. /// </summary> /// <param name="fileName">The name of the file that will be added to the project.</param> public FileProjectItem AddNewFile(string fileName) { //TODO: this can probably be moved to AbstractProjectBrowserTreeNode or even lower in the chain. this.Expanding(); FileNode fileNode = new FileNode(fileName, FileNodeStatus.InProject); fileNode.InsertSorted(this); fileNode.EnsureVisible(); return(IncludeFileInProject.IncludeFileNode(fileNode)); }
//public override void DoDragDrop(IDataObject dataObject, DragDropEffects effect) public virtual void DoDragDrop(IDataObject dataObject, DragDropEffects effect) { if (dataObject.GetDataPresent(typeof(FileNode))) { // Dragging a file onto another creates a dependency. FileNode other = (FileNode)dataObject.GetData(typeof(FileNode)); LoggingService.Debug("ProjectBrowser: Dragging file '" + other.FileName + "' onto file '" + this.FileName + "'"); // Copy/move the file to the correct directory // if the target is in a different directory than the source. if (!FileUtility.IsEqualFileName(Path.GetDirectoryName(this.FileName), Path.GetDirectoryName(other.FileName))) { LoggingService.Debug("-> Source file is in different directory, performing " + effect.ToString()); ExtTreeNode p = this; DirectoryNode parentDirectory; do { p = (ExtTreeNode)p.Parent; parentDirectory = p as DirectoryNode; } while (parentDirectory == null && p != null); if (parentDirectory == null) { throw new InvalidOperationException("File '" + this.FileName + "' does not have a parent directory."); } LoggingService.Debug("-> Copying/Moving source file to parent directory of target: " + parentDirectory.Directory); string otherFileName = Path.GetFileName(other.FileName); parentDirectory.CopyFileHere(other, effect == DragDropEffects.Move); // Find the copied or moved file node again other = parentDirectory.AllNodes.OfType <FileNode>().SingleOrDefault(n => FileUtility.IsEqualFileName(Path.GetFileName(n.FileName), otherFileName)); } if (other != null) { other.Remove(); ((FileProjectItem)other.ProjectItem).DependentUpon = Path.GetFileName(this.FileName); other.FileNodeStatus = FileNodeStatus.BehindFile; other.InsertSorted(this); LoggingService.Debug("-> Created new dependency, saving solution"); ProjectService.SaveSolution(); } else { LoggingService.Debug("-> Could not find the copied or moved file node in the new parent directory."); } return; } //((ExtTreeNode)Parent).DoDragDrop(dataObject, effect); DragDrop.DoDragDrop(this, dataObject, effect); }
public override void DoDragDrop(IDataObject dataObject, DragDropEffects effect) { PerformInitialization(); Expand(); try { if (dataObject.GetDataPresent(typeof(FileNode))) { FileNode fileNode = (FileNode)dataObject.GetData(typeof(FileNode)); LoggingService.Debug("ProjectBrowser: Dragging file '" + fileNode.FileName + "' onto directory '" + this.Directory + "'"); if (!FileUtility.IsEqualFileName(Directory, fileNode.FileName) && !FileUtility.IsEqualFileName(Directory, Path.GetDirectoryName(fileNode.FileName)) && !(fileNode.ProjectItem is FileProjectItem && FileUtility.IsEqualFileName(Directory, Path.GetDirectoryName(GetFullVirtualName((FileProjectItem)fileNode.ProjectItem))))) { LoggingService.Debug("-> Not in same directory, performing " + effect.ToString()); CopyFileHere(fileNode, effect == DragDropEffects.Move); } else { // Dragging a dependent file onto its parent directory // removes the dependency. LoggingService.Debug("-> In same directory, removing dependency"); ((FileProjectItem)fileNode.ProjectItem).DependentUpon = String.Empty; fileNode.Remove(); if (!File.Exists(fileNode.FileName)) { fileNode.FileNodeStatus = FileNodeStatus.Missing; } else { fileNode.FileNodeStatus = FileNodeStatus.InProject; } fileNode.InsertSorted(this); } } else if (dataObject.GetDataPresent(typeof(DirectoryNode))) { DirectoryNode directoryNode = (DirectoryNode)dataObject.GetData(typeof(DirectoryNode)); CopyDirectoryHere(directoryNode, effect == DragDropEffects.Move); } else if (dataObject.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])dataObject.GetData(DataFormats.FileDrop); if (files != null) { foreach (string fileName in files) { if (System.IO.Directory.Exists(fileName)) { if (!FileUtility.IsBaseDirectory(fileName, Directory)) { CopyDirectoryHere(fileName, false); } } else { CopyFileHere(fileName, false); } } } } ProjectService.SaveSolution(); } catch (Exception e) { MessageService.ShowException(e); } }
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 AddFileNodeTo(TreeNode node, FileNodeStatus status = FileNodeStatus.InProject) { var fileNode = new FileNode(newFileAddedToProject.FileName, status); fileNode.InsertSorted(node); }
/// <summary> /// Copies or moves a file node (and the corresponding file, if applicable) to this directory, /// discarding its DependentUpon value. /// </summary> /// <param name="fileNode">The file node to copy or move.</param> /// <param name="performMove">true to move the file node, false to copy it.</param> public void CopyFileHere(FileNode node, bool performMove) { if (node.FileNodeStatus == FileNodeStatus.None) { AddExistingItemsToProject.CopyFile(node.FileName, this, false); if (performMove) { FileService.RemoveFile(node.FileName, false); } } else if (node.IsLink) { string relFileName = FileUtility.GetRelativePath(Project.Directory, node.FileName); FileNode fileNode = new FileNode(node.FileName, FileNodeStatus.InProject); FileProjectItem fileProjectItem = new FileProjectItem(Project, Project.GetDefaultItemType(node.FileName)); fileProjectItem.Include = relFileName; fileProjectItem.SetEvaluatedMetadata("Link", Path.Combine(RelativePath, Path.GetFileName(node.FileName))); fileNode.ProjectItem = fileProjectItem; fileNode.InsertSorted(this); ProjectService.AddProjectItem(Project, fileProjectItem); if (performMove) { ProjectService.RemoveProjectItem(node.Project, node.ProjectItem); node.Remove(); } } else { CopyFileHere(node.FileName, performMove); } }
/// <summary> /// Create's a new FileProjectItem in this DirectoryNode. /// </summary> /// <param name="fileName">The name of the file that will be added to the project.</param> public FileProjectItem AddNewFile(string fileName) { //TODO: this can probably be moved to AbstractProjectBrowserTreeNode or even lower in the chain. this.Expanding(); FileNode fileNode = new FileNode(fileName, FileNodeStatus.InProject); fileNode.InsertSorted(this); fileNode.EnsureVisible(); return IncludeFileInProject.IncludeFileNode(fileNode); }
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 == ItemType.Folder || item.ItemType == ItemType.WebReferences) { 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(); }