|
1 | 1 | // Copyright (c) Files Community
|
2 | 2 | // Licensed under the MIT License.
|
3 | 3 |
|
4 |
| -using System.Windows.Input; |
5 | 4 | using Microsoft.UI.Input;
|
6 | 5 | using Microsoft.UI.Xaml;
|
7 | 6 | using Microsoft.UI.Xaml.Controls;
|
8 | 7 | using Microsoft.UI.Xaml.Controls.Primitives;
|
9 | 8 | using Microsoft.UI.Xaml.Input;
|
10 | 9 | using Microsoft.UI.Xaml.Media;
|
11 |
| -using Windows.System; |
12 | 10 | using Microsoft.UI.Xaml.Navigation;
|
| 11 | +using System.Windows.Input; |
| 12 | +using Windows.System; |
13 | 13 | using FocusManager = Microsoft.UI.Xaml.Input.FocusManager;
|
14 | 14 |
|
15 | 15 | namespace Files.App.UserControls
|
@@ -161,37 +161,49 @@ private async void ForwardHistoryFlyout_Opening(object? sender, object e)
|
161 | 161 | await AddHistoryItemsAsync(shellPage.ForwardStack, ForwardHistoryFlyout.Items, false);
|
162 | 162 | }
|
163 | 163 |
|
164 |
| - private async Task AddHistoryItemsAsync(IEnumerable<PageStackEntry> items, IList<MenuFlyoutItemBase> destination, bool isBackMode) |
| 164 | + private async Task AddHistoryItemsAsync(IEnumerable<PageStackEntry> items, IList<MenuFlyoutItemBase> flyoutItems, bool isBackMode) |
165 | 165 | {
|
166 | 166 | // This may not seem performant, however it's the most viable trade-off to make.
|
167 | 167 | // Instead of constantly keeping track of back/forward stack and performing lookups
|
168 | 168 | // (which may degrade performance), we only add items in bulk when it's needed.
|
169 | 169 | // There's also a high chance the user might not use the feature at all in which case
|
170 | 170 | // the former approach would just waste extra performance gain
|
171 | 171 |
|
172 |
| - destination.Clear(); |
| 172 | + flyoutItems.Clear(); |
173 | 173 | foreach (var item in items.Reverse())
|
174 | 174 | {
|
175 | 175 | if (item.Parameter is not NavigationArguments args || args.NavPathParam is null)
|
176 | 176 | continue;
|
177 | 177 |
|
178 |
| - var imageSource = await NavigationHelpers.GetIconForPathAsync(args.NavPathParam); |
179 | 178 | var fileName = SystemIO.Path.GetFileName(args.NavPathParam);
|
180 | 179 |
|
181 | 180 | // The fileName is empty if the path is (root) drive path
|
182 | 181 | if (string.IsNullOrEmpty(fileName))
|
183 | 182 | fileName = args.NavPathParam;
|
184 | 183 |
|
185 |
| - destination.Add(new MenuFlyoutItem() |
| 184 | + var flyoutItem = new MenuFlyoutItem |
186 | 185 | {
|
187 |
| - Icon = new ImageIcon() { Source = imageSource }, |
| 186 | + Icon = new FontIcon { Glyph = "\uE8B7" }, // Use font icon as placeholder |
188 | 187 | Text = fileName,
|
189 | 188 | Command = historyItemClickedCommand,
|
190 | 189 | CommandParameter = new ToolbarHistoryItemModel(item, isBackMode)
|
191 |
| - }); |
| 190 | + }; |
| 191 | + |
| 192 | + flyoutItems?.Add(flyoutItem); |
| 193 | + |
| 194 | + // Start loading the thumbnail in the background |
| 195 | + _ = LoadFlyoutItemIconAsync(flyoutItem, args.NavPathParam); |
192 | 196 | }
|
193 | 197 | }
|
194 | 198 |
|
| 199 | + private async Task LoadFlyoutItemIconAsync(MenuFlyoutItem flyoutItem, string path) |
| 200 | + { |
| 201 | + var imageSource = await NavigationHelpers.GetIconForPathAsync(path); |
| 202 | + |
| 203 | + if (imageSource is not null) |
| 204 | + flyoutItem.Icon = new ImageIcon { Source = imageSource }; |
| 205 | + } |
| 206 | + |
195 | 207 | private void HistoryItemClicked(ToolbarHistoryItemModel? itemModel)
|
196 | 208 | {
|
197 | 209 | if (itemModel is null)
|
|
0 commit comments