forked from menees/Libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffOptions.cs
More file actions
227 lines (188 loc) · 4.19 KB
/
DiffOptions.cs
File metadata and controls
227 lines (188 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
namespace Menees.Diffs.Windows.Forms
{
#region Using Directives
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using Menees.Windows.Forms;
#endregion
public static class DiffOptions
{
#region Public Fields
// I originally used PaleGreen, but it was too close to PaleTurquoise when I added intra-line diffs.
public static readonly Color DefaultChangedColor = Color.FromArgb(200, 255, 200);
public static readonly Color DefaultDeletedColor = Color.Pink;
public static readonly Color DefaultInsertedColor = Color.PaleTurquoise;
#endregion
#region Private Data Members
private const int DefaultSpacesPerTab = 4;
private static bool changed;
private static bool hatchDeadSpace;
private static Color changedColor = DefaultChangedColor;
private static Color deletedColor = DefaultDeletedColor;
private static Color insertedColor = DefaultInsertedColor;
private static int spacesPerTab = DefaultSpacesPerTab;
private static int updateLevel;
#endregion
#region Public Events
public static event EventHandler OptionsChanged;
#endregion
#region Public Properties
public static Color ChangedColor
{
get
{
return changedColor;
}
set
{
if (changedColor != value)
{
BeginUpdate();
changedColor = value;
changed = true;
EndUpdate();
}
}
}
public static Color DeletedColor
{
get
{
return deletedColor;
}
set
{
if (deletedColor != value)
{
BeginUpdate();
deletedColor = value;
changed = true;
EndUpdate();
}
}
}
public static bool HatchDeadSpace
{
get
{
return hatchDeadSpace;
}
set
{
if (hatchDeadSpace != value)
{
BeginUpdate();
hatchDeadSpace = value;
changed = true;
EndUpdate();
}
}
}
public static Color InsertedColor
{
get
{
return insertedColor;
}
set
{
if (insertedColor != value)
{
BeginUpdate();
insertedColor = value;
changed = true;
EndUpdate();
}
}
}
public static int SpacesPerTab
{
get
{
return spacesPerTab;
}
set
{
if (spacesPerTab != value)
{
BeginUpdate();
spacesPerTab = value;
changed = true;
EndUpdate();
}
}
}
#endregion
#region Public Methods
public static void BeginUpdate()
{
updateLevel++;
}
public static void EndUpdate()
{
updateLevel--;
if (updateLevel == 0 && changed)
{
changed = false;
OptionsChanged?.Invoke(null, EventArgs.Empty);
}
}
public static Color GetColorForEditType(EditType editType)
{
Color result;
switch (editType)
{
case EditType.Change:
result = ChangedColor;
break;
case EditType.Insert:
result = InsertedColor;
break;
case EditType.Delete:
result = DeletedColor;
break;
default:
Debug.Assert(false, "An invalid EditType was passed in.");
result = Color.Transparent;
break;
}
return result;
}
public static void Load(ISettingsNode node)
{
BeginUpdate();
try
{
InsertedColor = Color.FromArgb(node.GetValue(nameof(InsertedColor), DefaultInsertedColor.ToArgb()));
DeletedColor = Color.FromArgb(node.GetValue(nameof(DeletedColor), DefaultDeletedColor.ToArgb()));
ChangedColor = Color.FromArgb(node.GetValue(nameof(ChangedColor), DefaultChangedColor.ToArgb()));
SpacesPerTab = Math.Max(1, node.GetValue(nameof(SpacesPerTab), DefaultSpacesPerTab));
HatchDeadSpace = node.GetValue(nameof(HatchDeadSpace), hatchDeadSpace);
}
finally
{
EndUpdate();
}
}
public static void Save(ISettingsNode node)
{
node.SetValue(nameof(InsertedColor), InsertedColor.ToArgb());
node.SetValue(nameof(DeletedColor), DeletedColor.ToArgb());
node.SetValue(nameof(ChangedColor), ChangedColor.ToArgb());
node.SetValue(nameof(SpacesPerTab), SpacesPerTab);
node.SetValue(nameof(HatchDeadSpace), HatchDeadSpace);
}
public static Brush TryCreateDeadSpaceBrush(Color backColor)
{
Brush result = null;
if (HatchDeadSpace)
{
result = new HatchBrush(HatchStyle.Percent25, SystemColors.ControlDark, backColor);
}
return result;
}
#endregion
}
}