From fc2c2cd838ac6805418c2379604d8593e0b54407 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:11:44 -0500 Subject: [PATCH] Code Quality: Improve icon code for recent items (#14805) --- .../Widgets/RecentFilesWidget.xaml | 24 ++--------------- .../Widgets/RecentFilesWidget.xaml.cs | 1 - src/Files.App/Utils/RecentItem/RecentItem.cs | 26 +++++-------------- 3 files changed, 9 insertions(+), 42 deletions(-) diff --git a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml index b902619014d2..0eba968779db 100644 --- a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml +++ b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml @@ -60,33 +60,13 @@ - - diff --git a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs index a66953369a04..f9d6838be39d 100644 --- a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs +++ b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs @@ -369,7 +369,6 @@ private void RecentsView_ItemClick(object sender, ItemClickEventArgs e) RecentFileInvoked?.Invoke(this, new PathNavigationEventArgs() { ItemPath = recentItem.RecentPath, - IsFile = recentItem.IsFile }); } diff --git a/src/Files.App/Utils/RecentItem/RecentItem.cs b/src/Files.App/Utils/RecentItem/RecentItem.cs index 0c3e0b3be9a2..62c780fe9e09 100644 --- a/src/Files.App/Utils/RecentItem/RecentItem.cs +++ b/src/Files.App/Utils/RecentItem/RecentItem.cs @@ -18,18 +18,13 @@ public BitmapImage FileImg public string LinkPath { get; set; } // path of shortcut item (this is unique) public string RecentPath { get; set; } // path to target item public string Name { get; set; } - public StorageItemTypes Type { get; set; } - public bool FolderImg { get; set; } - public bool EmptyImgVis { get; set; } - public bool FileIconVis { get; set; } - public bool IsFile { get => Type == StorageItemTypes.File; } public DateTime LastModified { get; set; } public byte[] PIDL { get; set; } public string Path { get => RecentPath; } public RecentItem() { - EmptyImgVis = true; // defer icon load to LoadRecentItemIcon() + } /// @@ -50,9 +45,6 @@ public RecentItem(ShellLinkItem linkItem) : base() LinkPath = linkItem.FilePath; RecentPath = linkItem.TargetPath; Name = NameOrPathWithoutExtension(linkItem.FileName); - Type = linkItem.IsFolder ? StorageItemTypes.Folder : ZipStorageFolder.IsZipPath(LinkPath) ? StorageItemTypes.Folder : StorageItemTypes.File; - FolderImg = linkItem.IsFolder; - FileIconVis = !linkItem.IsFolder; LastModified = linkItem.ModifiedDate; PIDL = linkItem.PIDL; } @@ -66,9 +58,6 @@ public RecentItem(ShellFileItem fileItem) : base() LinkPath = ShellStorageFolder.IsShellPath(fileItem.FilePath) ? fileItem.RecyclePath : fileItem.FilePath; // use true path on disk for shell items RecentPath = LinkPath; // intentionally the same Name = NameOrPathWithoutExtension(fileItem.FileName); - Type = fileItem.IsFolder ? StorageItemTypes.Folder : ZipStorageFolder.IsZipPath(LinkPath) ? StorageItemTypes.Folder : StorageItemTypes.File; - FolderImg = fileItem.IsFolder; - FileIconVis = !fileItem.IsFolder; LastModified = fileItem.ModifiedDate; PIDL = fileItem.PIDL; } @@ -77,15 +66,14 @@ public async Task LoadRecentItemIconAsync() { var result = await FileThumbnailHelper.GetIconAsync( RecentPath, - Constants.ShellIconSizes.Large, + Constants.ShellIconSizes.Small, false, false, - IconOptions.None); - if (result.IconData is not null) - { - EmptyImgVis = false; - FileImg = await result.IconData.ToBitmapAsync(); - } + IconOptions.UseCurrentScale); + + var bitmapImage = await result.IconData.ToBitmapAsync(); + if (bitmapImage is not null) + FileImg = bitmapImage; } ///