Skip to content
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 @@ -549,10 +549,10 @@ public async Task<ReturnResult> MoveItemsFromClipboard(DataPackageView packageVi

#region Rename

public Task<ReturnResult> RenameAsync(IStorageItem source, string newName, NameCollisionOption collision, bool registerHistory)
=> RenameAsync(source.FromStorageItem(), newName, collision, registerHistory);
public Task<ReturnResult> RenameAsync(IStorageItem source, string newName, NameCollisionOption collision, bool registerHistory, bool showExtensionDialog = true)
=> RenameAsync(source.FromStorageItem(), newName, collision, registerHistory, showExtensionDialog);

public async Task<ReturnResult> RenameAsync(IStorageItemWithPath source, string newName, NameCollisionOption collision, bool registerHistory)
public async Task<ReturnResult> RenameAsync(IStorageItemWithPath source, string newName, NameCollisionOption collision, bool registerHistory, bool showExtensionDialog = true)
{
var returnStatus = ReturnResult.InProgress;
var errorCode = new Progress<FileSystemStatusCode>();
Expand All @@ -567,10 +567,8 @@ public async Task<ReturnResult> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ public interface IFilesystemHelpers : IDisposable
/// <param name="newName">Desired new name</param>
/// <param name="collision">Determines what to do if item already exists</param>
/// <param name="registerHistory">Determines whether <see cref="IStorageHistory"/> is saved</param>
/// <param name="showExtensionDialog">Determines wheteher the Extension Modified Dialog is shown</param>
/// <returns><see cref="ReturnResult"/> of performed operation</returns>
Task<ReturnResult> RenameAsync(IStorageItem source, string newName, NameCollisionOption collision, bool registerHistory);
Task<ReturnResult> RenameAsync(IStorageItem source, string newName, NameCollisionOption collision, bool registerHistory, bool showExtensionDialog = true);

/// <summary>
/// Renames <paramref name="source"/> fullPath with <paramref name="newName"/>
Expand All @@ -257,7 +258,8 @@ public interface IFilesystemHelpers : IDisposable
/// <param name="newName">Desired new name</param>
/// <param name="collision">Determines what to do if item already exists</param>
/// <param name="registerHistory">Determines whether <see cref="IStorageHistory"/> is saved</param>
/// <param name="showExtensionDialog">Determines wheteher the Extension Modified Dialog is shown</param>
/// <returns><see cref="ReturnResult"/> of performed operation</returns>
Task<ReturnResult> RenameAsync(IStorageItemWithPath source, string newName, NameCollisionOption collision, bool registerHistory);
Task<ReturnResult> RenameAsync(IStorageItemWithPath source, string newName, NameCollisionOption collision, bool registerHistory, bool showExtensionDialog = true);
}
}
4 changes: 2 additions & 2 deletions src/Files.App/Helpers/UIFilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public static async Task PasteItemAsync(string destinationPath, IShellPage assoc
}
}

public static async Task<bool> RenameFileItemAsync(ListedItem item, string newName, IShellPage associatedInstance)
public static async Task<bool> RenameFileItemAsync(ListedItem item, string newName, IShellPage associatedInstance, bool showExtensionDialog = true)
{
if (item is AlternateStreamItem ads) // For alternate streams Name is not a substring ItemNameRaw
{
Expand All @@ -260,7 +260,7 @@ public static async Task<bool> 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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Views/Pages/PropertiesGeneral.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async Task<bool> 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);
Expand Down Expand Up @@ -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)
);
}
}
Expand Down