internal async Task <UniversalPackageFile> CreateDirectoryPromptAsync(UniversalPackage.FileCollection collection, string prefix, string name) { try { return(await collection.CreateDirectoryAsync(prefix + name)); } catch (ArgumentException) { name = await this.Dispatcher.InvokeAsync(() => { var prompt = new NamePromptWindow("Folder Name Conflict", "New folder name:", NamePromptWindow.CreateNameValidator(true, collection, collection == this.Package.Metadata, prefix)) { Text = name, Owner = this }; if (prompt.ShowDialog() == true) { return(prompt.Text); } return(null); }); if (name == null) { return(null); } return(await collection.CreateDirectoryAsync(prefix + name)); } }
private void Content_NewFolder(object sender, ExecutedRoutedEventArgs e) { var referenceFile = this.FileTree.SelectedItem; var collection = referenceFile == null ? this.Package.Files : referenceFile.Collection; var prefix = referenceFile == null ? string.Empty : referenceFile.FullName.Substring(0, referenceFile.FullName.LastIndexOf('/') + 1); var prompt = new NamePromptWindow("New Folder", "New folder name:", NamePromptWindow.CreateNameValidator(true, collection, collection == this.Package.Metadata, prefix)) { Owner = this }; if (prompt.ShowDialog() == true) { Task.Run(() => this.PerformOperationAsync(() => collection.CreateDirectoryAsync(prefix + prompt.Text + "/"), this.FocusInTree)); } }
private void Content_Rename(object sender, ExecutedRoutedEventArgs e) { var file = this.FileTree.SelectedItem; var prefix = file.FullName.Substring(0, file.FullName.LastIndexOf('/') + 1); var prompt = new NamePromptWindow("Rename", file.Children == null ? "Rename file to:" : "Rename folder to:", NamePromptWindow.CreateNameValidator(file.Children != null, file.Collection, file.Collection == this.Package.Metadata, prefix, file.Name)) { Text = file.Name, Owner = this }; if (prompt.ShowDialog() == true) { Task.Run(() => this.PerformOperationAsync(async() => { await file.RenameAsync(prefix + prompt.Text); return(file); }, this.FocusInTree)); } }
private void Content_ExistingFolder(object sender, ExecutedRoutedEventArgs e) { var referenceFile = this.FileTree.SelectedItem; var collection = referenceFile == null ? this.Package.Files : referenceFile.Collection; var prefix = referenceFile == null ? string.Empty : referenceFile.FullName.Substring(0, referenceFile.FullName.LastIndexOf('/') + 1); var dialog = new System.Windows.Forms.FolderBrowserDialog { ShowNewFolderButton = false }; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var folderName = dialog.SelectedPath; Task.Run(() => this.PerformOperationAsync(async() => { UniversalPackageFile rootFolder; try { rootFolder = await collection.CreateDirectoryAsync(prefix + Path.GetFileName(folderName)); } catch (ArgumentException) { var name = await this.Dispatcher.InvokeAsync(() => { var prompt = new NamePromptWindow("Existing File", "New file name:", NamePromptWindow.CreateNameValidator(true, collection, collection == this.Package.Metadata, prefix)) { Text = Path.GetFileName(folderName), Owner = this }; if (prompt.ShowDialog() == true) { return(prompt.Text); } return(null); }); if (name == null) { rootFolder = null; } else { rootFolder = await collection.CreateDirectoryAsync(prefix + Path.GetFileName(folderName)); } } await rootFolder?.ImportFromFileSystemAsync(folderName); return(rootFolder); }, rootFolder => { if (rootFolder != null) { this.FocusInTree(rootFolder); } })); } }
private void Content_ExistingFile(object sender, ExecutedRoutedEventArgs e) { var referenceFile = this.FileTree.SelectedItem; var collection = referenceFile == null ? this.Package.Files : referenceFile.Collection; var prefix = referenceFile == null ? string.Empty : referenceFile.FullName.Substring(0, referenceFile.FullName.LastIndexOf('/') + 1); var dialog = new OpenFileDialog { CheckFileExists = true, Multiselect = true, ValidateNames = true, Filter = "All files (*.*)|*.*" }; if (dialog.ShowDialog(this) == true) { Task.Run(() => this.PerformOperationAsync(async() => { UniversalPackageFile firstFile = null; foreach (var fileName in dialog.FileNames) { UniversalPackageFile file; try { file = await collection.CreateFileAsync(prefix + Path.GetFileName(fileName)); } catch (ArgumentException) { var name = await this.Dispatcher.InvokeAsync(() => { var prompt = new NamePromptWindow("Existing File", "New file name:", NamePromptWindow.CreateNameValidator(false, collection, collection == this.Package.Metadata, prefix)) { Text = Path.GetFileName(fileName), Owner = this }; if (prompt.ShowDialog() == true) { return(prompt.Text); } return(null); }); if (name == null) { continue; } file = await collection.CreateFileAsync(prefix + name); } if (firstFile == null) { firstFile = file; } using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.Asynchronous | FileOptions.SequentialScan)) { await file.CopyFromAsync(stream); } } return(firstFile); }, firstFile => { if (firstFile != null) { this.FocusInTree(firstFile); } })); } }