From 929f9e9b23276e99a3e8ff2331fac845519ac932 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Wed, 22 Mar 2023 09:59:34 +0900 Subject: [PATCH] Fixed icon loading delayed --- .../Widgets/QuickAccessWidget.xaml.cs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Files.App/UserControls/Widgets/QuickAccessWidget.xaml.cs b/src/Files.App/UserControls/Widgets/QuickAccessWidget.xaml.cs index e10db7897c1f..43d9919cbe16 100644 --- a/src/Files.App/UserControls/Widgets/QuickAccessWidget.xaml.cs +++ b/src/Files.App/UserControls/Widgets/QuickAccessWidget.xaml.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.ComponentModel; using System.IO; using System.Linq; @@ -123,6 +124,8 @@ public QuickAccessWidget() OpenPropertiesCommand = new RelayCommand(OpenProperties); PinToFavoritesCommand = new RelayCommand(PinToFavorites); UnpinFromFavoritesCommand = new RelayCommand(UnpinFromFavorites); + + ItemsAdded.CollectionChanged += ItemsAdded_CollectionChanged; } public delegate void QuickAccessCardInvokedEventHandler(object sender, QuickAccessCardInvokedEventArgs e); @@ -270,8 +273,6 @@ await DispatcherQueue.EnqueueAsync(async () => SelectCommand = QuickAccessCardCommand }); } - var cardLoadTasks = ItemsAdded.Select(cardItem => cardItem.LoadCardThumbnailAsync()); - await Task.WhenAll(cardLoadTasks); return; } @@ -287,9 +288,6 @@ await DispatcherQueue.EnqueueAsync(async () => SelectCommand = QuickAccessCardCommand }); } - - var cardLoadTasks = ItemsAdded.Select(cardItem => cardItem.LoadCardThumbnailAsync()); - await Task.WhenAll(cardLoadTasks); } else foreach (var itemToRemove in ItemsAdded.Where(x => e.Paths.Contains(x.Path)).ToList()) @@ -314,9 +312,6 @@ private async void QuickAccessWidget_Loaded(object sender, RoutedEventArgs e) } App.QuickAccessManager.UpdateQuickAccessWidget += ModifyItem; - - var cardLoadTasks = ItemsAdded.Select(cardItem => cardItem.LoadCardThumbnailAsync()); - await Task.WhenAll(cardLoadTasks); } private void QuickAccessWidget_Unloaded(object sender, RoutedEventArgs e) @@ -325,6 +320,15 @@ private void QuickAccessWidget_Unloaded(object sender, RoutedEventArgs e) App.QuickAccessManager.UpdateQuickAccessWidget -= ModifyItem; } + private async void ItemsAdded_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) + { + if (e.Action is NotifyCollectionChangedAction.Add) + { + foreach (FolderCardItem cardItem in e.NewItems!) + await cardItem.LoadCardThumbnailAsync(); + } + } + private void MenuFlyout_Opening(object sender) { var pinToFavoritesItem = (sender as MenuFlyout)?.Items.SingleOrDefault(x => x.Name == "PinToFavorites"); @@ -416,8 +420,8 @@ public Task RefreshWidget() } public void Dispose() - { - + { + ItemsAdded.CollectionChanged -= ItemsAdded_CollectionChanged; } } } \ No newline at end of file