@@ -85,6 +85,15 @@ public List<Models.Change> Changes
8585 set => SetValue ( ChangesProperty , value ) ;
8686 }
8787
88+ public static readonly StyledProperty < bool > AutoSelectFirstChangeProperty =
89+ AvaloniaProperty . Register < ChangeCollectionView , bool > ( nameof ( AutoSelectFirstChange ) , false ) ;
90+
91+ public bool AutoSelectFirstChange
92+ {
93+ get => GetValue ( AutoSelectFirstChangeProperty ) ;
94+ set => SetValue ( AutoSelectFirstChangeProperty , value ) ;
95+ }
96+
8897 public static readonly StyledProperty < List < Models . Change > > SelectedChangesProperty =
8998 AvaloniaProperty . Register < ChangeCollectionView , List < Models . Change > > ( nameof ( SelectedChanges ) ) ;
9099
@@ -205,9 +214,9 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
205214 base . OnPropertyChanged ( change ) ;
206215
207216 if ( change . Property == ViewModeProperty )
208- UpdateDataSource ( false ) ;
209- else if ( change . Property == ChangesProperty )
210217 UpdateDataSource ( true ) ;
218+ else if ( change . Property == ChangesProperty )
219+ UpdateDataSource ( false ) ;
211220 else if ( change . Property == SelectedChangesProperty )
212221 UpdateSelection ( ) ;
213222 }
@@ -292,9 +301,9 @@ private void MakeTreeRows(List<ViewModels.ChangeTreeNode> rows, List<ViewModels.
292301 }
293302 }
294303
295- private void UpdateDataSource ( bool disableEvents )
304+ private void UpdateDataSource ( bool onlyViewModeChange )
296305 {
297- _disableSelectionChangingEvent = disableEvents ;
306+ _disableSelectionChangingEvent = ! onlyViewModeChange ;
298307
299308 var changes = Changes ;
300309 if ( changes == null || changes . Count == 0 )
@@ -324,7 +333,19 @@ private void UpdateDataSource(bool disableEvents)
324333 MakeTreeRows ( rows , tree . Tree ) ;
325334 tree . Rows . AddRange ( rows ) ;
326335
327- if ( selected . Count > 0 )
336+ if ( ! onlyViewModeChange && AutoSelectFirstChange )
337+ {
338+ foreach ( var row in tree . Rows )
339+ {
340+ if ( row . Change != null )
341+ {
342+ tree . SelectedRows . Add ( row ) ;
343+ SetCurrentValue ( SelectedChangesProperty , [ row . Change ] ) ;
344+ break ;
345+ }
346+ }
347+ }
348+ else if ( selected . Count > 0 )
328349 {
329350 var sets = new HashSet < Models . Change > ( ) ;
330351 foreach ( var c in selected )
@@ -346,16 +367,34 @@ private void UpdateDataSource(bool disableEvents)
346367 {
347368 var grid = new ViewModels . ChangeCollectionAsGrid ( ) ;
348369 grid . Changes . AddRange ( changes ) ;
349- if ( selected . Count > 0 )
370+
371+ if ( ! onlyViewModeChange && AutoSelectFirstChange )
372+ {
373+ grid . SelectedChanges . Add ( changes [ 0 ] ) ;
374+ SetCurrentValue ( SelectedChangesProperty , [ changes [ 0 ] ] ) ;
375+ }
376+ else if ( selected . Count > 0 )
377+ {
350378 grid . SelectedChanges . AddRange ( selected ) ;
379+ }
380+
351381 Content = grid ;
352382 }
353383 else
354384 {
355385 var list = new ViewModels . ChangeCollectionAsList ( ) ;
356386 list . Changes . AddRange ( changes ) ;
357- if ( selected . Count > 0 )
387+
388+ if ( ! onlyViewModeChange && AutoSelectFirstChange )
389+ {
390+ list . SelectedChanges . Add ( changes [ 0 ] ) ;
391+ SetCurrentValue ( SelectedChangesProperty , [ changes [ 0 ] ] ) ;
392+ }
393+ else if ( selected . Count > 0 )
394+ {
358395 list . SelectedChanges . AddRange ( selected ) ;
396+ }
397+
359398 Content = list ;
360399 }
361400
0 commit comments