Skip to content

Commit 7313452

Browse files
authored
Code Quality: Removed legacy SettingsViewModel (#15871)
1 parent 508b3db commit 7313452

File tree

5 files changed

+108
-103
lines changed

5 files changed

+108
-103
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,37 +114,72 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
114114
/// Gets or sets a value indicating if the favorites section should be visible.
115115
/// </summary>
116116
bool ShowPinnedSection { get; set; }
117+
118+
/// <summary>
119+
/// Gets or sets a value indicating if the favorites section should be expanded.
120+
/// </summary>
121+
bool IsPinnedSectionExpanded { get; set; }
117122

118123
/// <summary>
119124
/// Gets or sets a value indicating if the library section should be visible.
120125
/// </summary>
121126
bool ShowLibrarySection { get; set; }
122127

128+
/// <summary>
129+
/// Gets or sets a value indicating if the library section should be expanded.
130+
/// </summary>
131+
bool IsLibrarySectionExpanded { get; set; }
132+
123133
/// <summary>
124134
/// Gets or sets a value indicating if the drive section should be visible.
125135
/// </summary>
126136
bool ShowDrivesSection { get; set; }
127137

138+
/// <summary>
139+
/// Gets or sets a value indicating if the drive section should be expanded.
140+
/// </summary>
141+
bool IsDriveSectionExpanded { get; set; }
142+
128143
/// <summary>
129144
/// Gets or sets a value indicating if the cloud drive section should be visible.
130145
/// </summary>
131146
bool ShowCloudDrivesSection { get; set; }
132147

148+
/// <summary>
149+
/// Gets or sets a value indicating if the cloud drive section should be expanded.
150+
/// </summary>
151+
bool IsCloudDriveSectionExpanded { get; set; }
152+
133153
/// <summary>
134154
/// Gets or sets a value indicating if the network section should be visible.
135155
/// </summary>
136156
bool ShowNetworkSection { get; set; }
137157

158+
/// <summary>
159+
/// Gets or sets a value indicating if the network section should be expanded.
160+
/// </summary>
161+
bool IsNetworkSectionExpanded { get; set; }
162+
138163
/// <summary>
139164
/// Gets or sets a value indicating if the wsl section should be visible.
140165
/// </summary>
141166
bool ShowWslSection { get; set; }
142167

168+
/// <summary>
169+
/// Gets or sets a value indicating if the wsl section should be expanded.
170+
/// </summary>
171+
bool IsWslSectionExpanded { get; set; }
172+
143173
/// <summary>
144174
/// Gets or sets a value indicating if the tags section should be visible.
145175
/// </summary>
146176
bool ShowFileTagsSection { get; set; }
147177

178+
/// <summary>
179+
/// Gets or sets a value indicating if the file tags section should be expanded.
180+
/// </summary>
181+
bool IsFileTagsSectionExpanded { get; set; }
182+
148183
/// <summary>
149184
/// Gets or sets a value indicating whether or not to move shell extensions into a sub menu.
150185
/// </summary>

src/Files.App/Helpers/Application/AppLifecycleHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ public static IHost ConfigureHost()
205205
.AddSingleton<MainPageViewModel>()
206206
.AddSingleton<InfoPaneViewModel>()
207207
.AddSingleton<SidebarViewModel>()
208-
.AddSingleton<SettingsViewModel>()
209208
.AddSingleton<DrivesViewModel>()
210209
.AddSingleton<StatusCenterViewModel>()
211210
.AddSingleton<AppearanceViewModel>()

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,42 +143,84 @@ public bool ShowPinnedSection
143143
set => Set(value);
144144
}
145145

146+
public bool IsPinnedSectionExpanded
147+
{
148+
get => Get(true);
149+
set => Set(value);
150+
}
151+
146152
public bool ShowLibrarySection
147153
{
148154
get => Get(false);
149155
set => Set(value);
150156
}
151157

