Skip to content

Commit 5831ac2

Browse files
authored
Feature: Follow file extension setting for Recent Files widget (#15113)
1 parent 49f2cf2 commit 5831ac2

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/Files.App/Utils/RecentItem/RecentItem.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Microsoft.UI.Xaml.Media.Imaging;
5-
using Windows.Storage;
6-
using Windows.Storage.FileProperties;
75

86
namespace Files.App.Utils.RecentItem
97
{
@@ -40,11 +38,11 @@ public RecentItem(string linkPath) : base()
4038
/// <summary>
4139
/// Create a RecentItem from a ShellLinkItem (usually from shortcuts in `Windows\Recent`)
4240
/// </summary>
43-
public RecentItem(ShellLinkItem linkItem) : base()
41+
public RecentItem(ShellLinkItem linkItem, bool showFileExtension) : base()
4442
{
4543
LinkPath = linkItem.FilePath;
4644
RecentPath = linkItem.TargetPath;
47-
Name = NameOrPathWithoutExtension(linkItem.FileName);
45+
Name = showFileExtension ? linkItem.FileName : NameOrPathWithoutExtension(linkItem.FileName);
4846
LastModified = linkItem.ModifiedDate;
4947
PIDL = linkItem.PIDL;
5048
}
@@ -53,11 +51,11 @@ public RecentItem(ShellLinkItem linkItem) : base()
5351
/// Create a RecentItem from a ShellFileItem (usually from enumerating Quick Access directly).
5452
/// </summary>
5553
/// <param name="fileItem">The shell file item</param>
56-
public RecentItem(ShellFileItem fileItem) : base()
54+
public RecentItem(ShellFileItem fileItem, bool showFileExtension) : base()
5755
{
5856
LinkPath = ShellStorageFolder.IsShellPath(fileItem.FilePath) ? fileItem.RecyclePath : fileItem.FilePath; // use true path on disk for shell items
5957
RecentPath = LinkPath; // intentionally the same
60-
Name = NameOrPathWithoutExtension(fileItem.FileName);
58+
Name = showFileExtension ? fileItem.FileName : NameOrPathWithoutExtension(fileItem.FileName);
6159
LastModified = fileItem.ModifiedDate;
6260
PIDL = fileItem.PIDL;
6361
}

src/Files.App/Utils/RecentItem/RecentItems.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ public IReadOnlyList<RecentItem> RecentFolders // already sorted
4343
}
4444
}
4545

46-
public RecentItems()
46+
private readonly IUserSettingsService UserSettingsService;
47+
48+
private bool ShowFileExtensions => UserSettingsService.FoldersSettingsService.ShowFileExtensions;
49+
50+
51+
public RecentItems(IUserSettingsService userSettingsService)
4752
{
4853
RecentItemsManager.Default.RecentItemsChanged += OnRecentItemsChangedAsync;
54+
UserSettingsService = userSettingsService;
4955
}
5056

5157
private async void OnRecentItemsChangedAsync(object? sender, EventArgs e)
@@ -105,7 +111,7 @@ public async Task<List<RecentItem>> ListRecentFilesAsync()
105111
{
106112
return (await Win32Helper.GetShellFolderAsync(QuickAccessGuid, "Enumerate", 0, int.MaxValue)).Enumerate
107113
.Where(link => !link.IsFolder)
108-
.Select(link => new RecentItem(link)).ToList();
114+
.Select(link => new RecentItem(link, ShowFileExtensions)).ToList();
109115
}
110116

111117
/// <summary>
@@ -127,7 +133,7 @@ public async Task<List<RecentItem>> ListRecentFoldersAsync()
127133
if (!string.IsNullOrEmpty(link.TargetPath) && link.Target.IsFolder)
128134
{
129135
var shellLinkItem = ShellFolderExtensions.GetShellLinkItem(link);
130-
return new RecentItem(shellLinkItem);
136+
return new RecentItem(shellLinkItem, ShowFileExtensions);
131137
}
132138
}
133139
catch (FileNotFoundException)

0 commit comments

Comments
 (0)