@@ -74,6 +74,88 @@ private void RefreshLayout()
74
74
}
75
75
}
76
76
77
+ public class CommitStatusIndicator : Control
78
+ {
79
+ public static readonly StyledProperty < Models . Branch > CurrentBranchProperty =
80
+ AvaloniaProperty . Register < CommitStatusIndicator , Models . Branch > ( nameof ( CurrentBranch ) ) ;
81
+
82
+ public Models . Branch CurrentBranch
83
+ {
84
+ get => GetValue ( CurrentBranchProperty ) ;
85
+ set => SetValue ( CurrentBranchProperty , value ) ;
86
+ }
87
+
88
+ public static readonly StyledProperty < IBrush > AheadBrushProperty =
89
+ AvaloniaProperty . Register < CommitStatusIndicator , IBrush > ( nameof ( AheadBrush ) ) ;
90
+
91
+ public IBrush AheadBrush
92
+ {
93
+ get => GetValue ( AheadBrushProperty ) ;
94
+ set => SetValue ( AheadBrushProperty , value ) ;
95
+ }
96
+
97
+ public static readonly StyledProperty < IBrush > BehindBrushProperty =
98
+ AvaloniaProperty . Register < CommitStatusIndicator , IBrush > ( nameof ( BehindBrush ) ) ;
99
+
100
+ public IBrush BehindBrush
101
+ {
102
+ get => GetValue ( BehindBrushProperty ) ;
103
+ set => SetValue ( BehindBrushProperty , value ) ;
104
+ }
105
+
106
+ enum Status
107
+ {
108
+ Normal ,
109
+ Ahead ,
110
+ Behind ,
111
+ }
112
+
113
+ public override void Render ( DrawingContext context )
114
+ {
115
+ if ( _status == Status . Normal )
116
+ return ;
117
+
118
+ context . DrawEllipse ( _status == Status . Ahead ? AheadBrush : BehindBrush , null , new Rect ( 0 , 0 , 5 , 5 ) ) ;
119
+ }
120
+
121
+ protected override Size MeasureOverride ( Size availableSize )
122
+ {
123
+ if ( DataContext is Models . Commit commit && CurrentBranch is not null )
124
+ {
125
+ var sha = commit . SHA ;
126
+ var track = CurrentBranch . TrackStatus ;
127
+
128
+ if ( track . Ahead . Contains ( sha ) )
129
+ _status = Status . Ahead ;
130
+ else if ( track . Behind . Contains ( sha ) )
131
+ _status = Status . Behind ;
132
+ else
133
+ _status = Status . Normal ;
134
+ }
135
+ else
136
+ {
137
+ _status = Status . Normal ;
138
+ }
139
+
140
+ return _status == Status . Normal ? new Size ( 0 , 0 ) : new Size ( 9 , 5 ) ;
141
+ }
142
+
143
+ protected override void OnDataContextChanged ( EventArgs e )
144
+ {
145
+ base . OnDataContextChanged ( e ) ;
146
+ InvalidateMeasure ( ) ;
147
+ }
148
+
149
+ protected override void OnPropertyChanged ( AvaloniaPropertyChangedEventArgs change )
150
+ {
151
+ base . OnPropertyChanged ( change ) ;
152
+ if ( change . Property == CurrentBranchProperty )
153
+ InvalidateMeasure ( ) ;
154
+ }
155
+
156
+ private Status _status = Status . Normal ;
157
+ }
158
+
77
159
public class CommitSubjectPresenter : TextBlock
78
160
{
79
161
public static readonly StyledProperty < string > SubjectProperty =
@@ -450,6 +532,15 @@ private void DrawCurves(DrawingContext context, double top, double bottom)
450
532
451
533
public partial class Histories : UserControl
452
534
{
535
+ public static readonly StyledProperty < Models . Branch > CurrentBranchProperty =
536
+ AvaloniaProperty . Register < Histories , Models . Branch > ( nameof ( CurrentBranch ) ) ;
537
+
538
+ public Models . Branch CurrentBranch
539
+ {
540
+ get => GetValue ( CurrentBranchProperty ) ;
541
+ set => SetValue ( CurrentBranchProperty , value ) ;
542
+ }
543
+
453
544
public static readonly StyledProperty < long > NavigationIdProperty =
454
545
AvaloniaProperty . Register < Histories , long > ( nameof ( NavigationId ) ) ;
455
546
0 commit comments