Skip to content

Commit cf434d3

Browse files
authored
Code Quality: Added thumbnail cache settings UI (#18176)
1 parent 736f5f9 commit cf434d3

5 files changed

Lines changed: 131 additions & 1 deletion

File tree

src/Files.App/Data/Contracts/IGeneralSettingsService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
336336
bool ShowFilterHeader { get; set; }
337337

338338
/// <summary>
339+
/// Gets or sets a value indicating whether thumbnail cache should be enabled.
340+
/// </summary>
341+
bool EnableThumbnailCache { get; set; }
342+
343+
/// <summary>
344+
/// Gets or sets the thumbnail cache size limit in MB.
345+
/// </summary>
346+
double ThumbnailCacheSizeLimit { get; set; }
347+
339348
/// Gets or sets a value indicating whether smooth scrolling is enabled.
340349
/// </summary>
341350
bool EnableSmoothScrolling { get; set; }

src/Files.App/Services/Settings/GeneralSettingsService.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,24 @@ public bool ShowFilterHeader
411411
set => Set(value);
412412
}
413413

414-
/// <inheritdoc/>
414+
public bool EnableThumbnailCache
415+
{
416+
get => Get(true);
417+
set => Set(value);
418+
}
419+
415420
public bool EnableSmoothScrolling
416421
{
417422
get => Get(true);
418423
set => Set(value);
419424
}
420425

426+
public double ThumbnailCacheSizeLimit
427+
{
428+
get => Get(512d);
429+
set => Set(value);
430+
}
431+
421432
protected override void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e)
422433
{
423434
base.RaiseOnSettingChangedEvent(sender, e);

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,24 @@
231231
<data name="Advanced" xml:space="preserve">
232232
<value>Advanced</value>
233233
</data>
234+
<data name="CacheThumbnails" xml:space="preserve">
235+
<value>Cache thumbnails</value>
236+
</data>
237+
<data name="CacheSizeLimitDescription" xml:space="preserve">
238+
<value>Maximum disk space to use for thumbnail cache (100-5000 MiB).</value>
239+
</data>
240+
<data name="CacheSizeLimit" xml:space="preserve">
241+
<value>Cache size limit</value>
242+
</data>
243+
<data name="ClearCachedThumbnails" xml:space="preserve">
244+
<value>Clear cached thumbnails to free up space</value>
245+
</data>
246+
<data name="CurrentCacheSize" xml:space="preserve">
247+
<value>Current cache size: </value>
248+
</data>
249+
<data name="ClearCache" xml:space="preserve">
250+
<value>Clear cache</value>
251+
</data>
234252
<data name="SettingsOnStartupContinueWhereYouLeftOff.Content" xml:space="preserve">
235253
<value>Continue where you left off</value>
236254
</data>

src/Files.App/ViewModels/Settings/AdvancedViewModel.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public sealed partial class AdvancedViewModel : ObservableObject
2828
public ICommand ExportSettingsCommand { get; }
2929
public ICommand ImportSettingsCommand { get; }
3030
public AsyncRelayCommand OpenFilesOnWindowsStartupCommand { get; }
31+
public ICommand ClearThumbnailCacheCommand { get; }
3132

3233

3334
public AdvancedViewModel()
@@ -40,8 +41,10 @@ public AdvancedViewModel()
4041
ExportSettingsCommand = new AsyncRelayCommand(ExportSettingsAsync);
4142
ImportSettingsCommand = new AsyncRelayCommand(ImportSettingsAsync);
4243
OpenFilesOnWindowsStartupCommand = new AsyncRelayCommand(OpenFilesOnWindowsStartupAsync);
44+
ClearThumbnailCacheCommand = new AsyncRelayCommand(ClearThumbnailCacheAsync);
4345

4446
_ = DetectOpenFilesAtStartupAsync();
47+
_ = UpdateCacheSizeAsync();
4548
}
4649

4750
private async Task SetAsDefaultExplorerAsync()
@@ -356,6 +359,56 @@ public bool ShowFlattenOptions
356359
}
357360
}
358361

