mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-29 16:14:59 +00:00
fix: ahead/behind indicator of commit in histories view not updated after upstream changed
This commit is contained in:
parent
ce7420354d
commit
c596427380
6 changed files with 99 additions and 29 deletions
|
@ -62,15 +62,10 @@
|
|||
<DataTemplate x:DataType="{x:Type m:Commit}">
|
||||
<Border Margin="{Binding Margin}">
|
||||
<StackPanel Orientation="Horizontal" Margin="2,0,0,0">
|
||||
<Ellipse Width="5" Height="5"
|
||||
Margin="0,0,4,0"
|
||||
Fill="{DynamicResource Brush.Accent}"
|
||||
IsVisible="{Binding CanPushToUpstream}"/>
|
||||
|
||||
<Ellipse Width="5" Height="5"
|
||||
Margin="0,0,4,0"
|
||||
Fill="{DynamicResource Brush.FG1}"
|
||||
IsVisible="{Binding CanPullFromUpstream}"/>
|
||||
<v:CommitStatusIndicator CurrentBranch="{Binding $parent[v:Histories].CurrentBranch}"
|
||||
AheadBrush="{DynamicResource Brush.Accent}"
|
||||
BehindBrush="{DynamicResource Brush.FG1}"
|
||||
VerticalAlignment="Center"/>
|
||||
|
||||
<v:CommitRefsPresenter IsVisible="{Binding HasDecorators}"
|
||||
IconBackground="{DynamicResource Brush.DecoratorIconBG}"
|
||||
|
|
|
@ -74,6 +74,88 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
public class CommitStatusIndicator : Control
|
||||
{
|
||||
public static readonly StyledProperty<Models.Branch> CurrentBranchProperty =
|
||||
AvaloniaProperty.Register<CommitStatusIndicator, Models.Branch>(nameof(CurrentBranch));
|
||||
|
||||
public Models.Branch CurrentBranch
|
||||
{
|
||||
get => GetValue(CurrentBranchProperty);
|
||||
set => SetValue(CurrentBranchProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<IBrush> AheadBrushProperty =
|
||||
AvaloniaProperty.Register<CommitStatusIndicator, IBrush>(nameof(AheadBrush));
|
||||
|
||||
public IBrush AheadBrush
|
||||
{
|
||||
get => GetValue(AheadBrushProperty);
|
||||
set => SetValue(AheadBrushProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<IBrush> BehindBrushProperty =
|
||||
AvaloniaProperty.Register<CommitStatusIndicator, IBrush>(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<string> SubjectProperty =
|
||||
|
@ -450,6 +532,15 @@ namespace SourceGit.Views
|
|||
|
||||
public partial class Histories : UserControl
|
||||
{
|
||||
public static readonly StyledProperty<Models.Branch> CurrentBranchProperty =
|
||||
AvaloniaProperty.Register<Histories, Models.Branch>(nameof(CurrentBranch));
|
||||
|
||||
public Models.Branch CurrentBranch
|
||||
{
|
||||
get => GetValue(CurrentBranchProperty);
|
||||
set => SetValue(CurrentBranchProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<long> NavigationIdProperty =
|
||||
AvaloniaProperty.Register<Histories, long>(nameof(NavigationId));
|
||||
|
||||
|
|
|
@ -728,7 +728,8 @@
|
|||
<ContentControl Grid.Row="2" Content="{Binding SelectedView}">
|
||||
<ContentControl.DataTemplates>
|
||||
<DataTemplate DataType="vm:Histories">
|
||||
<v:Histories NavigationId="{Binding NavigationId}"/>
|
||||
<v:Histories CurrentBranch="{Binding $parent[v:Repository].((vm:Repository)DataContext).CurrentBranch}"
|
||||
NavigationId="{Binding NavigationId}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:WorkingCopy">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue