|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.IO; |
4 | 4 | using System.Threading.Tasks; |
| 5 | +using Avalonia.Threading; |
5 | 6 | using CommunityToolkit.Mvvm.ComponentModel; |
6 | 7 |
|
7 | 8 | namespace SourceGit.ViewModels |
@@ -187,6 +188,30 @@ public string StagedCountInfo |
187 | 188 | get => string.IsNullOrEmpty(_filter) ? $"({_staged.Count})" : $"({_visibleStaged.Count}/{_staged.Count})"; |
188 | 189 | } |
189 | 190 |
|
| 191 | + public int UnstagedAddedLines |
| 192 | + { |
| 193 | + get => _unstagedAddedLines; |
| 194 | + private set => SetProperty(ref _unstagedAddedLines, value); |
| 195 | + } |
| 196 | + |
| 197 | + public int UnstagedDeletedLines |
| 198 | + { |
| 199 | + get => _unstagedDeletedLines; |
| 200 | + private set => SetProperty(ref _unstagedDeletedLines, value); |
| 201 | + } |
| 202 | + |
| 203 | + public int StagedAddedLines |
| 204 | + { |
| 205 | + get => _stagedAddedLines; |
| 206 | + private set => SetProperty(ref _stagedAddedLines, value); |
| 207 | + } |
| 208 | + |
| 209 | + public int StagedDeletedLines |
| 210 | + { |
| 211 | + get => _stagedDeletedLines; |
| 212 | + private set => SetProperty(ref _stagedDeletedLines, value); |
| 213 | + } |
| 214 | + |
190 | 215 | public ChangeSelection SelectedUnstaged |
191 | 216 | { |
192 | 217 | get => _selectedUnstaged; |
@@ -358,6 +383,29 @@ public void SetData(List<Models.Change> changes) |
358 | 383 |
|
359 | 384 | UpdateInProgressState(); |
360 | 385 | UpdateDetail(); |
| 386 | + |
| 387 | + _ = Task.Run(async () => |
| 388 | + { |
| 389 | + var pref = Preferences.Instance; |
| 390 | + var unstagedStats = await new Commands.QueryDiffLineStats( |
| 391 | + _repo.FullPath, false, pref.IgnoreWhitespaceChangesInDiff, pref.IgnoreCRAtEOLInDiff) |
| 392 | + .GetResultAsync().ConfigureAwait(false); |
| 393 | + var stagedStats = await new Commands.QueryDiffLineStats( |
| 394 | + _repo.FullPath, true, pref.IgnoreWhitespaceChangesInDiff, pref.IgnoreCRAtEOLInDiff) |
| 395 | + .GetResultAsync().ConfigureAwait(false); |
| 396 | + |
| 397 | + Dispatcher.UIThread.Post(() => |
| 398 | + { |
| 399 | + // A newer SetData may have run while fetching stats; drop this stale update. |
| 400 | + if (!ReferenceEquals(_cached, changes)) |
| 401 | + return; |
| 402 | + |
| 403 | + UnstagedAddedLines = unstagedStats.added; |
| 404 | + UnstagedDeletedLines = unstagedStats.deleted; |
| 405 | + StagedAddedLines = stagedStats.added; |
| 406 | + StagedDeletedLines = stagedStats.deleted; |
| 407 | + }); |
| 408 | + }); |
361 | 409 | } |
362 | 410 |
|
363 | 411 | public async Task StageChangesAsync(List<Models.Change> changes, Models.Change next) |
@@ -874,6 +922,10 @@ private bool IsChanged(List<Models.Change> old, List<Models.Change> cur) |
874 | 922 | private List<Models.Change> _visibleStaged = []; |
875 | 923 | private ChangeSelection _selectedUnstaged = new(null); |
876 | 924 | private ChangeSelection _selectedStaged = new(null); |
| 925 | + private int _unstagedAddedLines = 0; |
| 926 | + private int _unstagedDeletedLines = 0; |
| 927 | + private int _stagedAddedLines = 0; |
| 928 | + private int _stagedDeletedLines = 0; |
877 | 929 | private object _detailContext = null; |
878 | 930 | private string _filter = string.Empty; |
879 | 931 | private string _commitMessage = string.Empty; |
|
0 commit comments