362+
public bool EnableThumbnailCache
363+
{
364+
get => UserSettingsService.GeneralSettingsService.EnableThumbnailCache;
365+
set
366+
{
367+
if (value != UserSettingsService.GeneralSettingsService.EnableThumbnailCache)
368+
{
369+
UserSettingsService.GeneralSettingsService.EnableThumbnailCache = value;
370+
OnPropertyChanged();
371+
}
372+
}
373+
}
374+
375+
public double ThumbnailCacheSizeLimit
376+
{
377+
get => UserSettingsService.GeneralSettingsService.ThumbnailCacheSizeLimit;
378+
set
379+
{
380+
if (value != UserSettingsService.GeneralSettingsService.ThumbnailCacheSizeLimit)
381+
{
382+
UserSettingsService.GeneralSettingsService.ThumbnailCacheSizeLimit = value;
383+
OnPropertyChanged();
384+
}
385+
}
386+
}
387+
388+
private string cacheSizeText = string.Empty;
389+
public string CacheSizeText
390+
{
391+
get => cacheSizeText;
392+
set => SetProperty(ref cacheSizeText, value);
393+
}
394+
395+
private bool isClearCacheButtonEnabled;
396+
public bool IsClearCacheButtonEnabled
397+
{
398+
get => isClearCacheButtonEnabled;
399+
set => SetProperty(ref isClearCacheButtonEnabled, value);
400+
}
401+
402+
private async Task ClearThumbnailCacheAsync()
403+
{
404+
//TODO: Clear thumbnail cache.
405+
}
406+
407+
private async Task UpdateCacheSizeAsync()
408+
{
409+
//TODO: Get thumbnail cache size and update CacheSizeText and IsClearCacheButtonEnabled accordingly.
410+
}
411+
359412
public async Task OpenFilesOnWindowsStartupAsync()
360413
{
361414
var stateMode = await ReadState();

src/Files.App/Views/Settings/AdvancedPage.xaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,45 @@
160160
</ToggleSwitch>
161161
</wctcontrols:SettingsCard>
162162

163+
<!-- Thumbnail Caching -->
164+
<wctcontrols:SettingsExpander
165+
x:Name="CacheSettings"
166+
x:Load="{x:Bind ViewModel.IsAppEnvironmentDev}"
167+
Header="{helpers:ResourceString Name=CacheThumbnails}"
168+
IsExpanded="False">
169+
<wctcontrols:SettingsExpander.HeaderIcon>
170+
<FontIcon Glyph="&#xEDA2;" />
171+
</wctcontrols:SettingsExpander.HeaderIcon>
172+
<ToggleSwitch AutomationProperties.Name="{helpers:ResourceString Name=CacheThumbnails}" IsOn="{x:Bind ViewModel.EnableThumbnailCache, Mode=TwoWay}" />
173+
<wctcontrols:SettingsExpander.Items>
174+
175+
<!-- Cache Size Limit -->
176+
<wctcontrols:SettingsCard Header="{helpers:ResourceString Name=CacheSizeLimit}" IsEnabled="{x:Bind ViewModel.EnableThumbnailCache, Mode=OneWay}">
177+
<wctcontrols:SettingsCard.Description>
178+
<TextBlock Text="{helpers:ResourceString Name=CacheSizeLimitDescription}" TextWrapping="WrapWholeWords" />
179+
</wctcontrols:SettingsCard.Description>
180+
<NumberBox
181+
AutomationProperties.Name="{helpers:ResourceString Name=CacheSizeLimit}"
182+
Maximum="5000"
183+
Minimum="100"
184+
SpinButtonPlacementMode="Inline"
185+
Value="{x:Bind ViewModel.ThumbnailCacheSizeLimit, Mode=TwoWay}" />
186+
</wctcontrols:SettingsCard>
187+
<wctcontrols:SettingsCard Header="{helpers:ResourceString Name=ClearCachedThumbnails}" IsEnabled="{x:Bind ViewModel.EnableThumbnailCache, Mode=OneWay}">
188+
<wctcontrols:SettingsCard.Description>
189+
<TextBlock>
190+
<Run Text="{helpers:ResourceString Name=CurrentCacheSize}" />
191+
<Run FontWeight="SemiBold" Text="{x:Bind ViewModel.CacheSizeText, Mode=OneWay}" />
192+
</TextBlock>
193+
</wctcontrols:SettingsCard.Description>
194+
<Button
195+
Command="{x:Bind ViewModel.ClearThumbnailCacheCommand}"
196+
Content="{helpers:ResourceString Name=ClearCache}"
197+
IsEnabled="{x:Bind ViewModel.IsClearCacheButtonEnabled, Mode=OneWay}" />
198+
</wctcontrols:SettingsCard>
199+
</wctcontrols:SettingsExpander.Items>
200+
</wctcontrols:SettingsExpander>
201+
163202
<!-- Flatten options -->
164203
<wctcontrols:SettingsCard Description="{helpers:ResourceString Name=ShowFlattenOptionsDescription}" Header="{helpers:ResourceString Name=ShowFlattenOptions}">
165204
<wctcontrols:SettingsCard.HeaderIcon>

0 commit comments

Comments
 (0)