Skip to content
Merged
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
43 changes: 19 additions & 24 deletions src/Files.App/Helpers/UIFilesystemHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
using Files.Shared;
using Files.App.Dialogs;
using Files.Shared.Enums;
using Files.Shared.Extensions;
using Files.App.Filesystem;
using Files.App.Filesystem.StorageItems;
using Files.App.Interacts;
using Files.App.ViewModels;
using Files.App.Extensions;
using Files.Backend.Enums;
using Files.Shared;
using Files.Shared.Enums;
using Files.Shared.Extensions;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel.AppService;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation.Collections;
using Windows.Storage;
using Files.Backend.Enums;
using Windows.System;
using Microsoft.UI.Xaml.Controls;

namespace Files.App.Helpers
{
Expand Down Expand Up @@ -255,26 +253,24 @@ public static async Task<bool> RenameFileItemAsync(ListedItem item, string newNa
StringComparison.Ordinal);
newName = $"{ads.MainStreamName}:{newName}";
}
else if (string.IsNullOrEmpty(item.Name))
{
newName = string.Concat(newName, item.FileExtension);
}
else
{
newName = item.ItemNameRaw.Replace(item.Name, newName, StringComparison.Ordinal);
}

if (item.ItemNameRaw == newName || string.IsNullOrEmpty(newName))
{
return true;
}

FilesystemItemType itemType = (item.PrimaryItemAttribute == StorageItemTypes.Folder) ? FilesystemItemType.Directory : FilesystemItemType.File;

ReturnResult renamed = ReturnResult.InProgress;
if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
{
renamed = await associatedInstance.FilesystemHelpers.RenameAsync(StorageHelpers.FromPathAndType(item.ItemPath, FilesystemItemType.Directory),
newName, NameCollisionOption.FailIfExists, true);
}
else
{
renamed = await associatedInstance.FilesystemHelpers.RenameAsync(StorageHelpers.FromPathAndType(item.ItemPath, FilesystemItemType.File),
newName, NameCollisionOption.FailIfExists, true);
}
renamed = await associatedInstance.FilesystemHelpers.RenameAsync(StorageHelpers.FromPathAndType(item.ItemPath, itemType), newName, NameCollisionOption.FailIfExists, true);

if (renamed == ReturnResult.Success)
{
Expand All @@ -286,7 +282,7 @@ public static async Task<bool> RenameFileItemAsync(ListedItem item, string newNa

public static async void CreateFileFromDialogResultType(AddItemDialogItemType itemType, ShellNewEntry itemInfo, IShellPage associatedInstance)
{
_ = await CreateFileFromDialogResultTypeForResult(itemType, itemInfo, associatedInstance);
await CreateFileFromDialogResultTypeForResult(itemType, itemInfo, associatedInstance);
}

// WINUI3
Expand All @@ -305,12 +301,11 @@ public static async Task<IStorageItem> CreateFileFromDialogResultTypeForResult(A
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();
}
if (App.LibraryManager.TryGetLibrary(currentPath, out var library) &&
!library.IsEmpty &&
library.Folders.Count == 1) // TODO: handle libraries with multiple folders
{
currentPath = library.Folders.First();
}
}

Expand Down