@@ -2563,6 +2563,85 @@ private void menuItemCopyPathToClipboard_Click(object sender, RoutedEventArgs e)
2563
2563
Clipboard . SetText ( path ) ;
2564
2564
}
2565
2565
2566
+ private void gridRecent_Sorting ( object sender , DataGridSortingEventArgs e )
2567
+ {
2568
+ SortHandler ( sender , e ) ;
2569
+ }
2570
+
2571
+ // https://stackoverflow.com/a/2130557/5452781
2572
+ void SortHandler ( object sender , DataGridSortingEventArgs e )
2573
+ {
2574
+ DataGridColumn column = e . Column ;
2575
+
2576
+ //Console.WriteLine("Sorted by " + column.Header);
2577
+
2578
+ IComparer comparer = null ;
2579
+
2580
+ // prevent the built-in sort from sorting
2581
+ e . Handled = true ;
2582
+
2583
+ ListSortDirection direction = ( column . SortDirection != ListSortDirection . Ascending ) ? ListSortDirection . Ascending : ListSortDirection . Descending ;
2584
+
2585
+ //set the sort order on the column
2586
+ column . SortDirection = direction ;
2587
+
2588
+ //use a ListCollectionView to do the sort.
2589
+ ListCollectionView lcv = ( ListCollectionView ) CollectionViewSource . GetDefaultView ( gridRecent . ItemsSource ) ;
2590
+
2591
+ comparer = new CustomProjectSort ( direction , column . Header . ToString ( ) ) ;
2592
+
2593
+ //apply the sort
2594
+ lcv . CustomSort = comparer ;
2595
+ }
2596
+
2597
+ public class CustomProjectSort : IComparer
2598
+ {
2599
+ private ListSortDirection direction ;
2600
+ private string sortBy ;
2601
+
2602
+ public CustomProjectSort ( ListSortDirection direction , string sortBy )
2603
+ {
2604
+ this . direction = direction ;
2605
+ this . sortBy = sortBy ;
2606
+ }
2607
+
2608
+ // TODO cleanup this
2609
+ public int Compare ( Object a , Object b )
2610
+ {
2611
+ switch ( sortBy )
2612
+ {
2613
+ case "Project" :
2614
+ return direction == ListSortDirection . Ascending ? ( ( Project ) a ) . Title . CompareTo ( ( ( Project ) b ) . Title ) : ( ( Project ) b ) . Title . CompareTo ( ( ( Project ) a ) . Title ) ;
2615
+ case "Version" :
2616
+ return direction == ListSortDirection . Ascending ? Tools . VersionAsInt ( ( ( Project ) a ) . Version ) . CompareTo ( Tools . VersionAsInt ( ( ( Project ) b ) . Version ) ) : Tools . VersionAsInt ( ( ( Project ) b ) . Version ) . CompareTo ( Tools . VersionAsInt ( ( ( Project ) a ) . Version ) ) ;
2617
+ case "Path" :
2618
+ return direction == ListSortDirection . Ascending ? ( ( Project ) a ) . Path . CompareTo ( ( ( Project ) b ) . Path ) : ( ( Project ) b ) . Path . CompareTo ( ( ( Project ) a ) . Path ) ;
2619
+ case "Modified" :
2620
+ return direction == ListSortDirection . Ascending ? ( ( DateTime ) ( ( Project ) a ) . Modified ) . CompareTo ( ( ( Project ) b ) . Modified ) : ( ( DateTime ) ( ( Project ) b ) . Modified ) . CompareTo ( ( ( Project ) a ) . Modified ) ;
2621
+ case "Arguments" :
2622
+ // handle null values
2623
+ if ( ( ( Project ) a ) . Arguments == null && ( ( Project ) b ) . Arguments == null ) return 0 ;
2624
+ if ( ( ( Project ) a ) . Arguments == null ) return direction == ListSortDirection . Ascending ? - 1 : 1 ;
2625
+ if ( ( ( Project ) b ) . Arguments == null ) return direction == ListSortDirection . Ascending ? 1 : - 1 ;
2626
+ return direction == ListSortDirection . Ascending ? ( ( Project ) a ) . Arguments . CompareTo ( ( ( Project ) b ) . Arguments ) : ( ( Project ) b ) . Arguments . CompareTo ( ( ( Project ) a ) . Arguments ) ;
2627
+ case "Branch" :
2628
+ // handle null values
2629
+ if ( ( ( Project ) a ) . GITBranch == null && ( ( Project ) b ) . GITBranch == null ) return 0 ;
2630
+ if ( ( ( Project ) a ) . GITBranch == null ) return direction == ListSortDirection . Ascending ? - 1 : 1 ;
2631
+ if ( ( ( Project ) b ) . GITBranch == null ) return direction == ListSortDirection . Ascending ? 1 : - 1 ;
2632
+ return direction == ListSortDirection . Ascending ? ( ( Project ) a ) . GITBranch . CompareTo ( ( ( Project ) b ) . GITBranch ) : ( ( Project ) b ) . GITBranch . CompareTo ( ( ( Project ) a ) . GITBranch ) ;
2633
+ case "Platform" :
2634
+ // handle null values
2635
+ if ( ( ( Project ) a ) . TargetPlatform == null && ( ( Project ) b ) . TargetPlatform == null ) return 0 ;
2636
+ if ( ( ( Project ) a ) . TargetPlatform == null ) return direction == ListSortDirection . Ascending ? - 1 : 1 ;
2637
+ if ( ( ( Project ) b ) . TargetPlatform == null ) return direction == ListSortDirection . Ascending ? 1 : - 1 ;
2638
+ return direction == ListSortDirection . Ascending ? ( ( Project ) a ) . TargetPlatform . CompareTo ( ( ( Project ) b ) . TargetPlatform ) : ( ( Project ) b ) . TargetPlatform . CompareTo ( ( ( Project ) a ) . TargetPlatform ) ;
2639
+ default :
2640
+ return 0 ;
2641
+ }
2642
+ }
2643
+ }
2644
+
2566
2645
//private void BtnBrowseTemplateUnityPackagesFolder_Click(object sender, RoutedEventArgs e)
2567
2646
//{
2568
2647
// var folder = Tools.BrowseForOutputFolder("Select unitypackage Templates folder");
0 commit comments