Skip to content
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

Feature: Disable folder thumbnails by default #14935

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/Files.App/Data/Models/ItemViewModel.cs
Expand Up @@ -592,7 +592,8 @@ private async void UserSettingsService_OnSettingChangedEvent(object? sender, Set
switch (e.SettingName)
{
case nameof(UserSettingsService.FoldersSettingsService.ShowFileExtensions):
case nameof(UserSettingsService.FoldersSettingsService.ShowThumbnails):
case nameof(UserSettingsService.FoldersSettingsService.ShowFileThumbnails):
case nameof(UserSettingsService.FoldersSettingsService.FolderIconOption):
case nameof(UserSettingsService.FoldersSettingsService.ShowHiddenItems):
case nameof(UserSettingsService.FoldersSettingsService.ShowProtectedSystemFiles):
case nameof(UserSettingsService.FoldersSettingsService.AreAlternateStreamsVisible):
Expand Down Expand Up @@ -916,16 +917,28 @@ private async Task<BitmapImage> GetShieldIcon()

private async Task LoadThumbnailAsync(ListedItem item)
{
// Cancel if thumbnails aren't enabled
var thumbnailSize = folderSettings.GetRoundedIconSize();
var returnIconOnly = UserSettingsService.FoldersSettingsService.ShowThumbnails == false || thumbnailSize < 48;
var flags = IconOptions.None;

// Use basic icons for smaller sizes or if the settings call for it
if (thumbnailSize < 48)
flags = IconOptions.ReturnIconOnly;
else if (!item.IsFolder && UserSettingsService.FoldersSettingsService.ShowFileThumbnails == false)
flags = IconOptions.ReturnIconOnly;
else if (item.IsFolder)
{
if (UserSettingsService.FoldersSettingsService.FolderIconOption == IconOptions.ReturnOnlyIfCached)
flags = IconOptions.ReturnOnlyIfCached;
else if (UserSettingsService.FoldersSettingsService.FolderIconOption == IconOptions.ReturnIconOnly)
flags = IconOptions.ReturnIconOnly;
}

// Get thumbnail
var result = await FileThumbnailHelper.GetIconAsync(
item.ItemPath,
thumbnailSize,
item.IsFolder,
returnIconOnly ? IconOptions.ReturnIconOnly : IconOptions.None);
flags);

if (result is not null)
{
Expand Down
11 changes: 9 additions & 2 deletions src/Files.App/Services/Settings/FoldersSettingsService.cs
Expand Up @@ -73,12 +73,18 @@ public bool ShowFileExtensions
set => Set(value);
}

public bool ShowThumbnails
public bool ShowFileThumbnails
{
get => Get(true);
set => Set(value);
}

public IconOptions FolderIconOption
{
get => (IconOptions)Get((long)IconOptions.ReturnOnlyIfCached);
set => Set((long)value);
}

public DeleteConfirmationPolicies DeleteConfirmationPolicy
{
get => (DeleteConfirmationPolicies)Get((long)DeleteConfirmationPolicies.Always);
Expand Down Expand Up @@ -123,7 +129,8 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged
case nameof(ScrollToPreviousFolderWhenNavigatingUp):
case nameof(CalculateFolderSizes):
case nameof(ShowFileExtensions):
case nameof(ShowThumbnails):
case nameof(ShowFileThumbnails):
case nameof(FolderIconOption):
case nameof(DeleteConfirmationPolicy):
case nameof(SelectFilesOnHover):
case nameof(DoubleClickToGoUp):
Expand Down
20 changes: 19 additions & 1 deletion src/Files.App/Strings/en-US/Resources.resw
Expand Up @@ -1953,9 +1953,27 @@
<data name="DateFormatSample" xml:space="preserve">
<value>ex: {0}, {1}</value>
</data>
<data name="SettingsFilesAndFoldersShowThumbnails" xml:space="preserve">
<data name="FileThumbnails" xml:space="preserve">
<value>File thumbnails</value>
</data>
<data name="ShowThumbnails" xml:space="preserve">
<value>Show thumbnails</value>
</data>
<data name="AlwaysShowIcons" xml:space="preserve">
<value>Always show icons</value>
</data>
<data name="OnlyShowCachedThumbnails" xml:space="preserve">
<value>Only show cached thumbnails</value>
</data>
<data name="FolderThumbnails" xml:space="preserve">
<value>Folder thumbnails</value>
</data>
<data name="Thumbnails" xml:space="preserve">
<value>Thumbnails</value>
</data>
<data name="ShowThumbnailsWarning" xml:space="preserve">
<value>Enabling folder thumbnails is resource intensive and may take more time to generate.</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Retry</value>
</data>
Expand Down
9 changes: 6 additions & 3 deletions src/Files.App/Utils/Shell/Win32API.cs
Expand Up @@ -287,7 +287,8 @@ public static string ExtractStringFromDLL(string file, int number)
string path,
int size,
bool isFolder,
bool returnIconOnly)
bool returnIconOnly,
bool returnOnlyIfCached)
{
byte[]? iconData = null;

Expand All @@ -303,6 +304,8 @@ public static string ExtractStringFromDLL(string file, int number)

if (returnIconOnly)
flags |= Shell32.SIIGBF.SIIGBF_ICONONLY;
else if (returnOnlyIfCached)
flags |= Shell32.SIIGBF.SIIGBF_INCACHEONLY;

var hres = shellFactory.GetImage(new SIZE(size, size), flags, out var hbitmap);
if (hres == HRESULT.S_OK)
Expand All @@ -316,7 +319,7 @@ public static string ExtractStringFromDLL(string file, int number)
}

if (iconData is not null)
return iconData;
return iconData;
else
{
var shfi = new Shell32.SHFILEINFO();
Expand All @@ -325,7 +328,7 @@ public static string ExtractStringFromDLL(string file, int number)
// Cannot access file, use file attributes
var useFileAttibutes = iconData is null;

var ret = Shell32.SHGetFileInfo(path, isFolder ? FileAttributes.Directory : 0, ref shfi, Shell32.SHFILEINFO.Size, flags);
var ret = Shell32.SHGetFileInfo(path, isFolder ? FileAttributes.Directory : 0, ref shfi, Shell32.SHFILEINFO.Size, flags);
if (ret == IntPtr.Zero)
return iconData;

Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/Utils/Storage/Helpers/FileThumbnailHelper.cs
Expand Up @@ -14,8 +14,9 @@ public static class FileThumbnailHelper
{
var size = iconOptions.HasFlag(IconOptions.UseCurrentScale) ? requestedSize * App.AppModel.AppWindowDPI : requestedSize;
var returnIconOnly = iconOptions.HasFlag(IconOptions.ReturnIconOnly);
var returnOnlyIfCached = iconOptions.HasFlag(IconOptions.ReturnOnlyIfCached);

return await Win32API.StartSTATask(() => Win32API.GetIcon(path, (int)size, isFolder, returnIconOnly));
return await Win32API.StartSTATask(() => Win32API.GetIcon(path, (int)size, isFolder, returnIconOnly, returnOnlyIfCached));
}

/// <summary>
Expand Down
37 changes: 33 additions & 4 deletions src/Files.App/ViewModels/Settings/FoldersViewModel.cs
Expand Up @@ -12,6 +12,7 @@ public class FoldersViewModel : ObservableObject
public FoldersViewModel()
{
SelectedDeleteConfirmationPolicyIndex = (int)DeleteConfirmationPolicy;
SelectedFolderIconOptionIndex = (int)FolderIconOption;
}

// Properties
Expand Down Expand Up @@ -172,14 +173,42 @@ public bool ShowFileExtensions
}
}

