Skip to content

Commit a422c87

Browse files
authored
Code Quality: Introduce details layout columns generator phase 1 (#14127)
1 parent 35e4bd8 commit a422c87

21 files changed

+1074
-1051
lines changed

src/Files.App/Data/Contexts/DisplayPage/DisplayPageContext.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public SortOption SortOption
5555
get => _SortOption;
5656
set
5757
{
58-
if (FolderSettings is FolderSettingsViewModel viewModel)
58+
if (FolderSettings is LayoutPreferencesManager viewModel)
5959
viewModel.DirectorySortOption = value;
6060
}
6161
}
@@ -66,7 +66,7 @@ public SortDirection SortDirection
6666
get => _SortDirection;
6767
set
6868
{
69-
if (FolderSettings is FolderSettingsViewModel viewModel)
69+
if (FolderSettings is LayoutPreferencesManager viewModel)
7070
viewModel.DirectorySortDirection = value;
7171
}
7272
}
@@ -77,7 +77,7 @@ public GroupOption GroupOption
7777
get => _GroupOption;
7878
set
7979
{
80-
if (FolderSettings is FolderSettingsViewModel viewModel)
80+
if (FolderSettings is LayoutPreferencesManager viewModel)
8181
viewModel.DirectoryGroupOption = value;
8282
}
8383
}
@@ -88,7 +88,7 @@ public SortDirection GroupDirection
8888
get => _GroupDirection;
8989
set
9090
{
91-
if (FolderSettings is FolderSettingsViewModel viewModel)
91+
if (FolderSettings is LayoutPreferencesManager viewModel)
9292
viewModel.DirectoryGroupDirection = value;
9393
}
9494
}
@@ -99,7 +99,7 @@ public GroupByDateUnit GroupByDateUnit
9999
get => _GroupByDateUnit;
100100
set
101101
{
102-
if (FolderSettings is FolderSettingsViewModel viewModel)
102+
if (FolderSettings is LayoutPreferencesManager viewModel)
103103
viewModel.DirectoryGroupByDateUnit = value;
104104
}
105105
}
@@ -110,12 +110,12 @@ public bool SortDirectoriesAlongsideFiles
110110
get => _SortDirectoriesAlongsideFiles;
111111
set
112112
{
113-
if (FolderSettings is FolderSettingsViewModel viewModel)
113+
if (FolderSettings is LayoutPreferencesManager viewModel)
114114
viewModel.SortDirectoriesAlongsideFiles = value;
115115
}
116116
}
117117

118-
private FolderSettingsViewModel? FolderSettings => context.PaneOrColumn?.InstanceViewModel?.FolderSettings;
118+
private LayoutPreferencesManager? FolderSettings => context.PaneOrColumn?.InstanceViewModel?.FolderSettings;
119119

