mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 04:04:59 +00:00
code_style: move some code from Histories.axaml
to separate files
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
bb2284c4c9
commit
0476a825ef
6 changed files with 705 additions and 672 deletions
90
src/Views/CommitStatusIndicator.cs
Normal file
90
src/Views/CommitStatusIndicator.cs
Normal file
|
@ -0,0 +1,90 @@
|
|||
using System;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue