1- using Microsoft . Toolkit . Uwp . UI . Controls ;
1+ using Microsoft . Toolkit . Uwp . UI ;
2+ using Microsoft . Toolkit . Uwp . UI . Controls ;
23using System ;
34using System . ComponentModel ;
45using Windows . ApplicationModel . DataTransfer ;
56using Windows . Storage ;
67using Windows . UI . Xaml ;
78using Windows . UI . Xaml . Controls ;
89using Windows . UI . Xaml . Navigation ;
10+ using Files . Enums ;
911using Files . Filesystem ;
10- using Files . Navigation ;
1112using Files . Interacts ;
1213using System . Diagnostics ;
1314using Windows . UI . Core ;
@@ -21,7 +22,6 @@ public sealed partial class GenericFileBrowser : Page, INotifyPropertyChanged
2122 public TextBlock emptyTextGFB ;
2223 public TextBlock textBlock ;
2324 public DataGrid data ;
24- public DataGridColumn sortedColumn ;
2525 public MenuFlyout context ;
2626 public MenuFlyout emptySpaceContext ;
2727 public MenuFlyout HeaderContextMenu ;
@@ -33,14 +33,74 @@ public sealed partial class GenericFileBrowser : Page, INotifyPropertyChanged
3333 public Flyout CopiedFlyout ;
3434 public Grid grid ;
3535 public ProgressBar progressBar ;
36+ private DataGridColumn _sortedColumn ;
3637 ItemViewModel viewModelInstance ;
3738 ProHome tabInstance ;
38- bool isSortedAscending ;
3939
4040 public event PropertyChangedEventHandler PropertyChanged ;
4141
4242 public EmptyFolderTextState TextState { get ; set ; } = new EmptyFolderTextState ( ) ;
4343
44+ public DataGridColumn SortedColumn
45+ {
46+ get
47+ {
48+ return _sortedColumn ;
49+ }
50+ set
51+ {
52+ if ( value == nameColumn )
53+ viewModelInstance . DirectorySortOption = SortOption . Name ;
54+ else if ( value == dateColumn )
55+ viewModelInstance . DirectorySortOption = SortOption . DateModified ;
56+ else if ( value == typeColumn )
57+ viewModelInstance . DirectorySortOption = SortOption . FileType ;
58+ else if ( value == sizeColumn )
59+ viewModelInstance . DirectorySortOption = SortOption . Size ;
60+ else
61+ viewModelInstance . DirectorySortOption = SortOption . Name ;
62+
63+ if ( value != _sortedColumn )
64+ {
65+ // Remove arrow on previous sorted column
66+ if ( _sortedColumn != null )
67+ _sortedColumn . SortDirection = null ;
68+ value . SortDirection = IsSortedAscending ? DataGridSortDirection . Ascending : DataGridSortDirection . Descending ;
69+ }
70+ _sortedColumn = value ;
71+ }
72+ }
73+
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+
44104 public GenericFileBrowser ( )
45105 {
46106 this . InitializeComponent ( ) ;
@@ -49,9 +109,6 @@ public GenericFileBrowser()
49109 progressBar = progBar ;
50110 progressBar . Visibility = Visibility . Collapsed ;
51111 data = AllView ;
52- sortedColumn = nameColumn ;
53- sortedColumn . SortDirection = DataGridSortDirection . Ascending ;
54- isSortedAscending = true ;
55112 context = RightClickContextMenu ;
56113 HeaderContextMenu = HeaderRightClickMenu ;
57114 grid = RootGrid ;
@@ -84,6 +141,22 @@ public GenericFileBrowser()
84141 NewTextDocument . Click += tabInstance . instanceInteraction . NewTextDocument_Click ;
85142 PropertiesItem . Click += tabInstance . ShowPropertiesButton_Click ;
86143 OpenInNewWindowItem . Click += tabInstance . instanceInteraction . OpenInNewWindowItem_Click ;
144+
145+ switch ( viewModelInstance . DirectorySortOption )
146+ {
147+ case SortOption . Name :
148+ SortedColumn = nameColumn ;
149+ break ;
150+ case SortOption . DateModified :
151+ SortedColumn = dateColumn ;
152+ break ;
153+ case SortOption . FileType :
154+ SortedColumn = typeColumn ;
155+ break ;
156+ case SortOption . Size :
157+ SortedColumn = nameColumn ;
158+ break ;
159+ }
87160 }
88161
89162 private void AddItem_Click ( object sender , RoutedEventArgs e )
@@ -339,64 +412,16 @@ private void AllView_Sorting(object sender, DataGridColumnEventArgs e)
339412 {
340413 if ( e . Column == iconColumn )
341414 return ;
342- if ( sortedColumn == e . Column )
343- isSortedAscending = e . Column . SortDirection == DataGridSortDirection . Descending ;
415+ if ( SortedColumn == e . Column )
416+ IsSortedAscending = ! IsSortedAscending ;
344417 else
345418 {
346- isSortedAscending = true ;
419+ IsSortedAscending = true ;
420+ SortedColumn = e . Column ;
347421 }
348422
349423 NotifyPropertyChanged ( "IsSortedAscending" ) ;
350424 NotifyPropertyChanged ( "IsSortedDescending" ) ;
351-
352- SortBy ( e . Column ) ;
353- }
354-
355- private void SortBy ( DataGridColumn column )
356- {
357- var selectedItems = data . SelectedItems ;
358-
359- viewModelInstance . OrderFiles ( column . Tag . ToString ( ) , isSortedAscending ) ;
360-
361- // Remove arrow on previous sorted column
362- sortedColumn . SortDirection = null ;
363- column . SortDirection = isSortedAscending ? DataGridSortDirection . Ascending : DataGridSortDirection . Descending ;
364- sortedColumn = column ;
365-
366- if ( selectedItems . Count == 1 )
367- {
368- data . SelectedItem = selectedItems [ 0 ] ;
369- }
370- }
371-
372- private bool IsSortedByName { get { return sortedColumn == nameColumn ; } set { if ( value ) SortBy ( nameColumn ) ; } }
373- private bool IsSortedByDate { get { return sortedColumn == dateColumn ; } set { if ( value ) SortBy ( dateColumn ) ; } }
374- private bool IsSortedByType { get { return sortedColumn == typeColumn ; } set { if ( value ) SortBy ( typeColumn ) ; } }
375- private bool IsSortedBySize { get { return sortedColumn == sizeColumn ; } set { if ( value ) SortBy ( sizeColumn ) ; } }
376- private bool IsSortedAscending
377- {
378- get
379- {
380- return isSortedAscending ;
381- }
382- set
383- {
384- isSortedAscending = value ;
385- if ( value ) SortBy ( sortedColumn ) ;
386- }
387- }
388-
389- private bool IsSortedDescending
390- {
391- get
392- {
393- return ! isSortedAscending ;
394- }
395- set
396- {
397- isSortedAscending = ! value ;
398- if ( value ) SortBy ( sortedColumn ) ;
399- }
400425 }
401426
402427 private void NotifyPropertyChanged ( string info )
0 commit comments