158+
public bool IsLibrarySectionExpanded
159+
{
160+
get => Get(false);
161+
set => Set(value);
162+
}
163+
152164
public bool ShowDrivesSection
153165
{
154166
get => Get(true);
155167
set => Set(value);
156168
}
157169

170+
public bool IsDriveSectionExpanded
171+
{
172+
get => Get(false);
173+
set => Set(value);
174+
}
175+
158176
public bool ShowCloudDrivesSection
159177
{
160178
get => Get(true);
161179
set => Set(value);
162180
}
163181

182+
public bool IsCloudDriveSectionExpanded
183+
{
184+
get => Get(false);
185+
set => Set(value);
186+
}
187+
164188
public bool ShowNetworkSection
165189
{
166190
get => Get(true);
167191
set => Set(value);
168192
}
169193

194+
public bool IsNetworkSectionExpanded
195+
{
196+
get => Get(false);
197+
set => Set(value);
198+
}
199+
170200
public bool ShowWslSection
171201
{
172202
get => Get(true);
173203
set => Set(value);
174204
}
175205

206+
public bool IsWslSectionExpanded
207+
{
208+
get => Get(false);
209+
set => Set(value);
210+
211+
}
176212
public bool ShowFileTagsSection
177213
{
178214
get => Get(true);
179215
set => Set(value);
180216
}
181217

218+
public bool IsFileTagsSectionExpanded
219+
{
220+
get => Get(false);
221+
set => Set(value);
222+
}
223+
182224
public bool MoveShellExtensionsToSubMenu
183225
{
184226
get => Get(true);

src/Files.App/ViewModels/SettingsViewModel.cs

Lines changed: 0 additions & 100 deletions
This file was deleted.

src/Files.App/ViewModels/UserControls/SidebarViewModel.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,37 @@ await lib.CheckDefaultSaveFolderAccess() &&
397397
}
398398
}
399399

400-
section.IsExpanded = Ioc.Default.GetRequiredService<SettingsViewModel>().Get(section.Text == "Pinned".GetLocalizedResource(), $"section:{section.Text.Replace('\\', '_')}");
401400
section.PropertyChanged += Section_PropertyChanged;
402401
}
403402

404403
private void Section_PropertyChanged(object? sender, PropertyChangedEventArgs e)
405404
{
406405
if (sender is LocationItem section && e.PropertyName == nameof(section.IsExpanded))
407406
{
408-
Ioc.Default.GetRequiredService<SettingsViewModel>().Set(section.IsExpanded, $"section:{section.Text.Replace('\\', '_')}");
407+
switch (section.Text)
408+
{
409+
case var text when text == "Pinned".GetLocalizedResource():
410+
UserSettingsService.GeneralSettingsService.IsPinnedSectionExpanded = section.IsExpanded;
411+
break;
412+
case var text when text == "SidebarLibraries".GetLocalizedResource():
413+
UserSettingsService.GeneralSettingsService.IsLibrarySectionExpanded = section.IsExpanded;
414+
break;
415+
case var text when text == "Drives".GetLocalizedResource():
416+
UserSettingsService.GeneralSettingsService.IsDriveSectionExpanded = section.IsExpanded;
417+
break;
418+
case var text when text == "SidebarCloudDrives".GetLocalizedResource():
419+
UserSettingsService.GeneralSettingsService.IsCloudDriveSectionExpanded = section.IsExpanded;
420+
break;
421+
case var text when text == "Network".GetLocalizedResource():
422+
UserSettingsService.GeneralSettingsService.IsNetworkSectionExpanded = section.IsExpanded;
423+
break;
424+
case var text when text == "WSL".GetLocalizedResource():
425+
UserSettingsService.GeneralSettingsService.IsWslSectionExpanded = section.IsExpanded;
426+
break;
427+
case var text when text == "FileTags".GetLocalizedResource():
428+
UserSettingsService.GeneralSettingsService.IsFileTagsSectionExpanded = section.IsExpanded;
429+
break;
430+
}
409431
}
410432
}
411433

