diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index f30596ae..6a199478 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -25,8 +25,6 @@ namespace SourceGit.Models public bool HasDecorators => Decorators.Count > 0; public bool IsMerged { get; set; } = false; - public bool CanPushToUpstream { get; set; } = false; - public bool CanPullFromUpstream { get; set; } = false; public Thickness Margin { get; set; } = new Thickness(0); public string AuthorTimeStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss"); diff --git a/src/Models/CommitGraph.cs b/src/Models/CommitGraph.cs index c5c66482..6f371594 100644 --- a/src/Models/CommitGraph.cs +++ b/src/Models/CommitGraph.cs @@ -128,7 +128,7 @@ namespace SourceGit.Models _penCount = colors.Count; } - public static CommitGraph Parse(List commits, HashSet canPushCommits, HashSet canPullCommits) + public static CommitGraph Parse(List commits) { double UNIT_WIDTH = 12; double HALF_WIDTH = 6; @@ -148,9 +148,6 @@ namespace SourceGit.Models var isMerged = commit.IsMerged; var oldCount = unsolved.Count; - commit.CanPushToUpstream = canPushCommits.Remove(commit.SHA); - commit.CanPullFromUpstream = canPullCommits.Remove(commit.SHA); - // Update current y offset offsetY += UNIT_HEIGHT; diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index d1d7606b..0bf9645f 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -749,20 +749,8 @@ namespace SourceGit.ViewModels limits += "--branches --remotes --tags"; } - var canPushCommits = new HashSet(); - var canPullCommits = new HashSet(); - var currentBranch = _branches.Find(x => x.IsCurrent); - if (currentBranch != null) - { - foreach (var sha in currentBranch.TrackStatus.Ahead) - canPushCommits.Add(sha); - - foreach (var sha in currentBranch.TrackStatus.Behind) - canPullCommits.Add(sha); - } - var commits = new Commands.QueryCommits(_fullpath, limits).Result(); - var graph = Models.CommitGraph.Parse(commits, canPushCommits, canPullCommits); + var graph = Models.CommitGraph.Parse(commits); Dispatcher.UIThread.Invoke(() => { diff --git a/src/Views/Histories.axaml b/src/Views/Histories.axaml index b9ff71e6..91190315 100644 --- a/src/Views/Histories.axaml +++ b/src/Views/Histories.axaml @@ -62,15 +62,10 @@ - - - + CurrentBranchProperty = + AvaloniaProperty.Register(nameof(CurrentBranch)); + + public Models.Branch CurrentBranch + { + get => GetValue(CurrentBranchProperty); + set => SetValue(CurrentBranchProperty, value); + } + + public static readonly StyledProperty AheadBrushProperty = + AvaloniaProperty.Register(nameof(AheadBrush)); + + public IBrush AheadBrush + { + get => GetValue(AheadBrushProperty); + set => SetValue(AheadBrushProperty, value); + } + + public static readonly StyledProperty BehindBrushProperty = + AvaloniaProperty.Register(nameof(BehindBrush)); + + public IBrush BehindBrush + { + get => GetValue(BehindBrushProperty); + set => SetValue(BehindBrushProperty, value); + } + + enum Status + { + Normal, + Ahead, + Behind, + } + + public override void Render(DrawingContext context) + { + if (_status == Status.Normal) + return; + + context.DrawEllipse(_status == Status.Ahead ? AheadBrush : BehindBrush, null, new Rect(0, 0, 5, 5)); + } + + protected override Size MeasureOverride(Size availableSize) + { + if (DataContext is Models.Commit commit && CurrentBranch is not null) + { + var sha = commit.SHA; + var track = CurrentBranch.TrackStatus; + + if (track.Ahead.Contains(sha)) + _status = Status.Ahead; + else if (track.Behind.Contains(sha)) + _status = Status.Behind; + else + _status = Status.Normal; + } + else + { + _status = Status.Normal; + } + + return _status == Status.Normal ? new Size(0, 0) : new Size(9, 5); + } + + protected override void OnDataContextChanged(EventArgs e) + { + base.OnDataContextChanged(e); + InvalidateMeasure(); + } + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + if (change.Property == CurrentBranchProperty) + InvalidateMeasure(); + } + + private Status _status = Status.Normal; + } + public class CommitSubjectPresenter : TextBlock { public static readonly StyledProperty SubjectProperty = @@ -450,6 +532,15 @@ namespace SourceGit.Views public partial class Histories : UserControl { + public static readonly StyledProperty CurrentBranchProperty = + AvaloniaProperty.Register(nameof(CurrentBranch)); + + public Models.Branch CurrentBranch + { + get => GetValue(CurrentBranchProperty); + set => SetValue(CurrentBranchProperty, value); + } + public static readonly StyledProperty NavigationIdProperty = AvaloniaProperty.Register(nameof(NavigationId)); diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index b288937b..e2ee4ea8 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -728,7 +728,8 @@ - +