/// <summary> /// Function to create a project view model. /// </summary> /// <param name="projectData">The project data to assign to the project view model.</param> /// <returns>The project view model.</returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="projectData"/> parameter is <b>null</b>.</exception> public async Task <IProjectVm> CreateProjectViewModelAsync(IProject projectData) { if (projectData == null) { throw new ArgumentNullException(nameof(projectData)); } var result = new ProjectVm(); var fileSystemService = new FileSystemService(projectData.FileSystemDirectory); await Task.Run(() => { FileExplorerVm fileExplorer = CreateFileExplorerViewModel(projectData, fileSystemService); result.ContentFileManager = fileExplorer; result.FileExplorer = fileExplorer; }); var previewer = new ContentPreviewVm(); var thumbDirectory = new DirectoryInfo(Path.Combine(projectData.TempDirectory.FullName, "thumbs")); if (!thumbDirectory.Exists) { thumbDirectory.Create(); thumbDirectory.Refresh(); } previewer.Initialize(new ContentPreviewVmParameters(result.FileExplorer, result.ContentFileManager, thumbDirectory, this)); result.ContentPreviewer = previewer; result.Initialize(new ProjectVmParameters(projectData, this)); // Empty this list, it will be rebuilt when we save, and having it lying around is a waste. projectData.ProjectItems.Clear(); return(result); }
/// <summary> /// Function to create a file explorer view model. /// </summary> /// <param name="project">The project data.</param> /// <param name="fileSystemService">The file system service for the project.</param> /// <returns>The file explorer view model.</returns> private FileExplorerVm CreateFileExplorerViewModel(IProject project, IFileSystemService fileSystemService) { project.FileSystemDirectory.Refresh(); if (!project.FileSystemDirectory.Exists) { throw new DirectoryNotFoundException(string.Format(Resources.GOREDIT_ERR_DIRECTORY_NOT_FOUND, project.FileSystemDirectory.FullName)); } var result = new FileExplorerVm(); _folderBrowser.FileSystem = result; var root = new FileExplorerRootNode(); // This is a special node, used internally. root.Initialize(new FileExplorerNodeParameters(project.FileSystemDirectory.FullName.FormatDirectory(Path.DirectorySeparatorChar), project, this, fileSystemService)); DoEnumerateFileSystemObjects(project, fileSystemService, root); var search = new FileSystemSearchSystem(root); result.Initialize(new FileExplorerParameters(fileSystemService, search, root, project, this)); // Walk through the content plug ins and register custom search keywords. foreach (ContentPlugIn plugin in ContentPlugIns.PlugIns.Values) { plugin.RegisterSearchKeywords(search); } return(result); }