public bool ShowThumbnails
public bool ShowFileThumbnails
{
get => UserSettingsService.FoldersSettingsService.ShowThumbnails;
get => UserSettingsService.FoldersSettingsService.ShowFileThumbnails;
set
{
if (value != UserSettingsService.FoldersSettingsService.ShowThumbnails)
if (value != UserSettingsService.FoldersSettingsService.ShowFileThumbnails)
{
UserSettingsService.FoldersSettingsService.ShowThumbnails = value;
UserSettingsService.FoldersSettingsService.ShowFileThumbnails = value;

OnPropertyChanged();
}
}
}

private int selectedFolderIconOptionIndex;
public int SelectedFolderIconOptionIndex
{
get => selectedFolderIconOptionIndex;
set
{
if (SetProperty(ref selectedFolderIconOptionIndex, value))
{
OnPropertyChanged(nameof(SelectedFolderIconOptionIndex));
FolderIconOption = (IconOptions)value;
}
}
}

public IconOptions FolderIconOption
{
get => UserSettingsService.FoldersSettingsService.FolderIconOption;
set
{
if (value != UserSettingsService.FoldersSettingsService.FolderIconOption)
{
UserSettingsService.FoldersSettingsService.FolderIconOption = value;

OnPropertyChanged();
}
Expand Down
35 changes: 30 additions & 5 deletions src/Files.App/Views/Settings/FoldersPage.xaml
Expand Up @@ -97,14 +97,39 @@
</local:SettingsBlockControl>

<!-- Show Thumbnails -->
<local:SettingsBlockControl Title="{helpers:ResourceString Name=SettingsFilesAndFoldersShowThumbnails}" HorizontalAlignment="Stretch">
<local:SettingsBlockControl Title="{helpers:ResourceString Name=Thumbnails}" HorizontalAlignment="Stretch">
<local:SettingsBlockControl.Icon>
<FontIcon Glyph="&#xE91B;" />
</local:SettingsBlockControl.Icon>
<ToggleSwitch
AutomationProperties.Name="{helpers:ResourceString Name=SettingsFilesAndFoldersShowThumbnails}"
IsOn="{x:Bind ViewModel.ShowThumbnails, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
<local:SettingsBlockControl.ExpandableContent>
<StackPanel>
<!-- File Thumbnails -->
<local:SettingsBlockControl Title="{helpers:ResourceString Name=FileThumbnails}" HorizontalAlignment="Stretch">
<ToggleSwitch
AutomationProperties.Name="{helpers:ResourceString Name=FileThumbnails}"
IsOn="{x:Bind ViewModel.ShowFileThumbnails, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</local:SettingsBlockControl>

<!-- Folder Thumbnails -->
<local:SettingsBlockControl Title="{helpers:ResourceString Name=FolderThumbnails}" HorizontalAlignment="Stretch">
<ComboBox AutomationProperties.Name="{helpers:ResourceString Name=FolderThumbnails}" SelectedIndex="{x:Bind ViewModel.SelectedFolderIconOptionIndex, Mode=TwoWay}">
<ComboBoxItem Content="{helpers:ResourceString Name=ShowThumbnails}" />
<ComboBoxItem Content="{helpers:ResourceString Name=AlwaysShowIcons}" />
<ComboBoxItem Content="{helpers:ResourceString Name=OnlyShowCachedThumbnails}" />
</ComboBox>
</local:SettingsBlockControl>

<!-- Performance Warning -->
<InfoBar
CornerRadius="0,0,2,2"
IsClosable="False"
IsIconVisible="True"
IsOpen="True"
Message="{helpers:ResourceString Name=ShowThumbnailsWarning}"
Severity="Warning" />
</StackPanel>
</local:SettingsBlockControl.ExpandableContent>
</local:SettingsBlockControl>

<!-- Show Checkboxes When Selecting Items -->
Expand Down
10 changes: 5 additions & 5 deletions src/Files.Core/Data/Enums/IconOptions.cs
Expand Up @@ -14,11 +14,6 @@ public enum IconOptions
/// </summary>
None,

/// <summary>
/// Increase requested size based on the displays DPI setting.
/// </summary>
UseCurrentScale,

/// <summary>
/// Retrieve only the file icon, even a thumbnail is available. This has the best performance.
/// </summary>
Expand All @@ -28,5 +23,10 @@ public enum IconOptions
/// Retrieve a thumbnail only if it is cached or embedded in the file.
/// </summary>
ReturnOnlyIfCached,

/// <summary>
/// Increase requested size based on the displays DPI setting.
/// </summary>
UseCurrentScale,
}
}
11 changes: 9 additions & 2 deletions src/Files.Core/Services/Settings/IFoldersSettingsService.cs
@@ -1,6 +1,8 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.Core.Data.Enums;

namespace Files.Core.Services.Settings
{
public interface IFoldersSettingsService : IBaseSettingsService, INotifyPropertyChanged
Expand Down Expand Up @@ -56,10 +58,15 @@ public interface IFoldersSettingsService : IBaseSettingsService, INotifyProperty
bool ShowFileExtensions { get; set; }

/// <summary>
/// Gets or sets a value indicating if media thumbnails should be displayed.
/// Gets or sets a value indicating if file thumbnails should be displayed.
/// </summary>
bool ShowThumbnails { get; set; }
bool ShowFileThumbnails { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not folder thumbnails should be displayed.
/// </summary>
IconOptions FolderIconOption { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to show the delete confirmation dialog when deleting items.
/// </summary>
Expand Down