Skip to content

Commit 8c350ae

Browse files
authored
Fix create folder with selection (#8929)
1 parent 0b565ce commit 8c350ae

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

src/Files.Uwp/Filesystem/FilesystemOperations/ShellFilesystemOperations.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ await sourceMatch.Select(x => x.dest).ToListAsync(),
260260
if (createdSources.Any())
261261
{
262262
var item = StorageHelpers.FromPathAndType(createdSources.Single().Destination, source.ItemType);
263-
return (new StorageHistory(FileOperationType.CreateNew, item.CreateList(), null), item.Item);
263+
var storageItem = await item.ToStorageItem(associatedInstance);
264+
return (new StorageHistory(FileOperationType.CreateNew, item.CreateList(), null), storageItem);
264265
}
265266
return (null, null);
266267
}

src/Files.Uwp/Helpers/UIFilesystemHelpers.cs

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ await associatedInstance.SlimContentPage.SelectedItems.ToList().ParallelForEachA
5959
{
6060
_ = CoreApplication.MainView.DispatcherQueue.TryEnqueue(Windows.System.DispatcherQueuePriority.Low, () =>
6161
{
62-
// Dim opacities accordingly
63-
listedItem.Opacity = Constants.UI.DimItemOpacity;
62+
// Dim opacities accordingly
63+
listedItem.Opacity = Constants.UI.DimItemOpacity;
6464
});
6565
}
6666
if (listedItem is FtpItem ftpItem)
@@ -329,53 +329,45 @@ public static async Task<IStorageItem> CreateFileFromDialogResultTypeForResult(A
329329
}
330330

331331
// Create file based on dialog result
332-
var folderRes = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(currentPath);
333-
var created = new FilesystemResult<(ReturnResult, IStorageItem)>((ReturnResult.Failed, null), FileSystemStatusCode.Generic);
334-
if (folderRes)
332+
(ReturnResult Status, IStorageItem Item) created = (ReturnResult.Failed, null);
333+
switch (itemType)
335334
{
336-
switch (itemType)
337-
{
338-
case AddItemDialogItemType.Folder:
339-
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized();
340-
created = await FilesystemTasks.Wrap(async () =>
341-
{
342-
return await associatedInstance.FilesystemHelpers.CreateAsync(
343-
StorageHelpers.FromPathAndType(PathNormalization.Combine(folderRes.Result.Path, userInput), FilesystemItemType.Directory),
344-
true);
345-
});
346-
break;
335+
case AddItemDialogItemType.Folder:
336+
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized();
337+
created = await associatedInstance.FilesystemHelpers.CreateAsync(
338+
StorageHelpers.FromPathAndType(PathNormalization.Combine(currentPath, userInput), FilesystemItemType.Directory),
339+
true);
340+
break;
347341

348-
case AddItemDialogItemType.File:
349-
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : itemInfo?.Name ?? "NewFile".GetLocalized();
350-
created = await FilesystemTasks.Wrap(async () =>
351-
{
352-
return await associatedInstance.FilesystemHelpers.CreateAsync(
353-
StorageHelpers.FromPathAndType(PathNormalization.Combine(folderRes.Result.Path, userInput + itemInfo?.Extension), FilesystemItemType.File),
354-
true);
355-
});
356-
break;
357-
}
342+
case AddItemDialogItemType.File:
343+
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : itemInfo?.Name ?? "NewFile".GetLocalized();
344+
created = await associatedInstance.FilesystemHelpers.CreateAsync(
345+
StorageHelpers.FromPathAndType(PathNormalization.Combine(currentPath, userInput + itemInfo?.Extension), FilesystemItemType.File),
346+
true);
347+
break;
358348
}
359349

360-
if (created == FileSystemStatusCode.Unauthorized)
350+
if (created.Status == ReturnResult.AccessUnauthorized)
361351
{
362352
await DialogDisplayHelper.ShowDialogAsync("AccessDenied".GetLocalized(), "AccessDeniedCreateDialog/Text".GetLocalized());
363353
}
364354

365-
return created.Result.Item2;
355+
return created.Item;
366356
}
367357

368358
public static async Task CreateFolderWithSelectionAsync(IShellPage associatedInstance)
369359
{
370360
try
371361
{
372-
await CopyItem(associatedInstance);
362+
var items = associatedInstance.SlimContentPage.SelectedItems.ToList().Select((item) => StorageHelpers.FromPathAndType(
363+
item.ItemPath,
364+
item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
373365
var folder = await CreateFileFromDialogResultTypeForResult(AddItemDialogItemType.Folder, null, associatedInstance);
374366
if (folder == null)
375367
{
376368
return;
377369
}
378-
await associatedInstance.FilesystemHelpers.MoveItemsFromClipboard(Clipboard.GetContent(), folder.Path, false, true);
370+
await associatedInstance.FilesystemHelpers.MoveItemsAsync(items, items.Select(x => PathNormalization.Combine(folder.Path, x.Name)), false, true);
379371
}
380372
catch (Exception ex)
381373
{

0 commit comments

Comments
 (0)