From a388df2f7454237aa6075c6e3ec52ab0febefe01 Mon Sep 17 00:00:00 2001 From: stefnotch Date: Tue, 22 Dec 2020 22:46:52 +0100 Subject: [PATCH] Better handle double file extensions on rename Fix #37 --- Source/Editor/Windows/ContentWindow.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index acea1e665..655ac653f 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -296,9 +296,14 @@ namespace FlaxEditor.Windows return; } + // Renaming a file to an extension it already has + if (!item.IsFolder && StringUtils.NormalizeExtension(Path.GetExtension(newShortName)) == StringUtils.NormalizeExtension(Path.GetExtension(item.Path))) + { + newShortName = StringUtils.GetPathWithoutExtension(newShortName); + } + // Check if name is valid - string hint; - if (!Editor.ContentEditing.IsValidAssetName(item, newShortName, out hint)) + if (!Editor.ContentEditing.IsValidAssetName(item, newShortName, out string hint)) { // Invalid name MessageBox.Show("Given asset name is invalid. " + hint, @@ -317,8 +322,8 @@ namespace FlaxEditor.Windows } // Cache data - var extension = Path.GetExtension(item.Path); - var newPath = StringUtils.CombinePaths(item.ParentFolder.Path, Path.ChangeExtension(newShortName, extension)); + string extension = Path.GetExtension(item.Path); + var newPath = StringUtils.CombinePaths(item.ParentFolder.Path, newShortName + extension); // Check if was renaming mock element // Note: we create `_newElement` and then rename it to create new asset