public static async Task <IStorageItem> CreateFileFromDialogResultTypeForResult(AddItemType itemType, ShellNewEntry itemInfo, IShellPage associatedInstance) { string currentPath = null; if (associatedInstance.SlimContentPage != null) { currentPath = associatedInstance.FilesystemViewModel.WorkingDirectory; } // Show rename dialog DynamicDialog dialog = DynamicDialogFactory.GetFor_RenameDialog(); await dialog.ShowAsync(); if (dialog.DynamicResult != DynamicDialogResult.Primary) { return(null); } // Create file based on dialog result string userInput = dialog.ViewModel.AdditionalData as string; var folderRes = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(currentPath); FilesystemResult <(ReturnResult, IStorageItem)> created = null; if (folderRes) { switch (itemType) { case AddItemType.Folder: userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized(); created = await FilesystemTasks.Wrap(async() => { return(await associatedInstance.FilesystemHelpers.CreateAsync( StorageItemHelpers.FromPathAndType(System.IO.Path.Combine(folderRes.Result.Path, userInput), FilesystemItemType.Directory), true)); }); break; case AddItemType.File: userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : itemInfo?.Name ?? "NewFile".GetLocalized(); created = await FilesystemTasks.Wrap(async() => { return(await associatedInstance.FilesystemHelpers.CreateAsync( StorageItemHelpers.FromPathAndType(System.IO.Path.Combine(folderRes.Result.Path, userInput + itemInfo?.Extension), FilesystemItemType.File), true)); }); break; } } if (created == FileSystemStatusCode.Unauthorized) { await DialogDisplayHelper.ShowDialogAsync("AccessDeniedCreateDialog/Title".GetLocalized(), "AccessDeniedCreateDialog/Text".GetLocalized()); } return(created.Result.Item2); }
public static async Task <IStorageItem> CreateFileFromDialogResultTypeForResult(AddItemDialogItemType itemType, ShellNewEntry itemInfo, IShellPage associatedInstance) { string currentPath = null; if (associatedInstance.SlimContentPage != null) { currentPath = associatedInstance.FilesystemViewModel.WorkingDirectory; if (App.LibraryManager.TryGetLibrary(currentPath, out var library)) { if (!library.IsEmpty && library.Folders.Count == 1) // TODO: handle libraries with multiple folders { currentPath = library.Folders.First(); } } } // Skip rename dialog when ShellNewEntry has a Command (e.g. ".accdb", ".gdoc") string userInput = null; if (itemType != AddItemDialogItemType.File || itemInfo?.Command == null) { DynamicDialog dialog = DynamicDialogFactory.GetFor_RenameDialog(); await dialog.ShowAsync(); // Show rename dialog if (dialog.DynamicResult != DynamicDialogResult.Primary) { return(null); } userInput = dialog.ViewModel.AdditionalData as string; } // Create file based on dialog result var folderRes = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(currentPath); var created = new FilesystemResult <(ReturnResult, IStorageItem)>((ReturnResult.Failed, null), FileSystemStatusCode.Generic); if (folderRes) { switch (itemType) { case AddItemDialogItemType.Folder: userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized(); created = await FilesystemTasks.Wrap(async() => { return(await associatedInstance.FilesystemHelpers.CreateAsync( StorageHelpers.FromPathAndType(PathNormalization.Combine(folderRes.Result.Path, userInput), FilesystemItemType.Directory), true)); }); break; case AddItemDialogItemType.File: userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : itemInfo?.Name ?? "NewFile".GetLocalized(); created = await FilesystemTasks.Wrap(async() => { return(await associatedInstance.FilesystemHelpers.CreateAsync( StorageHelpers.FromPathAndType(PathNormalization.Combine(folderRes.Result.Path, userInput + itemInfo?.Extension), FilesystemItemType.File), true)); }); break; } } if (created == FileSystemStatusCode.Unauthorized) { await DialogDisplayHelper.ShowDialogAsync("AccessDenied".GetLocalized(), "AccessDeniedCreateDialog/Text".GetLocalized()); } return(created.Result.Item2); }