@@ -79,13 +79,13 @@ private void RefreshLayout()
7979
8080 public class HistoriesCommitList : DataGrid
8181 {
82- public static readonly StyledProperty < List < Models . Commit > > CommitsProperty =
83- AvaloniaProperty . Register < HistoriesCommitList , List < Models . Commit > > ( nameof ( Commits ) , [ ] ) ;
82+ public static readonly StyledProperty < int > TotalCommitsProperty =
83+ AvaloniaProperty . Register < HistoriesCommitList , int > ( nameof ( TotalCommits ) , 0 ) ;
8484
85- public List < Models . Commit > Commits
85+ public int TotalCommits
8686 {
87- get => GetValue ( CommitsProperty ) ;
88- set => SetValue ( CommitsProperty , value ) ;
87+ get => GetValue ( TotalCommitsProperty ) ;
88+ set => SetValue ( TotalCommitsProperty , value ) ;
8989 }
9090
9191 public static readonly StyledProperty < List < Models . Commit > > SelectedCommitsProperty =
@@ -114,23 +114,18 @@ public HistoriesCommitList()
114114 VerticalScrollBarVisibility = ScrollBarVisibility . Auto ;
115115 }
116116
117+ protected override void OnLoaded ( RoutedEventArgs e )
118+ {
119+ base . OnLoaded ( e ) ;
120+ ApplySelection ( ) ;
121+ }
122+
117123 protected override void OnPropertyChanged ( AvaloniaPropertyChangedEventArgs change )
118124 {
119125 base . OnPropertyChanged ( change ) ;
120126
121127 if ( change . Property == SelectedCommitsProperty && IsLoaded && ! _ignoreSelectionChanged )
122- {
123- _ignoreSelectionChanged = true ;
124-
125- SelectedItems . Clear ( ) ;
126- if ( SelectedCommits is { Count : > 0 } )
127- {
128- foreach ( var c in SelectedCommits )
129- SelectedItems . Add ( c ) ;
130- }
131-
132- _ignoreSelectionChanged = false ;
133- }
128+ ApplySelection ( ) ;
134129 }
135130
136131 protected override void OnSelectionChanged ( SelectionChangedEventArgs e )
@@ -180,6 +175,28 @@ protected override void OnSelectionChanged(SelectionChangedEventArgs e)
180175 }
181176 }
182177
178+ private void ApplySelection ( )
179+ {
180+ _ignoreSelectionChanged = true ;
181+
182+ if ( SelectedCommits == null || SelectedCommits . Count == 0 )
183+ {
184+ SelectedItems . Clear ( ) ;
185+ }
186+ else if ( SelectedCommits . Count == TotalCommits )
187+ {
188+ SelectAll ( ) ;
189+ }
190+ else
191+ {
192+ SelectedItems . Clear ( ) ;
193+ foreach ( var c in SelectedCommits )
194+ SelectedItems . Add ( c ) ;
195+ }
196+
197+ _ignoreSelectionChanged = false ;
198+ }
199+
183200 private bool _ignoreSelectionChanged = false ;
184201 }
185202
0 commit comments