1010using Files . Enums ;
1111using Files . Filesystem ;
1212using Files . Interacts ;
13- using System . Diagnostics ;
14- using Windows . UI . Core ;
15- using System . Text . RegularExpressions ;
1613using System . IO ;
14+ using System . Runtime . CompilerServices ;
1715
1816namespace Files
1917{
20- public sealed partial class GenericFileBrowser : Page , INotifyPropertyChanged
18+ public sealed partial class GenericFileBrowser : Page
2119 {
2220 public TextBlock emptyTextGFB ;
2321 public TextBlock textBlock ;
@@ -37,8 +35,6 @@ public sealed partial class GenericFileBrowser : Page, INotifyPropertyChanged
3735 ItemViewModel viewModelInstance ;
3836 ProHome tabInstance ;
3937
40- public event PropertyChangedEventHandler PropertyChanged ;
41-
4238 public EmptyFolderTextState TextState { get ; set ; } = new EmptyFolderTextState ( ) ;
4339
4440 public DataGridColumn SortedColumn
@@ -65,42 +61,12 @@ public DataGridColumn SortedColumn
6561 // Remove arrow on previous sorted column
6662 if ( _sortedColumn != null )
6763 _sortedColumn . SortDirection = null ;
68- value . SortDirection = IsSortedAscending ? DataGridSortDirection . Ascending : DataGridSortDirection . Descending ;
6964 }
65+ value . SortDirection = viewModelInstance . DirectorySortDirection == SortDirection . Ascending ? DataGridSortDirection . Ascending : DataGridSortDirection . Descending ;
7066 _sortedColumn = value ;
7167 }
7268 }
7369
74- private bool IsSortedByName { get { return SortedColumn == nameColumn ; } set { if ( value ) SortedColumn = nameColumn ; } }
75- private bool IsSortedByDate { get { return SortedColumn == dateColumn ; } set { if ( value ) SortedColumn = dateColumn ; } }
76- private bool IsSortedByType { get { return SortedColumn == typeColumn ; } set { if ( value ) SortedColumn = typeColumn ; } }
77- private bool IsSortedBySize { get { return SortedColumn == sizeColumn ; } set { if ( value ) SortedColumn = sizeColumn ; } }
78-
79- private bool IsSortedAscending
80- {
81- get
82- {
83- return viewModelInstance . DirectorySortDirection == SortDirection . Ascending ;
84- }
85- set
86- {
87- viewModelInstance . DirectorySortDirection = value ? SortDirection . Ascending : SortDirection . Descending ;
88- _sortedColumn . SortDirection = value ? DataGridSortDirection . Ascending : DataGridSortDirection . Descending ;
89- }
90- }
91-
92- private bool IsSortedDescending
93- {
94- get
95- {
96- return ! IsSortedAscending ;
97- }
98- set
99- {
100- IsSortedAscending = ! value ;
101- }
102- }
103-
10470 public GenericFileBrowser ( )
10571 {
10672 this . InitializeComponent ( ) ;
@@ -154,9 +120,36 @@ public GenericFileBrowser()
154120 SortedColumn = typeColumn ;
155121 break ;
156122 case SortOption . Size :
157- SortedColumn = nameColumn ;
123+ SortedColumn = sizeColumn ;
158124 break ;
159125 }
126+ viewModelInstance . PropertyChanged += ViewModel_PropertyChanged ;
127+ }
128+
129+ private void ViewModel_PropertyChanged ( object sender , PropertyChangedEventArgs e )
130+ {
131+ if ( e . PropertyName == "DirectorySortOption" )
132+ {
133+ switch ( viewModelInstance . DirectorySortOption )
134+ {
135+ case SortOption . Name :
136+ SortedColumn = nameColumn ;
137+ break ;
138+ case SortOption . DateModified :
139+ SortedColumn = dateColumn ;
140+ break ;
141+ case SortOption . FileType :
142+ SortedColumn = typeColumn ;
143+ break ;
144+ case SortOption . Size :
145+ SortedColumn = sizeColumn ;
146+ break ;
147+ }
148+ } else if ( e . PropertyName == "DirectorySortDirection" )
149+ {
150+ // Swap arrows
151+ SortedColumn = _sortedColumn ;
152+ }
160153 }
161154
162155 private void AddItem_Click ( object sender , RoutedEventArgs e )
@@ -410,23 +403,10 @@ private void RightClickContextMenu_Opened(object sender, object e)
410403
411404 private void AllView_Sorting ( object sender , DataGridColumnEventArgs e )
412405 {
413- if ( e . Column == iconColumn )
414- return ;
415- if ( SortedColumn == e . Column )
416- IsSortedAscending = ! IsSortedAscending ;
417- else
418- {
419- IsSortedAscending = true ;
406+ if ( e . Column == SortedColumn )
407+ viewModelInstance . IsSortedAscending = ! viewModelInstance . IsSortedAscending ;
408+ else if ( e . Column != iconColumn )
420409 SortedColumn = e . Column ;
421- }
422-
423- NotifyPropertyChanged ( "IsSortedAscending" ) ;
424- NotifyPropertyChanged ( "IsSortedDescending" ) ;
425- }
426-
427- private void NotifyPropertyChanged ( string info )
428- {
429- PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( info ) ) ;
430410 }
431411 }
432412
@@ -451,9 +431,9 @@ public Visibility isVisible
451431 }
452432 public event PropertyChangedEventHandler PropertyChanged ;
453433
454- private void NotifyPropertyChanged ( string info )
434+ private void NotifyPropertyChanged ( [ CallerMemberName ] string propertyName = "" )
455435 {
456- PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( info ) ) ;
436+ PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( propertyName ) ) ;
457437 }
458438 }
459439}
0 commit comments