120120
public DisplayPageContext()
121121
{
@@ -126,12 +126,12 @@ public DisplayPageContext()
126126

127127
public void DecreaseLayoutSize()
128128
{
129-
if (FolderSettings is FolderSettingsViewModel viewModel)
129+
if (FolderSettings is LayoutPreferencesManager viewModel)
130130
viewModel.GridViewSize -= GridViewIncrement;
131131
}
132132
public void IncreaseLayoutSize()
133133
{
134-
if (FolderSettings is FolderSettingsViewModel viewModel)
134+
if (FolderSettings is LayoutPreferencesManager viewModel)
135135
viewModel.GridViewSize += GridViewIncrement;
136136
}
137137

@@ -158,27 +158,27 @@ private void FolderSettings_PropertyChanged(object? sender, PropertyChangedEvent
158158

159159
switch (e.PropertyName)
160160
{
161-
case nameof(FolderSettingsViewModel.LayoutMode):
162-
case nameof(FolderSettingsViewModel.GridViewSize):
163-
case nameof(FolderSettingsViewModel.IsAdaptiveLayoutEnabled):
161+
case nameof(LayoutPreferencesManager.LayoutMode):
162+
case nameof(LayoutPreferencesManager.GridViewSize):
163+
case nameof(LayoutPreferencesManager.IsAdaptiveLayoutEnabled):
164164
SetProperty(ref _LayoutType, GetLayoutType(), nameof(LayoutType));
165165
break;
166-
case nameof(FolderSettingsViewModel.DirectorySortOption):
166+
case nameof(LayoutPreferencesManager.DirectorySortOption):
167167
SetProperty(ref _SortOption, viewModel.DirectorySortOption, nameof(SortOption));
168168
break;
169-
case nameof(FolderSettingsViewModel.DirectorySortDirection):
169+
case nameof(LayoutPreferencesManager.DirectorySortDirection):
170170
SetProperty(ref _SortDirection, viewModel.DirectorySortDirection, nameof(SortDirection));
171171
break;
172-
case nameof(FolderSettingsViewModel.DirectoryGroupOption):
172+
case nameof(LayoutPreferencesManager.DirectoryGroupOption):
173173
SetProperty(ref _GroupOption, viewModel.DirectoryGroupOption, nameof(GroupOption));
174174
break;
175-
case nameof(FolderSettingsViewModel.DirectoryGroupDirection):
175+
case nameof(LayoutPreferencesManager.DirectoryGroupDirection):
176176
SetProperty(ref _GroupDirection, viewModel.DirectoryGroupDirection, nameof(GroupDirection));
177177
break;
178-
case nameof(FolderSettingsViewModel.DirectoryGroupByDateUnit):
178+
case nameof(LayoutPreferencesManager.DirectoryGroupByDateUnit):
179179
SetProperty(ref _GroupByDateUnit, viewModel.DirectoryGroupByDateUnit, nameof(GroupByDateUnit));
180180
break;
181-
case nameof(FolderSettingsViewModel.SortDirectoriesAlongsideFiles):
181+
case nameof(LayoutPreferencesManager.SortDirectoriesAlongsideFiles):
182182
SetProperty(ref _SortDirectoriesAlongsideFiles, viewModel.SortDirectoriesAlongsideFiles, nameof(SortDirectoriesAlongsideFiles));
183183
break;
184184
}

src/Files.App/Data/EventArguments/LayoutPreferenceEventArgs.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ public class LayoutPreferenceEventArgs
77
{
88
public readonly bool IsAdaptiveLayoutUpdateRequired;
99

10-
public readonly LayoutPreferences LayoutPreference;
10+
public readonly LayoutPreferencesItem LayoutPreference;
1111

12-
internal LayoutPreferenceEventArgs(LayoutPreferences layoutPref)
12+
internal LayoutPreferenceEventArgs(LayoutPreferencesItem layoutPref)
1313
=> LayoutPreference = layoutPref;
1414

15-
internal LayoutPreferenceEventArgs(LayoutPreferences layoutPref, bool isAdaptiveLayoutUpdateRequired)
15+
internal LayoutPreferenceEventArgs(LayoutPreferencesItem layoutPref, bool isAdaptiveLayoutUpdateRequired)
1616
=> (LayoutPreference, IsAdaptiveLayoutUpdateRequired) = (layoutPref, isAdaptiveLayoutUpdateRequired);
1717
}
1818
}

src/Files.App/Data/Models/ColumnViewModel.cs renamed to src/Files.App/Data/Items/DetailsLayoutColumnItem.cs

Lines changed: 48 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,42 @@
33

44
using Microsoft.UI.Xaml;
55

6-
namespace Files.App.Data.Models
6+
namespace Files.App.Data.Items
77
{
8-
public class ColumnViewModel : ObservableObject
8+
/// <summary>
9+
/// Represents item for a column shown in <see cref="DetailsLayoutPage"/>.
10+
/// </summary>
11+
public class DetailsLayoutColumnItem : ObservableObject
912
{
10-
private bool isHidden;
13+
private const int GRID_SPLITTER_WIDTH = 12;
1114

12-
[LiteDB.BsonIgnore]
13-
public bool IsHidden
14-
{
15-
get => isHidden;
16-
set => SetProperty(ref isHidden, value);
17-
}
18-
19-
[LiteDB.BsonIgnore]
20-
public double MaxLength
15+
public double UserLengthPixels
2116
{
22-
get => UserCollapsed || IsHidden ? 0 : NormalMaxLength;
17+
get => UserLength.Value;
18+
set => UserLength = new GridLength(value, GridUnitType.Pixel);
2319
}
2420

25-
private double normalMaxLength = 800;
26-
21+
private double _NormalMaxLength = 800;
2722
public double NormalMaxLength
2823
{
29-
get => normalMaxLength;
30-
set => SetProperty(ref normalMaxLength, value);
24+
get => _NormalMaxLength;
25+
set => SetProperty(ref _NormalMaxLength, value);
3126
}
3227

33-
private double normalMinLength = 50;
34-
35-
[LiteDB.BsonIgnore]
36-
public double NormalMinLength
28+
private bool _UserCollapsed;
29+
public bool UserCollapsed
3730
{
38-
get => normalMinLength;
31+
get => _UserCollapsed;
3932
set
4033
{
41-
if (SetProperty(ref normalMinLength, value))
42-
OnPropertyChanged(nameof(MinLength));
34+
if (SetProperty(ref _UserCollapsed, value))
35+
UpdateVisibility();
4336
}
4437
}
4538

39+
[LiteDB.BsonIgnore]
40+
public bool IsResizable { get; set; } = true;
41+
4642
[LiteDB.BsonIgnore]
4743
public double MinLength
4844
=> UserCollapsed || IsHidden ? 0 : NormalMinLength;
@@ -51,59 +47,55 @@ public double MinLength
5147
public Visibility Visibility
5248
=> UserCollapsed || IsHidden ? Visibility.Collapsed : Visibility.Visible;
5349

54-
private bool userCollapsed;
55-
56-
public bool UserCollapsed
57-
{
58-
get => userCollapsed;
59-
set
60-
{
61-
if (SetProperty(ref userCollapsed, value))
62-
UpdateVisibility();
63-
}
64-
}
65-
6650
[LiteDB.BsonIgnore]
6751
public GridLength Length
68-
{
69-
get => UserCollapsed || IsHidden ? new GridLength(0) : UserLength;
70-
}
52+
=> UserCollapsed || IsHidden ? new GridLength(0) : UserLength;
7153

72-
private const int gridSplitterWidth = 12;
54+
[LiteDB.BsonIgnore]
55+
public GridLength LengthIncludingGridSplitter =>
56+
UserCollapsed || IsHidden
57+
? new(0)
58+
: new(UserLength.Value + (IsResizable ? GRID_SPLITTER_WIDTH : 0));
59+
60+
[LiteDB.BsonIgnore]
61+
public double MaxLength
62+
=> UserCollapsed || IsHidden ? 0 : NormalMaxLength;
7363

64+
private bool _IsHidden;
7465
[LiteDB.BsonIgnore]
75-
public GridLength LengthIncludingGridSplitter
66+
public bool IsHidden
7667
{
77-
get => UserCollapsed || IsHidden
78-
? new(0)
79-
: new(UserLength.Value + (IsResizeable ? gridSplitterWidth : 0));
68+
get => _IsHidden;
69+
set => SetProperty(ref _IsHidden, value);
8070
}
8171

72+
private double _NormalMinLength = 50;
8273
[LiteDB.BsonIgnore]
83-
public bool IsResizeable { get; set; } = true;
84-
85-
private GridLength userLength = new(200, GridUnitType.Pixel);
74+
public double NormalMinLength
75+
{
76+
get => _NormalMinLength;
77+
set
78+
{
79+
if (SetProperty(ref _NormalMinLength, value))
80+
OnPropertyChanged(nameof(MinLength));
81+
}
82+
}
8683

84+
private GridLength _UserLength = new(200, GridUnitType.Pixel);
8785
[LiteDB.BsonIgnore]
8886
public GridLength UserLength
8987
{
90-
get => userLength;
88+
get => _UserLength;
9189
set
9290
{
93-
if (SetProperty(ref userLength, value))
91+
if (SetProperty(ref _UserLength, value))
9492
{
9593
OnPropertyChanged(nameof(Length));
9694
OnPropertyChanged(nameof(LengthIncludingGridSplitter));
9795
}
9896
}
9997
}
10098

101-
public double UserLengthPixels
102-
{
103-
get => UserLength.Value;
104-
set => UserLength = new GridLength(value, GridUnitType.Pixel);
105-
}
106-
10799
public void Hide()
108100
{
109101
IsHidden = true;
@@ -125,21 +117,6 @@ private void UpdateVisibility()
125117
OnPropertyChanged(nameof(MinLength));
126118
}
127119

128-
public void TryMultiplySize(double factor)
129-
{
130-
var newSize = Length.Value * factor;
131-
if (newSize == 0)
132-
return;
133-
134-
double setLength = newSize;
135-
if (newSize < MinLength)
136-
setLength = MinLength;
137-
else if (newSize >= MaxLength)
138-
setLength = MaxLength;
139-
140-
UserLength = new GridLength(setLength);
141-
}
142-
143120
public override bool Equals(object? obj)
144121
{
145122
if (obj is null)
@@ -148,7 +125,7 @@ public override bool Equals(object? obj)
148125
if (obj == this)
149126
return true;
150127

151-
if (obj is ColumnViewModel model)
128+
if (obj is DetailsLayoutColumnItem model)
152129
{
153130
return
154131
model.UserCollapsed == UserCollapsed &&

0 commit comments

Comments
 (0)