Skip to content

Commit d79b16d

Browse files
lukeblevinsyaira2
andauthored
More Precise Exception Handling for Item Rename Operation (#1793)
Co-authored-by: Yair Aichenbaum <[email protected]>
1 parent c53a9c4 commit d79b16d

19 files changed

+633
-39
lines changed

Files/Interacts/Interaction.cs

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -784,50 +784,65 @@ public async Task<bool> RenameFileItem(ListedItem item, string oldName, string n
784784
return false;
785785
}
786786
}
787-
catch
787+
catch (Exception ex)
788788
{
789-
var ItemAlreadyExistsDialog = new ContentDialog()
789+
if (ex is ArgumentException)
790790
{
791-
Title = ResourceController.GetTranslation("ItemAlreadyExistsDialogTitle"),
792-
Content = ResourceController.GetTranslation("ItemAlreadyExistsDialogContent"),
793-
PrimaryButtonText = ResourceController.GetTranslation("ItemAlreadyExistsDialogPrimaryButtonText"),
794-
SecondaryButtonText = ResourceController.GetTranslation("ItemAlreadyExistsDialogSecondaryButtonText")
795-
};
796-
797-
ContentDialogResult result = await ItemAlreadyExistsDialog.ShowAsync();
798-
799-
if (result == ContentDialogResult.Primary)
791+
await DialogDisplayHelper.ShowDialog(ResourceController.GetTranslation("RenameError.NameInvalid.Title"), ResourceController.GetTranslation("RenameError.NameInvalid.Text"));
792+
}
793+
else if (ex is PathTooLongException)
794+
{
795+
await DialogDisplayHelper.ShowDialog(ResourceController.GetTranslation("RenameError.TooLong.Title"), ResourceController.GetTranslation("RenameError.TooLong.Text"));
796+
}
797+
else if (ex is FileNotFoundException)
800798
{
801-
if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
799+
await DialogDisplayHelper.ShowDialog(ResourceController.GetTranslation("RenameError.ItemDeleted.Title"), ResourceController.GetTranslation("RenameError.ItemDeleted.Text"));
800+
}
801+
else
802+
{
803+
var ItemAlreadyExistsDialog = new ContentDialog()
802804
{
803-
var folder = await ItemViewModel.GetFolderFromPathAsync(item.ItemPath);
805+
Title = ResourceController.GetTranslation("ItemAlreadyExistsDialogTitle"),
806+
Content = ResourceController.GetTranslation("ItemAlreadyExistsDialogContent"),
807+
PrimaryButtonText = ResourceController.GetTranslation("ItemAlreadyExistsDialogPrimaryButtonText"),
808+
SecondaryButtonText = ResourceController.GetTranslation("ItemAlreadyExistsDialogSecondaryButtonText")
809+
};
804810

805-
await folder.RenameAsync(newName, NameCollisionOption.GenerateUniqueName);
811+
ContentDialogResult result = await ItemAlreadyExistsDialog.ShowAsync();
806812

807-
App.JumpList.RemoveFolder(folder.Path);
808-
}
809-
else
813+
if (result == ContentDialogResult.Primary)
810814
{
811-
var file = await ItemViewModel.GetFileFromPathAsync(item.ItemPath);
815+
if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
816+
{
817+
var folder = await ItemViewModel.GetFolderFromPathAsync(item.ItemPath);
812818

813-
await file.RenameAsync(newName, NameCollisionOption.GenerateUniqueName);
814-
}
815-
}
816-
else if (result == ContentDialogResult.Secondary)
817-
{
818-
if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
819-
{
820-
var folder = await ItemViewModel.GetFolderFromPathAsync(item.ItemPath);
819+
await folder.RenameAsync(newName, NameCollisionOption.GenerateUniqueName);
821820

822-
await folder.RenameAsync(newName, NameCollisionOption.ReplaceExisting);
821+
App.JumpList.RemoveFolder(folder.Path);
822+
}
823+
else
824+
{
825+
var file = await ItemViewModel.GetFileFromPathAsync(item.ItemPath);
823826

824-
App.JumpList.RemoveFolder(folder.Path);
827+
await file.RenameAsync(newName, NameCollisionOption.GenerateUniqueName);
828+
}
825829
}
826-
else
830+
else if (result == ContentDialogResult.Secondary)
827831
{
828-
var file = await ItemViewModel.GetFileFromPathAsync(item.ItemPath);
832+
if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
833+
{
834+
var folder = await ItemViewModel.GetFolderFromPathAsync(item.ItemPath);
835+
836+
await folder.RenameAsync(newName, NameCollisionOption.ReplaceExisting);
837+
838+
App.JumpList.RemoveFolder(folder.Path);
839+
}
840+
else
841+
{
842+
var file = await ItemViewModel.GetFileFromPathAsync(item.ItemPath);
829843

830-
await file.RenameAsync(newName, NameCollisionOption.ReplaceExisting);
844+
await file.RenameAsync(newName, NameCollisionOption.ReplaceExisting);
845+
}
831846
}
832847
}
833848
}

