@@ -85,6 +85,15 @@ public List<Models.Change> Changes
85
85
set => SetValue ( ChangesProperty , value ) ;
86
86
}
87
87
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
+
88
97
public static readonly StyledProperty < List < Models . Change > > SelectedChangesProperty =
89
98
AvaloniaProperty . Register < ChangeCollectionView , List < Models . Change > > ( nameof ( SelectedChanges ) ) ;
90
99
@@ -205,9 +214,9 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
205
214
base . OnPropertyChanged ( change ) ;
206
215
207
216
if ( change . Property == ViewModeProperty )
208
- UpdateDataSource ( false ) ;
209
- else if ( change . Property == ChangesProperty )
210
217
UpdateDataSource ( true ) ;
218
+ else if ( change . Property == ChangesProperty )
219
+ UpdateDataSource ( false ) ;
211
220
else if ( change . Property == SelectedChangesProperty )
212
221
UpdateSelection ( ) ;
213
222
}
@@ -292,9 +301,9 @@ private void MakeTreeRows(List<ViewModels.ChangeTreeNode> rows, List<ViewModels.
292
301
}
293
302
}
294
303
295
- private void UpdateDataSource ( bool disableEvents )
304
+ private void UpdateDataSource ( bool onlyViewModeChange )
296
305
{
297
- _disableSelectionChangingEvent = disableEvents ;
306
+ _disableSelectionChangingEvent = ! onlyViewModeChange ;
298
307
299
308
var changes = Changes ;
300
309
if ( changes == null || changes . Count == 0 )
@@ -324,7 +333,19 @@ private void UpdateDataSource(bool disableEvents)
324
333
MakeTreeRows ( rows , tree . Tree ) ;
325
334
tree . Rows . AddRange ( rows ) ;
326
335
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 )
328
349
{
329
350
var sets = new HashSet < Models . Change > ( ) ;
330
351
foreach ( var c in selected )
@@ -346,16 +367,34 @@ private void UpdateDataSource(bool disableEvents)
346
367
{
347
368
var grid = new ViewModels . ChangeCollectionAsGrid ( ) ;
348
369
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
+ {
350
378
grid . SelectedChanges . AddRange ( selected ) ;
379
+ }
380
+
351
381
Content = grid ;
352
382
}
353
383
else
354
384
{
355
385
var list = new ViewModels . ChangeCollectionAsList ( ) ;
356
386
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
+ {
358
395
list . SelectedChanges . AddRange ( selected ) ;
396
+ }
397
+
359
398
Content = list ;
360
399
}
361
400
0 commit comments