|
4 | 4 | using CommunityToolkit.WinUI; |
5 | 5 | using Files.App.Controls; |
6 | 6 | using Files.Shared.Helpers; |
| 7 | +using Microsoft.Extensions.Logging; |
7 | 8 | using Microsoft.UI.Dispatching; |
8 | 9 | using Microsoft.UI.Xaml; |
9 | 10 | using Microsoft.UI.Xaml.Controls; |
@@ -1042,93 +1043,53 @@ public async Task PopulateOmnibarSuggestionsForPathMode() |
1042 | 1043 | { |
1043 | 1044 | PathModeSuggestionItems.Clear(); |
1044 | 1045 |
|
1045 | | - var result = await SafetyExtensions.IgnoreExceptions((Func<Task<bool>>)(async () => |
| 1046 | + try |
1046 | 1047 | { |
1047 | 1048 | List<OmnibarPathModeSuggestionModel>? newSuggestions = []; |
1048 | | - var pathText = this.PathText; |
| 1049 | + var pathText = PathText; |
1049 | 1050 |
|
1050 | 1051 | // If the current input is special, populate navigation history instead. |
1051 | | - if (string.IsNullOrWhiteSpace((string)pathText) || |
1052 | | - pathText is "Home" or "ReleaseNotes" or "Settings") |
| 1052 | + if (string.IsNullOrWhiteSpace(pathText) || |
| 1053 | + pathText.Equals("Home", StringComparison.OrdinalIgnoreCase) || |
| 1054 | + pathText.Equals("ReleaseNotes", StringComparison.OrdinalIgnoreCase) || |
| 1055 | + pathText.Equals("Settings", StringComparison.OrdinalIgnoreCase)) |
1053 | 1056 | { |
1054 | 1057 | // Load previously entered path |
1055 | 1058 | if (UserSettingsService.GeneralSettingsService.PathHistoryList is { } pathHistoryList) |
1056 | 1059 | { |
1057 | | - newSuggestions.AddRange(pathHistoryList.Select(x => new OmnibarPathModeSuggestionModel(x, x))); |
| 1060 | + pathHistoryList.Select(x => new OmnibarPathModeSuggestionModel(x, x)).ForEach(PathModeSuggestionItems.Add); |
1058 | 1061 | } |
1059 | 1062 | } |
1060 | 1063 | else |
1061 | 1064 | { |
1062 | | - var isFtp = FtpHelpers.IsFtpPath((string)pathText); |
1063 | | - pathText = NormalizePathInput((string)pathText, isFtp); |
1064 | | - var expandedPath = StorageFileExtensions.GetResolvedPath((string)pathText, isFtp); |
| 1065 | + var isFtp = FtpHelpers.IsFtpPath(pathText); |
| 1066 | + pathText = NormalizePathInput(pathText, isFtp); |
| 1067 | + var expandedPath = StorageFileExtensions.GetResolvedPath(pathText, isFtp); |
1065 | 1068 | var folderPath = PathNormalization.GetParentDir(expandedPath) ?? expandedPath; |
1066 | 1069 | StorageFolderWithPath folder = await ContentPageContext.ShellPage.ShellViewModel.GetFolderWithPathFromPathAsync(folderPath); |
1067 | 1070 | if (folder is null) |
1068 | | - return false; |
| 1071 | + AddNoResultsItem(); |
1069 | 1072 |
|
1070 | 1073 | var currPath = await folder.GetFoldersWithPathAsync(Path.GetFileName(expandedPath), MaxSuggestionsCount); |
1071 | 1074 | if (currPath.Count >= MaxSuggestionsCount) |
1072 | 1075 | { |
1073 | | - newSuggestions.AddRange(currPath.Select(x => new OmnibarPathModeSuggestionModel(x.Path, x.Item.DisplayName))); |
| 1076 | + currPath.Select(x => new OmnibarPathModeSuggestionModel(x.Path, x.Item.DisplayName)).ForEach(PathModeSuggestionItems.Add); |
1074 | 1077 | } |
1075 | 1078 | else if (currPath.Any()) |
1076 | 1079 | { |
1077 | 1080 | var subPath = await currPath.First().GetFoldersWithPathAsync((uint)(MaxSuggestionsCount - currPath.Count)); |
1078 | | - newSuggestions.AddRange(currPath.Select(x => new OmnibarPathModeSuggestionModel(x.Path, x.Item.DisplayName))); |
1079 | | - newSuggestions.AddRange(subPath.Select(x => new OmnibarPathModeSuggestionModel(x.Path, PathNormalization.Combine(currPath.First().Item.DisplayName, x.Item.DisplayName)))); |
| 1081 | + currPath.Select(x => new OmnibarPathModeSuggestionModel(x.Path, x.Item.DisplayName)).ForEach(PathModeSuggestionItems.Add); |
| 1082 | + currPath.Select(x => new OmnibarPathModeSuggestionModel(x.Path, PathNormalization.Combine(currPath.First().Item.DisplayName, x.Item.DisplayName))).ForEach(PathModeSuggestionItems.Add); |
1080 | 1083 | } |
1081 | 1084 | } |
1082 | 1085 |
|
1083 | 1086 | // If there are no suggestions, show "No suggestions" |
1084 | | - if (newSuggestions.Count is 0) |
1085 | | - { |
| 1087 | + if (PathModeSuggestionItems.Count is 0) |
1086 | 1088 | AddNoResultsItem(); |
1087 | | - } |
1088 | | - |
1089 | | - // Check whether at least one item is in common between the old and the new suggestions |
1090 | | - // since the suggestions popup becoming empty causes flickering |
1091 | | - if (!PathModeSuggestionItems.IntersectBy(newSuggestions, x => x.DisplayName).Any()) |
1092 | | - { |
1093 | | - // No items in common, update the list in-place |
1094 | | - for (int index = 0; index < newSuggestions.Count; index++) |
1095 | | - { |
1096 | | - if (index < PathModeSuggestionItems.Count) |
1097 | | - { |
1098 | | - PathModeSuggestionItems[index] = newSuggestions[index]; |
1099 | | - } |
1100 | | - else |
1101 | | - { |
1102 | | - PathModeSuggestionItems.Add(newSuggestions[index]); |
1103 | | - } |
1104 | | - } |
1105 | | - |
1106 | | - while (PathModeSuggestionItems.Count > newSuggestions.Count) |
1107 | | - PathModeSuggestionItems.RemoveAt(PathModeSuggestionItems.Count - 1); |
1108 | | - } |
1109 | | - else |
1110 | | - { |
1111 | | - // At least an element in common, show animation |
1112 | | - foreach (var s in PathModeSuggestionItems.ExceptBy(newSuggestions, x => x.DisplayName).ToList()) |
1113 | | - PathModeSuggestionItems.Remove(s); |
1114 | | - |
1115 | | - for (int index = 0; index < newSuggestions.Count; index++) |
1116 | | - { |
1117 | | - if (PathModeSuggestionItems.Count > index && PathModeSuggestionItems[index].DisplayName == newSuggestions[index].DisplayName) |
1118 | | - { |
1119 | | - PathModeSuggestionItems[index] = newSuggestions[index]; |
1120 | | - } |
1121 | | - else |
1122 | | - PathModeSuggestionItems.Insert(index, newSuggestions[index]); |
1123 | | - } |
1124 | | - } |
1125 | | - |
1126 | | - return true; |
1127 | | - })); |
1128 | | - |
1129 | | - if (!result) |
| 1089 | + } |
| 1090 | + catch (Exception ex) |
1130 | 1091 | { |
1131 | | - AddNoResultsItem(); |
| 1092 | + App.Logger?.LogInformation(ex, ex.Message); |
1132 | 1093 | } |
1133 | 1094 |
|
1134 | 1095 | void AddNoResultsItem() |
|
0 commit comments