@@ -448,6 +470,7 @@ private async Task<LocationItem> CreateSectionAsync(SectionType sectionType)
448470
section = BuildSection("Pinned".GetLocalizedResource(), sectionType, new ContextMenuOptions { ShowHideSection = true }, false);
449471
icon = new BitmapImage(new Uri(Constants.FluentIconsPaths.StarIcon));
450472
section.IsHeader = true;
473+
section.IsExpanded = UserSettingsService.GeneralSettingsService.IsPinnedSectionExpanded;
451474

452475
break;
453476
}
@@ -461,6 +484,7 @@ private async Task<LocationItem> CreateSectionAsync(SectionType sectionType)
461484
section = BuildSection("SidebarLibraries".GetLocalizedResource(), sectionType, new ContextMenuOptions { IsLibrariesHeader = true, ShowHideSection = true }, false);
462485
iconIdex = Constants.ImageRes.Libraries;
463486
section.IsHeader = true;
487+
section.IsExpanded = UserSettingsService.GeneralSettingsService.IsLibrarySectionExpanded;
464488

465489
break;
466490
}
@@ -474,6 +498,7 @@ private async Task<LocationItem> CreateSectionAsync(SectionType sectionType)
474498
section = BuildSection("Drives".GetLocalizedResource(), sectionType, new ContextMenuOptions { ShowHideSection = true }, false);
475499
iconIdex = Constants.ImageRes.ThisPC;
476500
section.IsHeader = true;
501+
section.IsExpanded = UserSettingsService.GeneralSettingsService.IsDriveSectionExpanded;
477502

478503
break;
479504
}
@@ -487,6 +512,7 @@ private async Task<LocationItem> CreateSectionAsync(SectionType sectionType)
487512
section = BuildSection("SidebarCloudDrives".GetLocalizedResource(), sectionType, new ContextMenuOptions { ShowHideSection = true }, false);
488513
icon = new BitmapImage(new Uri(Constants.FluentIconsPaths.CloudDriveIcon));
489514
section.IsHeader = true;
515+
section.IsExpanded = UserSettingsService.GeneralSettingsService.IsCloudDriveSectionExpanded;
490516

491517
break;
492518
}
@@ -500,6 +526,7 @@ private async Task<LocationItem> CreateSectionAsync(SectionType sectionType)
500526
section = BuildSection("Network".GetLocalizedResource(), sectionType, new ContextMenuOptions { ShowHideSection = true }, false);
501527
iconIdex = Constants.ImageRes.Network;
502528
section.IsHeader = true;
529+
section.IsExpanded = UserSettingsService.GeneralSettingsService.IsNetworkSectionExpanded;
503530

504531
break;
505532
}
@@ -513,6 +540,7 @@ private async Task<LocationItem> CreateSectionAsync(SectionType sectionType)
513540
section = BuildSection("WSL".GetLocalizedResource(), sectionType, new ContextMenuOptions { ShowHideSection = true }, false);
514541
icon = new BitmapImage(new Uri(Constants.WslIconsPaths.GenericIcon));
515542
section.IsHeader = true;
543+
section.IsExpanded = UserSettingsService.GeneralSettingsService.IsWslSectionExpanded;
516544

517545
break;
518546
}
@@ -526,6 +554,7 @@ private async Task<LocationItem> CreateSectionAsync(SectionType sectionType)
526554
section = BuildSection("FileTags".GetLocalizedResource(), sectionType, new ContextMenuOptions { ShowHideSection = true }, false);
527555
icon = new BitmapImage(new Uri(Constants.FluentIconsPaths.FileTagsIcon));
528556
section.IsHeader = true;
557+
section.IsExpanded = UserSettingsService.GeneralSettingsService.IsFileTagsSectionExpanded;
529558

530559
break;
531560
}

0 commit comments

Comments
 (0)