Skip to content

Code Quality: Improve icon code for recent items #14805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,13 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<FontIcon
x:Name="RecentFolderImg"
Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
x:Load="{x:Bind FolderImg}"
x:Phase="1"
FontSize="24"
Foreground="#ffe793"
Glyph="&#xE8B7;" />
<FontIcon
x:Name="EmptyImg"
Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
x:Load="{x:Bind EmptyImgVis}"
x:Phase="1"
FontSize="24"
Glyph="&#xE7C3;" />
<Image
x:Name="RecentFileImg"
Grid.Column="0"
Width="24"
Height="24"
Width="16"
Height="16"
HorizontalAlignment="Center"
VerticalAlignment="Center"
x:Load="{x:Bind FileIconVis}"
x:Phase="1"
Source="{x:Bind FileImg, Mode=OneWay}"
Stretch="Uniform" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ private void RecentsView_ItemClick(object sender, ItemClickEventArgs e)
RecentFileInvoked?.Invoke(this, new PathNavigationEventArgs()
{
ItemPath = recentItem.RecentPath,
IsFile = recentItem.IsFile
});
}

Expand Down
26 changes: 7 additions & 19 deletions src/Files.App/Utils/RecentItem/RecentItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()

}

/// <summary>
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}

/// <summary>
Expand Down