/// <summary> /// Initializes a new instance of the <see cref="FileExplorerNodeRenameArgs"/> class. /// </summary> /// <param name="node">The node being renamed.</param> /// <param name="oldName">The old name.</param> /// <param name="newName">The new name.</param> public FileExplorerNodeRenameArgs(IFileExplorerNodeVm node, string oldName, string newName) : base(false) { Node = node; OldName = oldName; NewName = newName; }
/// <summary>Function to retrieve a path from the file system.</summary> /// <param name="initialPath">The starting path to select.</param> /// <param name="caption">The caption for the dialog.</param> /// <param name="description">The description of what the browser is supposed to be doing.</param> /// <returns>The selected path, or <b>null</b> if canceled.</returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="initialPath"/> parameter is <b>null</b>.</exception> /// <exception cref="ArgumentEmptyException">Thrown when the <paramref name="initialPath"/> parameter is emtpy.</exception> /// <exception cref="IOException">Thrown if no <see cref="FileSystemRoot"/> is set.</exception> public string GetFolderPath(string initialPath, string caption, string description) { if (initialPath == null) { throw new ArgumentNullException(nameof(initialPath)); } if (string.IsNullOrWhiteSpace(initialPath)) { throw new ArgumentEmptyException(nameof(initialPath)); } if (FileSystem == null) { throw new IOException(Resources.GOREDIT_ERR_NO_ROOT); } IFileExplorerNodeVm initialPathNode = FileSystem.FindNode(initialPath); if (initialPathNode == null) { initialPathNode = FileSystem.RootNode; } using (var browser = new FormFileSystemFolderBrowser() { Text = caption, Description = description }) { browser.SetDataContext(FileSystem); browser.SetInitialPath(initialPathNode); return(browser.ShowDialog(GetParentForm()) != DialogResult.OK ? null : browser.CurrentDirectory.FormatDirectory('/')); } }
/// <summary> /// Function to create a file explorer node view model for a file. /// </summary> /// <param name="project">The project data.</param> /// <param name="fileSystemService">The file system service used to manipulate the underlying physical file system.</param> /// <param name="parent">The parent for the node.</param> /// <param name="file">The file system file to wrap in the view model.</param> /// <param name="metaData">[Optional] The metadata for the file.</param> /// <returns>The new file explorer node view model.</returns> private IFileExplorerNodeVm DoCreateFileExplorerFileNode(IProject project, IFileSystemService fileSystemService, IFileExplorerNodeVm parent, FileInfo file, ProjectItemMetadata metaData, IReadOnlyList <IFileExplorerNodeVm> openFiles) { var result = new FileExplorerFileNodeVm(); // If this node already exists, then don't recreate it and just send it back. // This way, we don't need to worry about running around trying to update changed nodes. _pathBuilder.Length = 0; _pathBuilder.Append(parent.FullPath); _pathBuilder.Append(file.Name); string newPath = _pathBuilder.ToString(); IFileExplorerNodeVm openFile = openFiles?.FirstOrDefault(item => string.Equals(item.FullPath, newPath, StringComparison.OrdinalIgnoreCase)); if (openFile != null) { if (parent.Children.All(item => !string.Equals(item.FullPath, newPath, StringComparison.OrdinalIgnoreCase))) { parent.Children.Add(openFile); openFile.Refresh(); (openFile as IContentFile)?.RefreshMetadata(); } return(openFile); } result.Initialize(new FileExplorerNodeParameters(file.FullName, project, this, fileSystemService) { Parent = parent, Metadata = metaData }); if (result.Metadata == null) { if (project.ProjectItems.TryGetValue(result.FullPath, out ProjectItemMetadata existingMetaData)) { result.Metadata = existingMetaData; } else { result.Metadata = new ProjectItemMetadata(); } } parent.Children.Add(result); return(result); }
/// <summary> /// Function to enumerate the physical file system to build the node hierarchy. /// </summary> /// <param name="project">The project being evaluated.</param> /// <param name="fileSystemService">The file system service used to retrieve file system data.</param> /// <param name="parent">The parent of the nodes.</param> /// <param name="openFiles">A list of files that are open in the editor.</param> private void DoEnumerateFileSystemObjects(IProject project, IFileSystemService fileSystemService, IFileExplorerNodeVm parent, IReadOnlyList <IFileExplorerNodeVm> openFiles = null) { var directoryNodes = new Dictionary <string, IFileExplorerNodeVm>(StringComparer.OrdinalIgnoreCase); string parentPhysicalPath; if (parent.Parent == null) { parentPhysicalPath = project.FileSystemDirectory.FullName.FormatDirectory(Path.DirectorySeparatorChar); directoryNodes[parentPhysicalPath] = parent; } else { parentPhysicalPath = parent.PhysicalPath.FormatDirectory(Path.DirectorySeparatorChar); directoryNodes[parentPhysicalPath] = parent; } foreach (DirectoryInfo directory in fileSystemService.GetDirectories(parentPhysicalPath).OrderBy(item => item.FullName.Length)) { string directoryParentPath = directory.Parent.FullName.FormatDirectory(Path.DirectorySeparatorChar); string directoryPath = directory.FullName.FormatDirectory(Path.DirectorySeparatorChar); if (!directoryNodes.TryGetValue(directoryParentPath, out IFileExplorerNodeVm parentNode)) { Program.Log.Print($"ERROR: Directory '{directoryParentPath}' is the parent of '{directory.Name}', but is not found in the index list.", LoggingLevel.Simple); continue; } IFileExplorerNodeVm node = CreateFileExplorerDirectoryNodeVm(project, fileSystemService, parentNode, directory, true); directoryNodes[directoryPath] = node; // Get files for this directory. foreach (FileInfo file in fileSystemService.GetFiles(directory.FullName, false)) { DoCreateFileExplorerFileNode(project, fileSystemService, node, file, null, openFiles); } } // Get files for this directory. foreach (FileInfo file in fileSystemService.GetFiles(parentPhysicalPath, false)) { DoCreateFileExplorerFileNode(project, fileSystemService, parent, file, null, openFiles); } }
/// <summary> /// Function to perform the scan used to determine whether a content file has an associated plugin or not. /// </summary> /// <param name="node">The node to scan.</param> /// <param name="contentFileManager">The file manager used to manage content file data.</param> /// <param name="scanProgress">The callback method used to report progress of the scan.</param> /// <param name="deepScan"><b>true</b> to perform a more time consuming scan, or <b>false</b> to just scan by file name extension.</param> /// <param name="forceScan">[Optional] <b>true</b> to force the scan, even if content metadata is already available, or <b>false</b> to skip files with content metadata already.</param> /// <returns><b>true</b> if the content plugin metadata was updated, <b>false</b> if not.</returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="node"/>, <paramref name="contentFileManager"/> or the <paramref name="scanProgress"/> parameter is <b>null</b>.</exception> public bool Scan(IFileExplorerNodeVm node, IContentFileManager contentFileManager, Action <string, int, int> scanProgress, bool deepScan, bool forceScan = false) { if (node == null) { throw new ArgumentNullException(nameof(node)); } if (contentFileManager == null) { throw new ArgumentNullException(nameof(contentFileManager)); } if (scanProgress == null) { throw new ArgumentNullException(nameof(scanProgress)); } IEnumerable <IFileExplorerNodeVm> contentFiles; int fileCount; if (node.Children.Count > 0) { contentFiles = node.Children.Traverse(n => n.Children) .Where(n => ((n.Metadata != null) && (n.IsContent) && ((forceScan) || (n.Metadata.ContentMetadata == null)))); fileCount = contentFiles.Count(); } else { contentFiles = new IFileExplorerNodeVm[] { node }; fileCount = 1; } if (fileCount == 0) { return(false); } bool result = false; int count = 0; var prevDeps = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (IContentFile contentFile in contentFiles.OfType <IContentFile>()) { string pluginName = contentFile.Metadata.PlugInName; if (forceScan) { contentFile.Metadata.ContentMetadata = null; contentFile.Metadata.DependsOn.Clear(); } prevDeps.Clear(); foreach (KeyValuePair <string, string> dep in contentFile.Metadata.DependsOn) { prevDeps[dep.Key] = dep.Value; } if (_contentPlugIns.AssignContentPlugIn(contentFile, contentFileManager, !deepScan)) { if ((!string.Equals(pluginName, contentFile.Metadata.PlugInName, StringComparison.OrdinalIgnoreCase)) || (!CompareDependencyLists(contentFile.Metadata.DependsOn, prevDeps))) { result = true; } } scanProgress.Invoke(contentFile.Path, ++count, fileCount); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="ListViewItemDragData"/> class. /// </summary> /// <param name="item">The list item being dragged.</param> /// <param name="node">The file system node being dragged.</param> /// <param name="dragOperation">The desired drag operation.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="item"/>, or the <paramref name="node"/> parameter is <b>null</b>.</exception> public ListViewItemDragData(ListViewItem item, IFileExplorerNodeVm node, DragOperation dragOperation) { Item = item ?? throw new ArgumentNullException(nameof(item)); Node = node ?? throw new ArgumentNullException(nameof(node)); DragOperation = dragOperation; }
/// <summary>Initializes a new instance of the <see cref="CreateNodeArgs"/> class.</summary> /// <param name="parent">The parent of the new node.</param> public CreateNodeArgs(IFileExplorerNodeVm parent) => ParentNode = parent;
/// <summary> /// Function to create a new dependency node. /// </summary> /// <param name="project">The project that contains the file system.</param> /// <param name="fileSystemService">The file system service for the project.</param> /// <param name="parentNode">The node to use as a the parent of the node.</param> /// <param name="content">The content object referenced by the dependency node.</param> /// <returns>A new dependency node.</returns> /// <exception cref="ArgumentNullException">Thrown when any of the parameters are <b>null</b>.</exception> public DependencyNode CreateDependencyNode(IProject project, IFileSystemService fileSystemService, IFileExplorerNodeVm parentNode, IContentFile content) { if (project == null) { throw new ArgumentNullException(nameof(project)); } if (parentNode == null) { throw new ArgumentNullException(nameof(parentNode)); } if (content == null) { throw new ArgumentNullException(nameof(content)); } var fileNode = (IFileExplorerNodeVm)content; var dependNode = new DependencyNode(parentNode, (IFileExplorerNodeVm)content); dependNode.Initialize(new FileExplorerNodeParameters(fileNode.PhysicalPath, project, this, fileSystemService)); return(dependNode); }
/// <summary> /// Function to create a file explorer node view model for a directory. /// </summary> /// <param name="project">The project data.</param> /// <param name="fileSystemService">The file system service used to manipulate the underlying physical file system.</param> /// <param name="parentNode">The parent for the node.</param> /// <param name="metadataManager">The metadata manager to use.</param> /// <param name="directory">The file system directory to wrap in the view model.</param> /// <param name="addToParent"><b>true</b> to automatically add the node to the parent, <b>false</b> to just return the node without adding to the parent.</param> /// <returns>The new file explorer node view model.</returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="project"/>, <paramref name="fileSystemService"/>, <paramref name="parentNode"/>, or the <paramref name="directory"/> parameter is <b>null</b>.</exception> public IFileExplorerNodeVm CreateFileExplorerDirectoryNodeVm(IProject project, IFileSystemService fileSystemService, IFileExplorerNodeVm parentNode, DirectoryInfo directory, bool addToParent) { if (project == null) { throw new ArgumentNullException(nameof(project)); } if (fileSystemService == null) { throw new ArgumentNullException(nameof(fileSystemService)); } if (parentNode == null) { throw new ArgumentNullException(nameof(parentNode)); } if (directory == null) { throw new ArgumentNullException(nameof(directory)); } var result = new FileExplorerDirectoryNodeVm(); var children = new ObservableCollection <IFileExplorerNodeVm>(); result.Initialize(new FileExplorerNodeParameters(directory.FullName, project, this, fileSystemService) { Metadata = new ProjectItemMetadata(), Parent = parentNode, Children = children }); if (addToParent) { parentNode.Children.Add(result); } return(result); }
/// <summary> /// Function to create a file explorer node view model for a directory. /// </summary> /// <param name="project">The project data.</param> /// <param name="fileSystemService">The file system service used to manipulate the underlying physical file system.</param> /// <param name="parentNode">The parent for the node.</param> /// <param name="newNodeName">The name of the new node.</param> /// <returns>The new file explorer node view model.</returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="project"/>, <paramref name="fileSystemService"/>, <paramref name="parentNode"/>, or the <paramref name="directory"/> parameter is <b>null</b>.</exception> public IFileExplorerNodeVm CreateNewDirectoryNode(IProject project, IFileSystemService fileSystemService, IFileExplorerNodeVm parentNode, string newNodeName) { var parent = new DirectoryInfo(parentNode.PhysicalPath); DirectoryInfo directory = string.IsNullOrWhiteSpace(newNodeName) ? fileSystemService.CreateDirectory(parent) : fileSystemService.CreateDirectory(parent, newNodeName); return(CreateFileExplorerDirectoryNodeVm(project, fileSystemService, parentNode, directory, true)); }
/// <summary> /// Function to create a file explorer node view model for a file. /// </summary> /// <param name="project">The project data.</param> /// <param name="fileSystemService">The file system service used to manipulate the underlying physical file system.</param> /// <param name="parent">The parent for the node.</param> /// <param name="file">The file system file to wrap in the view model.</param> /// <param name="metaData">[Optional] The metadata for the file.</param> /// <returns>The new file explorer node view model.</returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="project"/>, <paramref name="metadataManager"/>, <paramref name="fileSystemService"/> or the <paramref name="file"/> parameter is <b>null</b>.</exception> public IFileExplorerNodeVm CreateFileExplorerFileNodeVm(IProject project, IFileSystemService fileSystemService, IFileExplorerNodeVm parent, FileInfo file, ProjectItemMetadata metaData = null) { if (project == null) { throw new ArgumentNullException(nameof(project)); } if (fileSystemService == null) { throw new ArgumentNullException(nameof(fileSystemService)); } if (file == null) { throw new ArgumentNullException(nameof(file)); } return(DoCreateFileExplorerFileNode(project, fileSystemService, parent, file, metaData, null)); }
/// <summary> /// Function to enumerate the physical file system to build the node hierarchy. /// </summary> /// <param name="project">The project being evaluated.</param> /// <param name="fileSystemService">The file system service used to retrieve file system data.</param> /// <param name="parent">The parent of the nodes.</param> /// <param name="openFiles">A list of files that are open in the editor.</param> /// <returns>A hierarchy of nodes representing the physical file system.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <b>null</b>.</exception> /// <exception cref="ArgumentEmptyException">Thrown when the <paramref name="path"/> parameter is empty.</exception> public void EnumerateFileSystemObjects(IProject project, IFileSystemService fileSystemService, IFileExplorerNodeVm parent, IReadOnlyList <IFileExplorerNodeVm> openFiles) { if (project == null) { throw new ArgumentNullException(nameof(project)); } if (fileSystemService == null) { throw new ArgumentNullException(nameof(fileSystemService)); } if (parent == null) { throw new ArgumentNullException(nameof(parent)); } DoEnumerateFileSystemObjects(project, fileSystemService, parent, openFiles); }
/// <summary>Initializes a new instance of the <see cref="T:Gorgon.Editor.ViewModels.DeletNodeArgs"/> class.</summary> /// <param name="node">The node being deleted.</param> public DeleteNodeArgs(IFileExplorerNodeVm node) => Node = node;
/// <summary> /// Initializes a new instance of the <see cref="FileExplorerParameters" /> class. /// </summary> /// <param name="fileSystemService">The file system service to use for manipulating the virtual file system.</param> /// <param name="fileSearch">The service used to search for files in the file explorer.</param> /// <param name="rootNode">The root node for the file system tree.</param> /// <param name="viewModelFactory">The view model factory.</param> /// <param name="project">The project data.</param> /// <exception cref="ArgumentNullException">Thrown when any of the parameters are <b>null</b>.</exception> public FileExplorerParameters(IFileSystemService fileSystemService, ISearchService <IFileExplorerNodeVm> fileSearch, IFileExplorerNodeVm rootNode, IProject project, ViewModelFactory viewModelFactory) : base(viewModelFactory) { Project = project ?? throw new ArgumentNullException(nameof(project)); FileSystemService = fileSystemService ?? throw new ArgumentNullException(nameof(fileSystemService)); RootNode = rootNode ?? throw new ArgumentNullException(nameof(rootNode)); FileSearch = fileSearch ?? throw new ArgumentNullException(nameof(fileSearch)); }
/// <summary> /// Initializes a new instance of the <see cref="TreeNodeDragData"/> class. /// </summary> /// <param name="treeNode">The tree node being dragged.</param> /// <param name="node">The file system node being dragged.</param> /// <param name="dragOperation">The desired drag operation.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="treeNode"/>, or the <paramref name="node"/> parameter is <b>null</b>.</exception> public TreeNodeDragData(KryptonTreeNode treeNode, IFileExplorerNodeVm node, DragOperation dragOperation) { TreeNode = treeNode ?? throw new ArgumentNullException(nameof(treeNode)); Node = node ?? throw new ArgumentNullException(nameof(node)); DragOperation = dragOperation; }
/// <summary> /// Initializes a new instance of the <see cref="CopyNodeArgs"/> class. /// </summary> /// <param name="source">The source node to copy.</param> /// <param name="dest">The destination node that will receive the copy.</param> public CopyNodeArgs(IFileExplorerNodeVm source, IFileExplorerNodeVm dest) { Source = source; Dest = dest; }