Skip to content

Fix create folder with selection #8929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ await sourceMatch.Select(x => x.dest).ToListAsync(),
if (createdSources.Any())
{
var item = StorageHelpers.FromPathAndType(createdSources.Single().Destination, source.ItemType);
return (new StorageHistory(FileOperationType.CreateNew, item.CreateList(), null), item.Item);
var storageItem = await item.ToStorageItem(associatedInstance);
return (new StorageHistory(FileOperationType.CreateNew, item.CreateList(), null), storageItem);
}
return (null, null);
}
Expand Down
52 changes: 22 additions & 30 deletions src/Files.Uwp/Helpers/UIFilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ await associatedInstance.SlimContentPage.SelectedItems.ToList().ParallelForEachA
{
_ = CoreApplication.MainView.DispatcherQueue.TryEnqueue(Windows.System.DispatcherQueuePriority.Low, () =>
{
// Dim opacities accordingly
listedItem.Opacity = Constants.UI.DimItemOpacity;
// Dim opacities accordingly
listedItem.Opacity = Constants.UI.DimItemOpacity;
});
}
if (listedItem is FtpItem ftpItem)
Expand Down Expand Up @@ -329,53 +329,45 @@ public static async Task<IStorageItem> CreateFileFromDialogResultTypeForResult(A
}

// 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)
(ReturnResult Status, IStorageItem Item) created = (ReturnResult.Failed, null);
switch (itemType)
{
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.Folder:
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized();
created = await associatedInstance.FilesystemHelpers.CreateAsync(
StorageHelpers.FromPathAndType(PathNormalization.Combine(currentPath, 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;
}
case AddItemDialogItemType.File:
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : itemInfo?.Name ?? "NewFile".GetLocalized();
created = await associatedInstance.FilesystemHelpers.CreateAsync(
StorageHelpers.FromPathAndType(PathNormalization.Combine(currentPath, userInput + itemInfo?.Extension), FilesystemItemType.File),
true);
break;
}

if (created == FileSystemStatusCode.Unauthorized)
if (created.Status == ReturnResult.AccessUnauthorized)
{
await DialogDisplayHelper.ShowDialogAsync("AccessDenied".GetLocalized(), "AccessDeniedCreateDialog/Text".GetLocalized());
}

return created.Result.Item2;
return created.Item;
}

public static async Task CreateFolderWithSelectionAsync(IShellPage associatedInstance)
{
try
{
await CopyItem(associatedInstance);
var items = associatedInstance.SlimContentPage.SelectedItems.ToList().Select((item) => StorageHelpers.FromPathAndType(
item.ItemPath,
item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
var folder = await CreateFileFromDialogResultTypeForResult(AddItemDialogItemType.Folder, null, associatedInstance);
if (folder == null)
{
return;
}
await associatedInstance.FilesystemHelpers.MoveItemsFromClipboard(Clipboard.GetContent(), folder.Path, false, true);
await associatedInstance.FilesystemHelpers.MoveItemsAsync(items, items.Select(x => PathNormalization.Combine(folder.Path, x.Name)), false, true);
}
catch (Exception ex)
{
Expand Down