|
1 | 1 | using CommunityToolkit.Mvvm.DependencyInjection;
|
| 2 | +using Files.App.ViewModels; |
2 | 3 | using Files.Backend.Services.Settings;
|
3 | 4 | using Files.Shared.Enums;
|
4 |
| -using Files.App.ViewModels; |
5 | 5 |
|
6 | 6 | namespace Files.App.Helpers.LayoutPreferences
|
7 | 7 | {
|
8 |
| - public class LayoutPreferences |
9 |
| - { |
10 |
| - private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>(); |
| 8 | + public class LayoutPreferences |
| 9 | + { |
| 10 | + private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>(); |
| 11 | + |
| 12 | + public SortOption DirectorySortOption; |
| 13 | + public SortDirection DirectorySortDirection; |
| 14 | + public bool SortDirectoriesAlongsideFiles; |
| 15 | + public GroupOption DirectoryGroupOption; |
| 16 | + public FolderLayoutModes LayoutMode; |
| 17 | + public int GridViewSize; |
| 18 | + public bool IsAdaptiveLayoutOverridden; |
| 19 | + |
| 20 | + public ColumnsViewModel ColumnsViewModel; |
| 21 | + |
| 22 | + [LiteDB.BsonIgnore] |
| 23 | + public static LayoutPreferences DefaultLayoutPreferences => new LayoutPreferences(); |
11 | 24 |
|
12 |
| - public SortOption DirectorySortOption; |
13 |
| - public SortDirection DirectorySortDirection; |
14 |
| - public bool SortDirectoriesAlongsideFiles; |
15 |
| - public GroupOption DirectoryGroupOption; |
16 |
| - public FolderLayoutModes LayoutMode; |
17 |
| - public int GridViewSize; |
18 |
| - public bool IsAdaptiveLayoutOverridden; |
| 25 | + public LayoutPreferences() |
| 26 | + { |
| 27 | + this.LayoutMode = UserSettingsService.PreferencesSettingsService.DefaultLayoutMode; |
| 28 | + this.GridViewSize = UserSettingsService.LayoutSettingsService.DefaultGridViewSize; |
| 29 | + this.DirectorySortOption = UserSettingsService.LayoutSettingsService.DefaultDirectorySortOption; |
| 30 | + this.DirectoryGroupOption = UserSettingsService.LayoutSettingsService.DefaultDirectoryGroupOption; |
| 31 | + this.DirectorySortDirection = UserSettingsService.LayoutSettingsService.DefaultDirectorySortDirection; |
| 32 | + this.SortDirectoriesAlongsideFiles = UserSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles; |
| 33 | + this.IsAdaptiveLayoutOverridden = false; |
19 | 34 |
|
20 |
| - public ColumnsViewModel ColumnsViewModel; |
| 35 | + this.ColumnsViewModel = new ColumnsViewModel(); |
| 36 | + this.ColumnsViewModel.DateCreatedColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowDateCreatedColumn; |
| 37 | + this.ColumnsViewModel.DateModifiedColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowDateColumn; |
| 38 | + this.ColumnsViewModel.ItemTypeColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowTypeColumn; |
| 39 | + this.ColumnsViewModel.SizeColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowSizeColumn; |
| 40 | + this.ColumnsViewModel.TagColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowFileTagColumn; |
21 | 41 |
|
22 |
| - [LiteDB.BsonIgnore] |
23 |
| - public static LayoutPreferences DefaultLayoutPreferences => new LayoutPreferences(); |
| 42 | + this.ColumnsViewModel.NameColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.NameColumnWidth; |
| 43 | + this.ColumnsViewModel.DateModifiedColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.DateModifiedColumnWidth; |
| 44 | + this.ColumnsViewModel.DateCreatedColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.DateCreatedColumnWidth; |
| 45 | + this.ColumnsViewModel.ItemTypeColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.TypeColumnWidth; |
| 46 | + this.ColumnsViewModel.SizeColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.SizeColumnWidth; |
| 47 | + this.ColumnsViewModel.TagColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.TagColumnWidth; |
| 48 | + } |
24 | 49 |
|
25 |
| - public LayoutPreferences() |
26 |
| - { |
27 |
| - this.LayoutMode = UserSettingsService.PreferencesSettingsService.DefaultLayoutMode; |
28 |
| - this.GridViewSize = UserSettingsService.LayoutSettingsService.DefaultGridViewSize; |
29 |
| - this.DirectorySortOption = UserSettingsService.LayoutSettingsService.DefaultDirectorySortOption; |
30 |
| - this.DirectoryGroupOption = UserSettingsService.LayoutSettingsService.DefaultDirectoryGroupOption; |
31 |
| - this.DirectorySortDirection = UserSettingsService.LayoutSettingsService.DefaultDirectorySortDirection; |
32 |
| - this.SortDirectoriesAlongsideFiles = UserSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles; |
33 |
| - this.IsAdaptiveLayoutOverridden = false; |
| 50 | + public override bool Equals(object? obj) |
| 51 | + { |
| 52 | + if (obj == null) |
| 53 | + return false; |
34 | 54 |
|
35 |
| - this.ColumnsViewModel = new ColumnsViewModel(); |
36 |
| - this.ColumnsViewModel.DateCreatedColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowDateCreatedColumn; |
37 |
| - this.ColumnsViewModel.DateModifiedColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowDateColumn; |
38 |
| - this.ColumnsViewModel.ItemTypeColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowTypeColumn; |
39 |
| - this.ColumnsViewModel.SizeColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowSizeColumn; |
40 |
| - this.ColumnsViewModel.TagColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowFileTagColumn; |
41 |
| - } |
| 55 | + if (obj == this) |
| 56 | + return true; |
42 | 57 |
|
43 |
| - public override bool Equals(object obj) |
44 |
| - { |
45 |
| - if (obj == null) |
46 |
| - { |
47 |
| - return false; |
48 |
| - } |
49 |
| - if (obj == this) |
50 |
| - { |
51 |
| - return true; |
52 |
| - } |
53 |
| - if (obj is LayoutPreferences prefs) |
54 |
| - { |
55 |
| - return ( |
56 |
| - prefs.LayoutMode == this.LayoutMode && |
57 |
| - prefs.GridViewSize == this.GridViewSize && |
58 |
| - prefs.DirectoryGroupOption == this.DirectoryGroupOption && |
59 |
| - prefs.DirectorySortOption == this.DirectorySortOption && |
60 |
| - prefs.DirectorySortDirection == this.DirectorySortDirection && |
61 |
| - prefs.SortDirectoriesAlongsideFiles == this.SortDirectoriesAlongsideFiles && |
62 |
| - prefs.IsAdaptiveLayoutOverridden == this.IsAdaptiveLayoutOverridden && |
63 |
| - prefs.ColumnsViewModel.Equals(this.ColumnsViewModel)); |
64 |
| - } |
65 |
| - return base.Equals(obj); |
66 |
| - } |
| 58 | + if (obj is LayoutPreferences prefs) |
| 59 | + { |
| 60 | + return ( |
| 61 | + prefs.LayoutMode == this.LayoutMode && |
| 62 | + prefs.GridViewSize == this.GridViewSize && |
| 63 | + prefs.DirectoryGroupOption == this.DirectoryGroupOption && |
| 64 | + prefs.DirectorySortOption == this.DirectorySortOption && |
| 65 | + prefs.DirectorySortDirection == this.DirectorySortDirection && |
| 66 | + prefs.SortDirectoriesAlongsideFiles == this.SortDirectoriesAlongsideFiles && |
| 67 | + prefs.IsAdaptiveLayoutOverridden == this.IsAdaptiveLayoutOverridden && |
| 68 | + prefs.ColumnsViewModel.Equals(this.ColumnsViewModel)); |
| 69 | + } |
| 70 | + return base.Equals(obj); |
| 71 | + } |
67 | 72 |
|
68 |
| - public override int GetHashCode() |
69 |
| - { |
70 |
| - var hashCode = LayoutMode.GetHashCode(); |
71 |
| - hashCode = (hashCode * 397) ^ GridViewSize.GetHashCode(); |
72 |
| - hashCode = (hashCode * 397) ^ DirectoryGroupOption.GetHashCode(); |
73 |
| - hashCode = (hashCode * 397) ^ DirectorySortOption.GetHashCode(); |
74 |
| - hashCode = (hashCode * 397) ^ DirectorySortDirection.GetHashCode(); |
75 |
| - hashCode = (hashCode * 397) ^ SortDirectoriesAlongsideFiles.GetHashCode(); |
76 |
| - hashCode = (hashCode * 397) ^ IsAdaptiveLayoutOverridden.GetHashCode(); |
77 |
| - hashCode = (hashCode * 397) ^ ColumnsViewModel.GetHashCode(); |
78 |
| - return hashCode; |
79 |
| - } |
80 |
| - } |
| 73 | + public override int GetHashCode() |
| 74 | + { |
| 75 | + var hashCode = LayoutMode.GetHashCode(); |
| 76 | + hashCode = (hashCode * 397) ^ GridViewSize.GetHashCode(); |
| 77 | + hashCode = (hashCode * 397) ^ DirectoryGroupOption.GetHashCode(); |
| 78 | + hashCode = (hashCode * 397) ^ DirectorySortOption.GetHashCode(); |
| 79 | + hashCode = (hashCode * 397) ^ DirectorySortDirection.GetHashCode(); |
| 80 | + hashCode = (hashCode * 397) ^ SortDirectoriesAlongsideFiles.GetHashCode(); |
| 81 | + hashCode = (hashCode * 397) ^ IsAdaptiveLayoutOverridden.GetHashCode(); |
| 82 | + hashCode = (hashCode * 397) ^ ColumnsViewModel.GetHashCode(); |
| 83 | + return hashCode; |
| 84 | + } |
| 85 | + } |
81 | 86 | }
|
0 commit comments