Better handle double file extensions on rename

Fix #37
This commit is contained in:
stefnotch
2020-12-22 22:46:52 +01:00
parent 2c6a70b744
commit a388df2f74

View File

@@ -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