@@ -8,14 +8,8 @@ namespace Files.App.ViewModels.UserControls
88{
99 public sealed partial class SidebarViewModel
1010 {
11- // Each tab is the sole source of truth for its own expansion (sections and folders alike); Pinned/Drives/CloudDrives are seeded as expanded so a fresh tab matches the historical defaults .
11+ // Each tab is the sole source of truth for its own expansion (sections and folders alike); section expansion is additionally mirrored into the per-section IGeneralSettingsService.Is*SectionExpanded bools so it survives across sessions and seeds freshly opened tabs .
1212 private static readonly string [ ] SectionKeyByEnum = BuildSectionKeyByEnum ( ) ;
13- private static readonly string [ ] DefaultExpandedSectionKeys =
14- {
15- SectionKeyByEnum [ ( int ) SectionType . Pinned ] ,
16- SectionKeyByEnum [ ( int ) SectionType . Drives ] ,
17- SectionKeyByEnum [ ( int ) SectionType . CloudDrives ] ,
18- } ;
1913
2014 private static string [ ] BuildSectionKeyByEnum ( )
2115 {
@@ -26,6 +20,54 @@ private static string[] BuildSectionKeyByEnum()
2620 return arr ;
2721 }
2822
23+ private IEnumerable < string > GetPersistedExpandedSectionKeys ( )
24+ {
25+ var general = UserSettingsService . GeneralSettingsService ;
26+ if ( general . IsPinnedSectionExpanded )
27+ yield return SectionKeyByEnum [ ( int ) SectionType . Pinned ] ;
28+ if ( general . IsLibrarySectionExpanded )
29+ yield return SectionKeyByEnum [ ( int ) SectionType . Library ] ;
30+ if ( general . IsDriveSectionExpanded )
31+ yield return SectionKeyByEnum [ ( int ) SectionType . Drives ] ;
32+ if ( general . IsCloudDriveSectionExpanded )
33+ yield return SectionKeyByEnum [ ( int ) SectionType . CloudDrives ] ;
34+ if ( general . IsNetworkSectionExpanded )
35+ yield return SectionKeyByEnum [ ( int ) SectionType . Network ] ;
36+ if ( general . IsWslSectionExpanded )
37+ yield return SectionKeyByEnum [ ( int ) SectionType . WSL ] ;
38+ if ( general . IsFileTagsSectionExpanded )
39+ yield return SectionKeyByEnum [ ( int ) SectionType . FileTag ] ;
40+ }
41+
42+ private void PersistSectionExpansion ( SectionType section , bool isExpanded )
43+ {
44+ var general = UserSettingsService . GeneralSettingsService ;
45+ switch ( section )
46+ {
47+ case SectionType . Pinned :
48+ general . IsPinnedSectionExpanded = isExpanded ;
49+ break ;
50+ case SectionType . Library :
51+ general . IsLibrarySectionExpanded = isExpanded ;
52+ break ;
53+ case SectionType . Drives :
54+ general . IsDriveSectionExpanded = isExpanded ;
55+ break ;
56+ case SectionType . CloudDrives :
57+ general . IsCloudDriveSectionExpanded = isExpanded ;
58+ break ;
59+ case SectionType . Network :
60+ general . IsNetworkSectionExpanded = isExpanded ;
61+ break ;
62+ case SectionType . WSL :
63+ general . IsWslSectionExpanded = isExpanded ;
64+ break ;
65+ case SectionType . FileTag :
66+ general . IsFileTagsSectionExpanded = isExpanded ;
67+ break ;
68+ }
69+ }
70+
2971 private readonly Dictionary < TabBarItem , HashSet < string > > tabExpansionState = new ( ) ;
3072 private readonly HashSet < INotifyPropertyChanged > trackedItems = new ( ) ;
3173 private readonly HashSet < INotifyCollectionChanged > trackedChildCollections = new ( ) ;
@@ -113,8 +155,8 @@ private HashSet<string> GetOrInitTabState(TabBarItem tab)
113155 {
114156 if ( ! tabExpansionState . TryGetValue ( tab , out var state ) )
115157 {
116- state = new HashSet < string > ( DefaultExpandedSectionKeys , StringComparer . OrdinalIgnoreCase ) ;
117- // Inherit whatever section state the user currently sees so a freshly opened tab matches expectation rather than snapping back to defaults .
158+ state = new HashSet < string > ( GetPersistedExpandedSectionKeys ( ) , StringComparer . OrdinalIgnoreCase ) ;
159+ // Inherit whatever section state the user currently sees so a freshly opened tab matches expectation rather than snapping back to the persisted baseline .
118160 foreach ( var sectionObj in sidebarItems )
119161 {
120162 if ( sectionObj is LocationItem section && section . IsExpanded )
@@ -231,6 +273,8 @@ private void CaptureExpansionToCurrentTab(INavigationControlItem item)
231273 state . Add ( key ) ;
232274 else
233275 state . Remove ( key ) ;
276+ if ( item is LocationItem { IsHeader : true } section )
277+ PersistSectionExpansion ( section . Section , item . IsExpanded ) ;
234278 }
235279
236280 // Restores expansion for the initial pass over sidebarItems and for items realized later (async section sync, lazy-loaded subfolders).
0 commit comments