Files/MultilingualResources/Files.de-DE.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,30 @@
11331133
<source>Sharing {0} {1}</source>
11341134
<target state="translated">Teilen {0} {1}</target>
11351135
</trans-unit>
1136+
<trans-unit id="RenameError.ItemDeleted.Text" translate="yes" xml:space="preserve">
1137+
<source>The item you're attempting to rename no longer exists. Please verify the correct location of the item you need to rename.</source>
1138+
<target state="new">The item you're attempting to rename no longer exists. Please verify the correct location of the item you need to rename.</target>
1139+
</trans-unit>
1140+
<trans-unit id="RenameError.ItemDeleted.Title" translate="yes" xml:space="preserve">
1141+
<source>Item no longer exists</source>
1142+
<target state="new">Item no longer exists</target>
1143+
</trans-unit>
1144+
<trans-unit id="RenameError.NameInvalid.Text" translate="yes" xml:space="preserve">
1145+
<source>The name specified was invalid. Please check the desired item name and try again.</source>
1146+
<target state="new">The name specified was invalid. Please check the desired item name and try again.</target>
1147+
</trans-unit>
1148+
<trans-unit id="RenameError.NameInvalid.Title" translate="yes" xml:space="preserve">
1149+
<source>Invalid item name</source>
1150+
<target state="new">Invalid item name</target>
1151+
</trans-unit>
1152+
<trans-unit id="RenameError.TooLong.Text" translate="yes" xml:space="preserve">
1153+
<source>The length of the item name specified exceeds the maximum limit. Please check the desired name and try again.</source>
1154+
<target state="new">The length of the item name specified exceeds the maximum limit. Please check the desired name and try again.</target>
1155+
</trans-unit>
1156+
<trans-unit id="RenameError.TooLong.Title" translate="yes" xml:space="preserve">
1157+
<source>Item name was too long</source>
1158+
<target state="new">Item name was too long</target>
1159+
</trans-unit>
11361160
<trans-unit id="ContextMenuMoreItemsLabel" translate="yes" xml:space="preserve">
11371161
<source>More</source>
11381162
<target state="translated">Mehr</target>

Files/MultilingualResources/Files.es-ES.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,30 @@
11301130
<source>Sharing {0} {1}</source>
11311131
<target state="translated">Compartiendo {0} {1}</target>
11321132
</trans-unit>
1133+
<trans-unit id="RenameError.ItemDeleted.Text" translate="yes" xml:space="preserve">
1134+
<source>The item you're attempting to rename no longer exists. Please verify the correct location of the item you need to rename.</source>
1135+
<target state="new">The item you're attempting to rename no longer exists. Please verify the correct location of the item you need to rename.</target>
1136+
</trans-unit>
1137+
<trans-unit id="RenameError.ItemDeleted.Title" translate="yes" xml:space="preserve">
1138+
<source>Item no longer exists</source>
1139+
<target state="new">Item no longer exists</target>
1140+
</trans-unit>
1141+
<trans-unit id="RenameError.NameInvalid.Text" translate="yes" xml:space="preserve">
1142+
<source>The name specified was invalid. Please check the desired item name and try again.</source>
1143+
<target state="new">The name specified was invalid. Please check the desired item name and try again.</target>
1144+
</trans-unit>
1145+
<trans-unit id="RenameError.NameInvalid.Title" translate="yes" xml:space="preserve">
1146+
<source>Invalid item name</source>
1147+
<target state="new">Invalid item name</target>
1148+
</trans-unit>
1149+
<trans-unit id="RenameError.TooLong.Text" translate="yes" xml:space="preserve">
1150+
<source>The length of the item name specified exceeds the maximum limit. Please check the desired name and try again.</source>
1151+
<target state="new">The length of the item name specified exceeds the maximum limit. Please check the desired name and try again.</target>
1152+
</trans-unit>
1153+
<trans-unit id="RenameError.TooLong.Title" translate="yes" xml:space="preserve">
1154+
<source>Item name was too long</source>
1155+
<target state="new">Item name was too long</target>
1156+
</trans-unit>
11331157
<trans-unit id="ContextMenuMoreItemsLabel" translate="yes" xml:space="preserve">
11341158
<source>More</source>
11351159
<target state="translated">Más</target>

