diff --git a/src/Files.App/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs b/src/Files.App/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs index 23d04224134f..75567acc6cc2 100644 --- a/src/Files.App/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs +++ b/src/Files.App/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs @@ -549,10 +549,10 @@ public async Task MoveItemsFromClipboard(DataPackageView packageVi #region Rename - public Task RenameAsync(IStorageItem source, string newName, NameCollisionOption collision, bool registerHistory) - => RenameAsync(source.FromStorageItem(), newName, collision, registerHistory); + public Task RenameAsync(IStorageItem source, string newName, NameCollisionOption collision, bool registerHistory, bool showExtensionDialog = true) + => RenameAsync(source.FromStorageItem(), newName, collision, registerHistory, showExtensionDialog); - public async Task RenameAsync(IStorageItemWithPath source, string newName, NameCollisionOption collision, bool registerHistory) + public async Task RenameAsync(IStorageItemWithPath source, string newName, NameCollisionOption collision, bool registerHistory, bool showExtensionDialog = true) { var returnStatus = ReturnResult.InProgress; var errorCode = new Progress(); @@ -567,10 +567,8 @@ public async Task RenameAsync(IStorageItemWithPath source, string break; case FilesystemItemType.File: - - /* Only prompt user when extension has changed, - not when file name has changed */ - if (Path.GetExtension(source.Path) != Path.GetExtension(newName)) + if (showExtensionDialog && + Path.GetExtension(source.Path) != Path.GetExtension(newName)) // Only prompt user when extension has changed, not when file name has changed { var yesSelected = await DialogDisplayHelper.ShowDialogAsync("RenameFileDialogTitle".GetLocalizedResource(), "RenameFileDialog/Text".GetLocalizedResource(), "Yes".GetLocalizedResource(), "No".GetLocalizedResource()); if (yesSelected) diff --git a/src/Files.App/Filesystem/FilesystemOperations/Helpers/IFilesystemHelpers.cs b/src/Files.App/Filesystem/FilesystemOperations/Helpers/IFilesystemHelpers.cs index 245670f9fdf7..8c350755b5c9 100644 --- a/src/Files.App/Filesystem/FilesystemOperations/Helpers/IFilesystemHelpers.cs +++ b/src/Files.App/Filesystem/FilesystemOperations/Helpers/IFilesystemHelpers.cs @@ -247,8 +247,9 @@ public interface IFilesystemHelpers : IDisposable /// Desired new name /// Determines what to do if item already exists /// Determines whether is saved + /// Determines wheteher the Extension Modified Dialog is shown /// of performed operation - Task RenameAsync(IStorageItem source, string newName, NameCollisionOption collision, bool registerHistory); + Task RenameAsync(IStorageItem source, string newName, NameCollisionOption collision, bool registerHistory, bool showExtensionDialog = true); /// /// Renames fullPath with @@ -257,7 +258,8 @@ public interface IFilesystemHelpers : IDisposable /// Desired new name /// Determines what to do if item already exists /// Determines whether is saved + /// Determines wheteher the Extension Modified Dialog is shown /// of performed operation - Task RenameAsync(IStorageItemWithPath source, string newName, NameCollisionOption collision, bool registerHistory); + Task RenameAsync(IStorageItemWithPath source, string newName, NameCollisionOption collision, bool registerHistory, bool showExtensionDialog = true); } } \ No newline at end of file diff --git a/src/Files.App/Helpers/UIFilesystemHelpers.cs b/src/Files.App/Helpers/UIFilesystemHelpers.cs index 604e68b2687e..f3b15904bb97 100644 --- a/src/Files.App/Helpers/UIFilesystemHelpers.cs +++ b/src/Files.App/Helpers/UIFilesystemHelpers.cs @@ -233,7 +233,7 @@ public static async Task PasteItemAsync(string destinationPath, IShellPage assoc } } - public static async Task RenameFileItemAsync(ListedItem item, string newName, IShellPage associatedInstance) + public static async Task RenameFileItemAsync(ListedItem item, string newName, IShellPage associatedInstance, bool showExtensionDialog = true) { if (item is AlternateStreamItem ads) // For alternate streams Name is not a substring ItemNameRaw { @@ -260,7 +260,7 @@ public static async Task RenameFileItemAsync(ListedItem item, string newNa FilesystemItemType itemType = (item.PrimaryItemAttribute == StorageItemTypes.Folder) ? FilesystemItemType.Directory : FilesystemItemType.File; ReturnResult renamed = ReturnResult.InProgress; - renamed = await associatedInstance.FilesystemHelpers.RenameAsync(StorageHelpers.FromPathAndType(item.ItemPath, itemType), newName, NameCollisionOption.FailIfExists, true); + renamed = await associatedInstance.FilesystemHelpers.RenameAsync(StorageHelpers.FromPathAndType(item.ItemPath, itemType), newName, NameCollisionOption.FailIfExists, true, showExtensionDialog); if (renamed == ReturnResult.Success) { diff --git a/src/Files.App/Views/Pages/PropertiesGeneral.xaml.cs b/src/Files.App/Views/Pages/PropertiesGeneral.xaml.cs index 47e427706077..6290dbb17a99 100644 --- a/src/Files.App/Views/Pages/PropertiesGeneral.xaml.cs +++ b/src/Files.App/Views/Pages/PropertiesGeneral.xaml.cs @@ -64,7 +64,7 @@ async Task SaveLibraryAsync(LibraryItem library) newName = $"{newName}{ShellLibraryItem.EXTENSION}"; var file = new StorageFileWithPath(null, library.ItemPath); - var renamed = await AppInstance!.FilesystemHelpers.RenameAsync(file, newName, NameCollisionOption.FailIfExists, false); + var renamed = await AppInstance!.FilesystemHelpers.RenameAsync(file, newName, NameCollisionOption.FailIfExists, false, false); if (renamed is ReturnResult.Success) { var newPath = Path.Combine(Path.GetDirectoryName(library.ItemPath)!, newName); @@ -109,7 +109,7 @@ await App.Window.DispatcherQueue.EnqueueAsync(() => return true; return await App.Window.DispatcherQueue.EnqueueAsync(() => - UIFilesystemHelpers.RenameFileItemAsync(item, ViewModel.ItemName, AppInstance) + UIFilesystemHelpers.RenameFileItemAsync(item, ViewModel.ItemName, AppInstance, false) ); } }