@@ -608,6 +608,9 @@ async Task CallGetUnityUpdates()
608608 if ( items == null ) return ;
609609 updatesSource = GetUnityUpdates . Parse ( items ) ;
610610 if ( updatesSource == null ) return ;
611+
612+
613+
611614 dataGridUpdates . ItemsSource = updatesSource ;
612615 }
613616
@@ -908,33 +911,17 @@ private void CloseThemeEditor()
908911 private void Window_SizeChanged ( object sender , SizeChangedEventArgs e )
909912 {
910913 var win = ( Window ) sender ;
911- //Properties.Settings.Default.windowWidth = (int)win.Width;
912- //Properties.Settings.Default.windowHeight = (int)win.Height;
913914 // save new size instead, to fix DPI scaling issue
914915 Properties . Settings . Default . windowWidth = ( int ) e . NewSize . Width ;
915916 Properties . Settings . Default . windowHeight = ( int ) e . NewSize . Height ;
916917 Properties . Settings . Default . Save ( ) ;
917-
918- //Console.WriteLine("Window_SizeChanged: " + win.Width + "x" + win.Height + " e:" + e.NewSize.Width + "x" + e.NewSize.Height);
919-
920- //// get current screen DPI
921- //PresentationSource source = PresentationSource.FromVisual(this);
922- //double dpiX, dpiY;
923- //if (source != null)
924- //{
925- // dpiX = 96.0 * source.CompositionTarget.TransformToDevice.M11;
926- // dpiY = 96.0 * source.CompositionTarget.TransformToDevice.M22;
927- // Console.WriteLine("new dpi: " + dpiX + "x" + dpiY);
928- //}
929918 }
930919
931920 private void BtnLaunchProject_Click ( object sender , RoutedEventArgs e )
932921 {
933922 var proj = GetSelectedProject ( ) ;
934923 var proc = Tools . LaunchProject ( proj , gridRecent ) ;
935-
936924 //ProcessHandler.Add(proj, proc);
937-
938925 Tools . SetFocusToGrid ( gridRecent ) ;
939926 }
940927
@@ -2791,13 +2778,79 @@ private void menuItemCopyPathToClipboard_Click(object sender, RoutedEventArgs e)
27912778 Clipboard . SetText ( path ) ;
27922779 }
27932780
2781+ private void dataGridUpdates_Sorting ( object sender , DataGridSortingEventArgs e )
2782+ {
2783+ SortHandlerUpdates ( sender , e ) ;
2784+ }
2785+
2786+ // TODO combine similar methods
2787+ void SortHandlerUpdates ( object sender , DataGridSortingEventArgs e )
2788+ {
2789+ DataGridColumn column = e . Column ;
2790+
2791+ //Console.WriteLine("Sorted by " + column.Header);
2792+
2793+ IComparer comparer = null ;
2794+
2795+ // prevent the built-in sort from sorting
2796+ e . Handled = true ;
2797+
2798+ ListSortDirection direction = ( column . SortDirection != ListSortDirection . Ascending ) ? ListSortDirection . Ascending : ListSortDirection . Descending ;
2799+
2800+ //set the sort order on the column
2801+ column . SortDirection = direction ;
2802+
2803+ //use a ListCollectionView to do the sort.
2804+ ListCollectionView lcv = ( ListCollectionView ) CollectionViewSource . GetDefaultView ( dataGridUpdates . ItemsSource ) ;
2805+
2806+ Console . WriteLine ( "Sorted by " + column . Header + " " + direction ) ;
2807+
2808+ comparer = new CustomUpdatesSort ( direction , column . Header . ToString ( ) ) ;
2809+
2810+ //apply the sort
2811+ lcv . CustomSort = comparer ;
2812+ }
2813+
2814+ public class CustomUpdatesSort : IComparer
2815+ {
2816+ private ListSortDirection direction ;
2817+ private string sortBy ;
2818+
2819+ public CustomUpdatesSort ( ListSortDirection direction , string sortBy )
2820+ {
2821+ this . direction = direction ;
2822+ this . sortBy = sortBy ;
2823+ }
2824+
2825+ public int Compare ( Object a , Object b )
2826+ {
2827+ switch ( sortBy )
2828+ {
2829+ case "Version" :
2830+ // handle null values
2831+ if ( ( ( Updates ) a ) . Version == null && ( ( Updates ) b ) . Version == null ) return 0 ;
2832+ if ( ( ( Updates ) a ) . Version == null ) return direction == ListSortDirection . Ascending ? - 1 : 1 ;
2833+ if ( ( ( Updates ) b ) . Version == null ) return direction == ListSortDirection . Ascending ? 1 : - 1 ;
2834+ return direction == ListSortDirection . Ascending ? Tools . VersionAsInt ( ( ( Updates ) a ) . Version ) . CompareTo ( Tools . VersionAsInt ( ( ( Updates ) b ) . Version ) ) : Tools . VersionAsInt ( ( ( Updates ) b ) . Version ) . CompareTo ( Tools . VersionAsInt ( ( ( Updates ) a ) . Version ) ) ;
2835+ case "Released" :
2836+ // handle null values
2837+ if ( ( ( Updates ) a ) . ReleaseDate == null && ( ( Updates ) b ) . ReleaseDate == null ) return 0 ;
2838+ if ( ( ( Updates ) a ) . ReleaseDate == null ) return direction == ListSortDirection . Ascending ? - 1 : 1 ;
2839+ if ( ( ( Updates ) b ) . ReleaseDate == null ) return direction == ListSortDirection . Ascending ? 1 : - 1 ;
2840+ return direction == ListSortDirection . Ascending ? ( ( DateTime ) ( ( Updates ) a ) . ReleaseDate ) . CompareTo ( ( ( Updates ) b ) . ReleaseDate ) : ( ( DateTime ) ( ( Updates ) b ) . ReleaseDate ) . CompareTo ( ( ( Updates ) a ) . ReleaseDate ) ;
2841+ default :
2842+ return 0 ;
2843+ }
2844+ }
2845+ }
2846+
27942847 private void gridRecent_Sorting ( object sender , DataGridSortingEventArgs e )
27952848 {
2796- SortHandler ( sender , e ) ;
2849+ SortHandlerRecentProjects ( sender , e ) ;
27972850 }
27982851
27992852 // https://stackoverflow.com/a/2130557/5452781
2800- void SortHandler ( object sender , DataGridSortingEventArgs e )
2853+ void SortHandlerRecentProjects ( object sender , DataGridSortingEventArgs e )
28012854 {
28022855 DataGridColumn column = e . Column ;
28032856
@@ -3112,7 +3165,6 @@ private void txtMaxProjectCount_TextChanged(object sender, TextChangedEventArgs
31123165 }
31133166 }
31143167
3115-
31163168 //private void BtnBrowseTemplateUnityPackagesFolder_Click(object sender, RoutedEventArgs e)
31173169 //{
31183170 // var folder = Tools.BrowseForOutputFolder("Select unitypackage Templates folder");
0 commit comments