Files/MultilingualResources/Files.fr-FR.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,30 @@
11301130
<source>Sharing {0} {1}</source>
11311131
<target state="new">Sharing {0} {1}</target>
11321132
</trans-unit>
1133+
<trans-unit id="RenameError.ItemDeleted.Text" translate="yes" xml:space="preserve">
1134+
<source>The item you're attempting to rename no longer exists. Please verify the correct location of the item you need to rename.</source>
1135+
<target state="new">The item you're attempting to rename no longer exists. Please verify the correct location of the item you need to rename.</target>
1136+
</trans-unit>
1137+
<trans-unit id="RenameError.ItemDeleted.Title" translate="yes" xml:space="preserve">
1138+
<source>Item no longer exists</source>
1139+
<target state="new">Item no longer exists</target>
1140+
</trans-unit>
1141+
<trans-unit id="RenameError.NameInvalid.Text" translate="yes" xml:space="preserve">
1142+
<source>The name specified was invalid. Please check the desired item name and try again.</source>
1143+
<target state="new">The name specified was invalid. Please check the desired item name and try again.</target>
1144+
</trans-unit>
1145+
<trans-unit id="RenameError.NameInvalid.Title" translate="yes" xml:space="preserve">
1146+
<source>Invalid item name</source>
1147+
<target state="new">Invalid item name</target>
1148+
</trans-unit>
1149+
<trans-unit id="RenameError.TooLong.Text" translate="yes" xml:space="preserve">
1150+
<source>The length of the item name specified exceeds the maximum limit. Please check the desired name and try again.</source>
1151+
<target state="new">The length of the item name specified exceeds the maximum limit. Please check the desired name and try again.</target>
1152+
</trans-unit>
1153+
<trans-unit id="RenameError.TooLong.Title" translate="yes" xml:space="preserve">
1154+
<source>Item name was too long</source>
1155+
<target state="new">Item name was too long</target>
1156+
</trans-unit>
11331157
<trans-unit id="ContextMenuMoreItemsLabel" translate="yes" xml:space="preserve">
11341158
<source>More</source>
11351159
<target state="translated">Plus</target>

Files/MultilingualResources/Files.he-IL.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,30 @@
11331133
<source>Sharing {0} {1}</source>
11341134
<target state="new">Sharing {0} {1}</target>
11351135
</trans-unit>
1136+
<trans-unit id="RenameError.ItemDeleted.Text" translate="yes" xml:space="preserve">
1137+
<source>The item you're attempting to rename no longer exists. Please verify the correct location of the item you need to rename.</source>
1138+
<target state="new">The item you're attempting to rename no longer exists. Please verify the correct location of the item you need to rename.</target>
1139+
</trans-unit>
1140+
<trans-unit id="RenameError.ItemDeleted.Title" translate="yes" xml:space="preserve">
1141+
<source>Item no longer exists</source>
1142+
<target state="new">Item no longer exists</target>
1143+
</trans-unit>
1144+
<trans-unit id="RenameError.NameInvalid.Text" translate="yes" xml:space="preserve">
1145+
<source>The name specified was invalid. Please check the desired item name and try again.</source>
1146+
<target state="new">The name specified was invalid. Please check the desired item name and try again.</target>
1147+
</trans-unit>
1148+
<trans-unit id="RenameError.NameInvalid.Title" translate="yes" xml:space="preserve">
1149+
<source>Invalid item name</source>
1150+
<target state="new">Invalid item name</target>
1151+
</trans-unit>
1152+
<trans-unit id="RenameError.TooLong.Text" translate="yes" xml:space="preserve">
1153+
<source>The length of the item name specified exceeds the maximum limit. Please check the desired name and try again.</source>
1154+
<target state="new">The length of the item name specified exceeds the maximum limit. Please check the desired name and try again.</target>
1155+
</trans-unit>
1156+
<trans-unit id="RenameError.TooLong.Title" translate="yes" xml:space="preserve">
1157+
<source>Item name was too long</source>
1158+
<target state="new">Item name was too long</target>
1159+
</trans-unit>
11361160
<trans-unit id="ContextMenuMoreItemsLabel" translate="yes" xml:space="preserve">
11371161
<source>More</source>
11381162
<target state="needs-review-translation" state-qualifier="tm-suggestion">עוד</target>

