Skip to content

Commit 2170976

Browse files
authored
Code Quality: Added default icon sizes to LayoutSettingsService (#14645)
1 parent 3e3aacb commit 2170976

File tree

4 files changed

+98
-30
lines changed

4 files changed

+98
-30
lines changed

src/Files.App/Helpers/Layout/LayoutPreferencesItem.cs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ public class LayoutPreferencesItem
1919
public bool SortDirectoriesAlongsideFiles;
2020
public bool SortFilesFirst;
2121
public bool IsAdaptiveLayoutOverridden;
22-
public int GridViewSize;
22+
23+
// Icon sizes
24+
public int IconSizeDetailsView;
25+
public int IconSizeListView;
26+
public int IconSizeTilesView;
27+
public int IconSizeGridView;
28+
public int IconSizeColumnsView;
2329

2430
public FolderLayoutModes LayoutMode;
2531

@@ -37,7 +43,11 @@ public LayoutPreferencesItem()
3743
var defaultLayout = UserSettingsService.FoldersSettingsService.DefaultLayoutMode;
3844

3945
LayoutMode = defaultLayout is FolderLayoutModes.Adaptive ? FolderLayoutModes.DetailsView : defaultLayout;
40-
GridViewSize = UserSettingsService.LayoutSettingsService.DefaultGridViewSize;
46+
IconSizeDetailsView = UserSettingsService.LayoutSettingsService.DefaultIconSizeDetailsView;
47+
IconSizeListView = UserSettingsService.LayoutSettingsService.DefaultIconSizeListView;
48+
IconSizeTilesView = UserSettingsService.LayoutSettingsService.DefaulIconSizeTilesView;
49+
IconSizeGridView = UserSettingsService.LayoutSettingsService.DefaulIconSizeGridView;
50+
IconSizeColumnsView = UserSettingsService.LayoutSettingsService.DefaultIconSizeColumnsView;
4151
DirectorySortOption = UserSettingsService.FoldersSettingsService.DefaultSortOption;
4252
DirectoryGroupOption = UserSettingsService.FoldersSettingsService.DefaultGroupOption;
4353
DirectorySortDirection = UserSettingsService.FoldersSettingsService.DefaultDirectorySortDirection;
@@ -68,11 +78,11 @@ public LayoutPreferencesItem()
6878
ColumnsViewModel.DateCreatedColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.DateCreatedColumnWidth;
6979
ColumnsViewModel.ItemTypeColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.TypeColumnWidth;
7080
ColumnsViewModel.SizeColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.SizeColumnWidth;
71-
ColumnsViewModel.GitStatusColumn.UserLengthPixels= UserSettingsService.FoldersSettingsService.GitStatusColumnWidth;
72-
ColumnsViewModel.GitLastCommitDateColumn.UserLengthPixels= UserSettingsService.FoldersSettingsService.GitLastCommitDateColumnWidth;
73-
ColumnsViewModel.GitLastCommitMessageColumn.UserLengthPixels= UserSettingsService.FoldersSettingsService.GitLastCommitMessageColumnWidth;
74-
ColumnsViewModel.GitCommitAuthorColumn.UserLengthPixels= UserSettingsService.FoldersSettingsService.GitCommitAuthorColumnWidth;
75-
ColumnsViewModel.GitLastCommitShaColumn.UserLengthPixels= UserSettingsService.FoldersSettingsService.GitLastCommitShaColumnWidth;
81+
ColumnsViewModel.GitStatusColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.GitStatusColumnWidth;
82+
ColumnsViewModel.GitLastCommitDateColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.GitLastCommitDateColumnWidth;
83+
ColumnsViewModel.GitLastCommitMessageColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.GitLastCommitMessageColumnWidth;
84+
ColumnsViewModel.GitCommitAuthorColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.GitCommitAuthorColumnWidth;
85+
ColumnsViewModel.GitLastCommitShaColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.GitLastCommitShaColumnWidth;
7686
ColumnsViewModel.TagColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.TagColumnWidth;
7787
ColumnsViewModel.DateDeletedColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.DateDeletedColumnWidth;
7888
ColumnsViewModel.PathColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.PathColumnWidth;
@@ -94,7 +104,11 @@ public override bool Equals(object? obj)
94104
{
95105
return (
96106
item.LayoutMode == LayoutMode &&
97-
item.GridViewSize == GridViewSize &&
107+
item.IconSizeDetailsView == IconSizeDetailsView &&
108+
item.IconSizeListView == IconSizeListView &&
109+
item.IconSizeTilesView == IconSizeTilesView &&
110+
item.IconSizeGridView == IconSizeGridView &&
111+
item.IconSizeColumnsView == IconSizeColumnsView &&
98112
item.DirectoryGroupOption == DirectoryGroupOption &&
99113
item.DirectorySortOption == DirectorySortOption &&
100114
item.DirectorySortDirection == DirectorySortDirection &&
@@ -113,7 +127,11 @@ public override int GetHashCode()
113127
HashCode hash = new();
114128

115129
hash.Add(LayoutMode);
116-
hash.Add(GridViewSize);
130+
hash.Add(IconSizeDetailsView);
131+
hash.Add(IconSizeListView);
132+
hash.Add(IconSizeTilesView);
133+
hash.Add(IconSizeGridView);
134+
hash.Add(IconSizeColumnsView);
117135
hash.Add(DirectoryGroupOption);
118136
hash.Add(DirectorySortOption);
119137
hash.Add(DirectorySortDirection);

src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public bool IsAdaptiveLayoutEnabled
4242

4343
public int GridViewSize
4444
{
45-
get => LayoutPreferencesItem.GridViewSize;
45+
get => LayoutPreferencesItem.IconSizeGridView;
4646
set
4747
{
4848
// Size down
49-
if (value < LayoutPreferencesItem.GridViewSize)
49+
if (value < LayoutPreferencesItem.IconSizeGridView)
5050
{
5151
// Size down from List to Details
5252
if (LayoutMode == FolderLayoutModes.ListView)
@@ -74,7 +74,7 @@ public int GridViewSize
7474
{
7575
// Set grid size to allow immediate UI update
7676
var newValue = (value >= Constants.Browser.GridViewBrowser.GridViewSizeSmall) ? value : Constants.Browser.GridViewBrowser.GridViewSizeSmall;
77-
SetProperty(ref LayoutPreferencesItem.GridViewSize, newValue, nameof(GridViewSize));
77+
SetProperty(ref LayoutPreferencesItem.IconSizeGridView, newValue, nameof(GridViewSize));
7878

7979
// Only update layout mode if it isn't already in grid view
8080
if (LayoutMode != FolderLayoutModes.GridView)
@@ -92,7 +92,7 @@ public int GridViewSize
9292
}
9393
}
9494
// Size up
95-
else if (value > LayoutPreferencesItem.GridViewSize)
95+
else if (value > LayoutPreferencesItem.IconSizeGridView)
9696
{
9797
// Size up from Details to List
9898
if (LayoutMode == FolderLayoutModes.DetailsView)
@@ -112,7 +112,7 @@ public int GridViewSize
112112
{
113113
// Set grid size to allow immediate UI update
114114
var newValue = (LayoutMode == FolderLayoutModes.TilesView) ? Constants.Browser.GridViewBrowser.GridViewSizeSmall : (value <= Constants.Browser.GridViewBrowser.GridViewSizeLarge) ? value : Constants.Browser.GridViewBrowser.GridViewSizeLarge;
115-
SetProperty(ref LayoutPreferencesItem.GridViewSize, newValue, nameof(GridViewSize));
115+
SetProperty(ref LayoutPreferencesItem.IconSizeGridView, newValue, nameof(GridViewSize));
116116

117117
// Only update layout mode if it isn't already in grid view
118118
if (LayoutMode != FolderLayoutModes.GridView)
@@ -329,13 +329,17 @@ public uint GetIconSize()
329329
=> Constants.DefaultIconSizes.Large,
330330
FolderLayoutModes.TilesView
331331
=> Constants.Browser.GridViewBrowser.TilesView,
332-
_ when GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeSmall
333-
=> Constants.Browser.GridViewBrowser.GridViewSizeSmall,
334-
_ when GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeMedium
335-
=> Constants.Browser.GridViewBrowser.GridViewSizeMedium,
336-
_ when GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeLarge
337-
=> Constants.Browser.GridViewBrowser.GridViewSizeLarge,
338-
_ => Constants.Browser.GridViewBrowser.GridViewSizeLarge,
332+
_ when GridViewSize <= 64
333+
=> 64,
334+
_ when GridViewSize <= 72
335+
=> 72,
336+
_ when GridViewSize <= 96
337+
=> 96,
338+
_ when GridViewSize <= 128
339+
=> 128,
340+
_ when GridViewSize <= 180
341+
=> 180,
342+
_ => 256,
339343
};
340344
}
341345

@@ -431,7 +435,7 @@ public void ToggleLayoutModeTiles(bool manuallySet)
431435

432436
LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.TilesView, GridViewSize));
433437
}
434-
438+
435439
public void ToggleLayoutModeList(bool manuallySet)
436440
{
437441
IsAdaptiveLayoutEnabled &= !manuallySet;
@@ -534,7 +538,11 @@ public static void SetLayoutPreferencesForPath(string path, LayoutPreferencesIte
534538
else
535539
{
536540
UserSettingsService.FoldersSettingsService.DefaultLayoutMode = preferencesItem.LayoutMode;
537-
UserSettingsService.LayoutSettingsService.DefaultGridViewSize = preferencesItem.GridViewSize;
541+
UserSettingsService.LayoutSettingsService.DefaultIconSizeDetailsView = preferencesItem.IconSizeDetailsView;
542+
UserSettingsService.LayoutSettingsService.DefaultIconSizeListView = preferencesItem.IconSizeListView;
543+
UserSettingsService.LayoutSettingsService.DefaulIconSizeTilesView = preferencesItem.IconSizeTilesView;
544+
UserSettingsService.LayoutSettingsService.DefaulIconSizeGridView = preferencesItem.IconSizeGridView;
545+
UserSettingsService.LayoutSettingsService.DefaultIconSizeColumnsView = preferencesItem.IconSizeColumnsView;
538546

539547
// Do not save options which only work in recycle bin or cloud folders or search results as global
540548
if (preferencesItem.DirectorySortOption != SortOption.Path &&
Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.App.Utils.Serialization;
5-
using Files.Core.Services.Settings;
6-
74
namespace Files.App.Services.Settings
85
{
96
internal sealed class LayoutSettingsService : BaseObservableJsonSettings, ILayoutSettingsService
@@ -14,10 +11,34 @@ public LayoutSettingsService(ISettingsSharingContext settingsSharingContext)
1411
RegisterSettingsContext(settingsSharingContext);
1512
}
1613

17-
public int DefaultGridViewSize
14+
public int DefaultIconSizeDetailsView
15+
{
16+
get => (int)Get((long)Constants.DefaultIconSizes.Large);
17+
set => Set((long)value);
18+
}
19+
20+
public int DefaultIconSizeListView
21+
{
22+
get => (int)Get((long)Constants.DefaultIconSizes.Large);
23+
set => Set((long)value);
24+
}
25+
26+
public int DefaulIconSizeTilesView
1827
{
1928
get => (int)Get((long)Constants.Browser.GridViewBrowser.GridViewSizeMedium);
2029
set => Set((long)value);
2130
}
31+
32+
public int DefaulIconSizeGridView
33+
{
34+
get => (int)Get((long)Constants.Browser.GridViewBrowser.GridViewSizeMedium);
35+
set => Set((long)value);
36+
}
37+
38+
public int DefaultIconSizeColumnsView
39+
{
40+
get => (int)Get((long)Constants.DefaultIconSizes.Large);
41+
set => Set((long)value);
42+
}
2243
}
2344
}
Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using System.ComponentModel;
5-
64
namespace Files.Core.Services.Settings
75
{
86
public interface ILayoutSettingsService : IBaseSettingsService, INotifyPropertyChanged
97
{
10-
int DefaultGridViewSize { get; set; }
8+
/// <summary>
9+
/// Default icon size in the Details View
10+
/// </summary>
11+
int DefaultIconSizeDetailsView { get; set; }
12+
13+
/// <summary>
14+
/// Default icon size in the List View
15+
/// </summary>
16+
int DefaultIconSizeListView { get; set; }
17+
18+
/// <summary>
19+
/// Default icon size in the Tiles View
20+
/// </summary>
21+
int DefaulIconSizeTilesView { get; set; }
22+
23+
/// <summary>
24+
/// Default icon size in the Grid View
25+
/// </summary>
26+
int DefaulIconSizeGridView { get; set; }
27+
28+
/// <summary>
29+
/// Default icon size in the Columns View
30+
/// </summary>
31+
int DefaultIconSizeColumnsView { get; set; }
1132
}
1233
}

0 commit comments

Comments
 (0)