1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Globalization ;
3
-
4
4
using Avalonia ;
5
5
using Avalonia . Controls ;
6
6
using Avalonia . Media ;
@@ -9,55 +9,86 @@ namespace SourceGit.Views
9
9
{
10
10
public class ChangeStatusIcon : Control
11
11
{
12
- private static readonly IBrush [ ] BACKGROUNDS = [
13
- Brushes . Transparent ,
14
- new LinearGradientBrush
15
- {
16
- GradientStops = new GradientStops ( ) { new GradientStop ( Color . FromRgb ( 238 , 160 , 14 ) , 0 ) , new GradientStop ( Color . FromRgb ( 228 , 172 , 67 ) , 1 ) } ,
17
- StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
18
- EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
12
+ private static readonly Dictionary < Models . ChangeState , IBrush > BACKGROUNDS = new Dictionary < Models . ChangeState , IBrush > ( )
13
+ {
14
+ { Models . ChangeState . None , Brushes . Transparent } ,
15
+ { Models . ChangeState . Modified , new LinearGradientBrush
16
+ {
17
+ GradientStops = new GradientStops ( ) { new GradientStop ( Color . FromRgb ( 238 , 160 , 14 ) , 0 ) , new GradientStop ( Color . FromRgb ( 228 , 172 , 67 ) , 1 ) } ,
18
+ StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
19
+ EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
20
+ }
19
21
} ,
20
- new LinearGradientBrush
21
- {
22
- GradientStops = new GradientStops ( ) { new GradientStop ( Color . FromRgb ( 238 , 160 , 14 ) , 0 ) , new GradientStop ( Color . FromRgb ( 228 , 172 , 67 ) , 1 ) } ,
23
- StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
24
- EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
22
+ { Models . ChangeState . TypeChanged , new LinearGradientBrush
23
+ {
24
+ GradientStops = new GradientStops ( ) { new GradientStop ( Color . FromRgb ( 238 , 160 , 14 ) , 0 ) , new GradientStop ( Color . FromRgb ( 228 , 172 , 67 ) , 1 ) } ,
25
+ StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
26
+ EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
27
+ }
25
28
} ,
26
- new LinearGradientBrush
27
- {
28
- GradientStops = new GradientStops ( ) { new GradientStop ( Color . FromRgb ( 47 , 185 , 47 ) , 0 ) , new GradientStop ( Color . FromRgb ( 75 , 189 , 75 ) , 1 ) } ,
29
- StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
30
- EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
29
+ { Models . ChangeState . Added , new LinearGradientBrush
30
+ {
31
+ GradientStops = new GradientStops ( ) { new GradientStop ( Color . FromRgb ( 47 , 185 , 47 ) , 0 ) , new GradientStop ( Color . FromRgb ( 75 , 189 , 75 ) , 1 ) } ,
32
+ StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
33
+ EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
34
+ }
31
35
} ,
32
- new LinearGradientBrush
33
- {
34
- GradientStops = new GradientStops ( ) { new GradientStop ( Colors . Tomato , 0 ) , new GradientStop ( Color . FromRgb ( 252 , 165 , 150 ) , 1 ) } ,
35
- StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
36
- EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
36
+ { Models . ChangeState . Deleted , new LinearGradientBrush
37
+ {
38
+ GradientStops = new GradientStops ( ) { new GradientStop ( Colors . Tomato , 0 ) , new GradientStop ( Color . FromRgb ( 252 , 165 , 150 ) , 1 ) } ,
39
+ StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
40
+ EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
41
+ }
37
42
} ,
38
- new LinearGradientBrush
39
- {
40
- GradientStops = new GradientStops ( ) { new GradientStop ( Colors . Orchid , 0 ) , new GradientStop ( Color . FromRgb ( 248 , 161 , 245 ) , 1 ) } ,
41
- StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
42
- EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
43
+ { Models . ChangeState . Renamed , new LinearGradientBrush
44
+ {
45
+ GradientStops = new GradientStops ( ) { new GradientStop ( Colors . Orchid , 0 ) , new GradientStop ( Color . FromRgb ( 248 , 161 , 245 ) , 1 ) } ,
46
+ StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
47
+ EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
48
+ }
43
49
} ,
44
- new LinearGradientBrush
45
- {
46
- GradientStops = new GradientStops ( ) { new GradientStop ( Color . FromRgb ( 238 , 160 , 14 ) , 0 ) , new GradientStop ( Color . FromRgb ( 228 , 172 , 67 ) , 1 ) } ,
47
- StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
48
- EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
50
+ { Models . ChangeState . Copied , new LinearGradientBrush
51
+ {
52
+ GradientStops = new GradientStops ( ) { new GradientStop ( Color . FromRgb ( 238 , 160 , 14 ) , 0 ) , new GradientStop ( Color . FromRgb ( 228 , 172 , 67 ) , 1 ) } ,
53
+ StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
54
+ EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
55
+ }
49
56
} ,
50
- new LinearGradientBrush
51
- {
52
- GradientStops = new GradientStops ( ) { new GradientStop ( Color . FromRgb ( 47 , 185 , 47 ) , 0 ) , new GradientStop ( Color . FromRgb ( 75 , 189 , 75 ) , 1 ) } ,
53
- StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
54
- EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
57
+ { Models . ChangeState . Untracked , new LinearGradientBrush
58
+ {
59
+ GradientStops = new GradientStops ( ) { new GradientStop ( Color . FromRgb ( 47 , 185 , 47 ) , 0 ) , new GradientStop ( Color . FromRgb ( 75 , 189 , 75 ) , 1 ) } ,
60
+ StartPoint = new RelativePoint ( 0 , 0 , RelativeUnit . Relative ) ,
61
+ EndPoint = new RelativePoint ( 0 , 1 , RelativeUnit . Relative ) ,
62
+ }
55
63
} ,
56
- Brushes . OrangeRed ,
57
- ] ;
64
+ { Models . ChangeState . Conflicted , Brushes . OrangeRed } ,
65
+ } ;
58
66
59
- private static readonly string [ ] INDICATOR = [ "?" , "±" , "T" , "+" , "−" , "➜" , "❏" , "★" , "!" ] ;
60
- private static readonly string [ ] TIPS = [ "Unknown" , "Modified" , "Type Changed" , "Added" , "Deleted" , "Renamed" , "Copied" , "Untracked" , "Conflict" ] ;
67
+ private static readonly Dictionary < Models . ChangeState , string > INDICATOR = new Dictionary < Models . ChangeState , string > ( )
68
+ {
69
+ { Models . ChangeState . None , "?" } ,
70
+ { Models . ChangeState . Modified , "±" } ,
71
+ { Models . ChangeState . TypeChanged , "T" } ,
72
+ { Models . ChangeState . Added , "+" } ,
73
+ { Models . ChangeState . Deleted , "−" } ,
74
+ { Models . ChangeState . Renamed , "➜" } ,
75
+ { Models . ChangeState . Copied , "❏" } ,
76
+ { Models . ChangeState . Untracked , "★" } ,
77
+ { Models . ChangeState . Conflicted , "!" }
78
+ } ;
79
+
80
+ private static readonly Dictionary < Models . ChangeState , string > TIPS = new Dictionary < Models . ChangeState , string > ( )
81
+ {
82
+ { Models . ChangeState . None , "Unknown" } ,
83
+ { Models . ChangeState . Modified , "Modified" } ,
84
+ { Models . ChangeState . TypeChanged , "Type Changed" } ,
85
+ { Models . ChangeState . Added , "Added" } ,
86
+ { Models . ChangeState . Deleted , "Deleted" } ,
87
+ { Models . ChangeState . Renamed , "Renamed" } ,
88
+ { Models . ChangeState . Copied , "Copied" } ,
89
+ { Models . ChangeState . Untracked , "Untracked" } ,
90
+ { Models . ChangeState . Conflicted , "Conflict" }
91
+ } ;
61
92
62
93
public static readonly StyledProperty < bool > IsUnstagedChangeProperty =
63
94
AvaloniaProperty . Register < ChangeStatusIcon , bool > ( nameof ( IsUnstagedChange ) ) ;
@@ -88,13 +119,15 @@ public override void Render(DrawingContext context)
88
119
string indicator ;
89
120
if ( IsUnstagedChange )
90
121
{
91
- background = BACKGROUNDS [ ( int ) Change . WorkTree ] ;
92
- indicator = INDICATOR [ ( int ) Change . WorkTree ] ;
122
+ var status = Models . Change . GetPrimaryState ( Change . WorkTree ) ;
123
+ background = BACKGROUNDS [ status ] ;
124
+ indicator = INDICATOR [ status ] ;
93
125
}
94
126
else
95
127
{
96
- background = BACKGROUNDS [ ( int ) Change . Index ] ;
97
- indicator = INDICATOR [ ( int ) Change . Index ] ;
128
+ var status = Models . Change . GetPrimaryState ( Change . Index ) ;
129
+ background = BACKGROUNDS [ status ] ;
130
+ indicator = INDICATOR [ status ] ;
98
131
}
99
132
100
133
var txt = new FormattedText (
@@ -125,11 +158,11 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
125
158
return ;
126
159
}
127
160
128
- if ( isUnstaged )
129
- ToolTip . SetTip ( this , TIPS [ ( int ) c . WorkTree ] ) ;
130
- else
131
- ToolTip . SetTip ( this , TIPS [ ( int ) c . Index ] ) ;
161
+ var status = isUnstaged ?
162
+ Models . Change . GetPrimaryState ( c . WorkTree ) :
163
+ Models . Change . GetPrimaryState ( c . Index ) ;
132
164
165
+ ToolTip . SetTip ( this , TIPS [ status ] ) ;
133
166
InvalidateVisual ( ) ;
134
167
}
135
168
}
0 commit comments