Files/MultilingualResources/Files.hi-IN.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,30 @@
11431143
<source>Sharing {0} {1}</source>
11441144
<target state="new">Sharing {0} {1}</target>
11451145
</trans-unit>
1146+
<trans-unit id="RenameError.ItemDeleted.Text" translate="yes" xml:space="preserve">
1147+
<source>The item you're attempting to rename no longer exists. Please verify the correct location of the item you need to rename.</source>
1148+
<target state="new">The item you're attempting to rename no longer exists. Please verify the correct location of the item you need to rename.</target>
1149+
</trans-unit>
1150+
<trans-unit id="RenameError.ItemDeleted.Title" translate="yes" xml:space="preserve">
1151+
<source>Item no longer exists</source>
1152+
<target state="new">Item no longer exists</target>
1153+
</trans-unit>
1154+
<trans-unit id="RenameError.NameInvalid.Text" translate="yes" xml:space="preserve">
1155+
<source>The name specified was invalid. Please check the desired item name and try again.</source>
1156+
<target state="new">The name specified was invalid. Please check the desired item name and try again.</target>
1157+
</trans-unit>
1158+
<trans-unit id="RenameError.NameInvalid.Title" translate="yes" xml:space="preserve">
1159+
<source>Invalid item name</source>
1160+
<target state="new">Invalid item name</target>
1161+
</trans-unit>
1162+
<trans-unit id="RenameError.TooLong.Text" translate="yes" xml:space="preserve">
1163+
<source>The length of the item name specified exceeds the maximum limit. Please check the desired name and try again.</source>
1164+
<target state="new">The length of the item name specified exceeds the maximum limit. Please check the desired name and try again.</target>
1165+
</trans-unit>
1166+
<trans-unit id="RenameError.TooLong.Title" translate="yes" xml:space="preserve">
1167+
<source>Item name was too long</source>
1168+
<target state="new">Item name was too long</target>
1169+
</trans-unit>
11461170
<trans-unit id="ContextMenuMoreItemsLabel" translate="yes" xml:space="preserve">
11471171
<source>More</source>
11481172
<target state="new">More</target>

Files/MultilingualResources/Files.it-IT.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,30 @@
11431143
<source>Sharing {0} {1}</source>
11441144
<target state="new">Sharing {0} {1}</target>
11451145
</trans-unit>
1146+
<trans-unit id="RenameError.ItemDeleted.Text" translate="yes" xml:space="preserve">
1147+
<source>The item you're attempting to rename no longer exists. Please verify the correct location of the item you need to rename.</source>
1148+
<target state="new">The item you're attempting to rename no longer exists. Please verify the correct location of the item you need to rename.</target>
1149+
</trans-unit>
1150+
<trans-unit id="RenameError.ItemDeleted.Title" translate="yes" xml:space="preserve">
1151+
<source>Item no longer exists</source>
1152+
<target state="new">Item no longer exists</target>
1153+
</trans-unit>
1154+
<trans-unit id="RenameError.NameInvalid.Text" translate="yes" xml:space="preserve">
1155+
<source>The name specified was invalid. Please check the desired item name and try again.</source>
1156+
<target state="new">The name specified was invalid. Please check the desired item name and try again.</target>
1157+
</trans-unit>
1158+
<trans-unit id="RenameError.NameInvalid.Title" translate="yes" xml:space="preserve">
1159+
<source>Invalid item name</source>
1160+
<target state="new">Invalid item name</target>
1161+
</trans-unit>
1162+
<trans-unit id="RenameError.TooLong.Text" translate="yes" xml:space="preserve">
1163+
<source>The length of the item name specified exceeds the maximum limit. Please check the desired name and try again.</source>
1164+
<target state="new">The length of the item name specified exceeds the maximum limit. Please check the desired name and try again.</target>
1165+
</trans-unit>
1166+
<trans-unit id="RenameError.TooLong.Title" translate="yes" xml:space="preserve">
1167+
<source>Item name was too long</source>
1168+
<target state="new">Item name was too long</target>
1169+
</trans-unit>
11461170
<trans-unit id="ContextMenuMoreItemsLabel" translate="yes" xml:space="preserve">
11471171
<source>More</source>
11481172
<target state="translated">Altri elementi</target>

0 commit comments

Comments
 (0)