-
Notifications
You must be signed in to change notification settings - Fork 107
/
SccGlyphsHelper.cs
195 lines (163 loc) · 6.2 KB
/
SccGlyphsHelper.cs
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
namespace GitScc
{
using Color = System.Drawing.Color;
using Image = System.Drawing.Image;
using ImageList = System.Windows.Forms.ImageList;
using Size = System.Drawing.Size;
using VsStateIcon = Microsoft.VisualStudio.Shell.Interop.VsStateIcon;
internal static class SccGlyphsHelper
{
// Remember the base index where our custom scc glyph start
private static uint _customSccGlyphBaseIndex = 0;
// Our custom image list
private static ImageList _customSccGlyphsImageList;
private static bool? _usingVisualStudio2010Icons;
// Indexes of icons in our custom image list
private enum CustomSccGlyphs2010
{
Untracked = 0,
Staged = 1,
Modified = 2,
Tracked = 3,
};
// Indexes of icons in our custom image list
private enum CustomSccGlyphs2012
{
New = 0,
Staged = 1,
Conflicted = 2,
Merged = 3,
};
public static VsStateIcon Tracked
{
get
{
if (UsingTortoiseGitIcons)
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2010.Tracked);
return VsStateIcon.STATEICON_CHECKEDIN;
}
}
public static VsStateIcon Modified
{
get
{
if (UsingTortoiseGitIcons)
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2010.Modified);
return VsStateIcon.STATEICON_CHECKEDOUT;
}
}
public static VsStateIcon New
{
get
{
if (UsingVisualStudio2010Icons)
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2010.Untracked);
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2012.New);
}
}
public static VsStateIcon Added
{
get
{
return Staged;
}
}
public static VsStateIcon Staged
{
get
{
if (UsingVisualStudio2010Icons)
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2010.Staged);
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2012.Staged);
}
}
public static VsStateIcon NotControlled
{
get
{
return VsStateIcon.STATEICON_NOSTATEICON;
}
}
public static VsStateIcon Ignored
{
get
{
return VsStateIcon.STATEICON_EXCLUDEDFROMSCC;
}
}
public static VsStateIcon Conflict
{
get
{
if (UsingVisualStudio2010Icons)
return VsStateIcon.STATEICON_DISABLED;
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2012.Conflicted);
}
}
public static VsStateIcon Merged
{
get
{
if (UsingVisualStudio2010Icons)
return Modified;
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2012.Merged);
}
}
public static VsStateIcon Default
{
get
{
return VsStateIcon.STATEICON_NOSTATEICON;
}
}
private static bool UsingVisualStudio2010Icons
{
get
{
if (!_usingVisualStudio2010Icons.HasValue)
{
if (GitSccOptions.IsVisualStudio2010)
_usingVisualStudio2010Icons = true;
else
_usingVisualStudio2010Icons = GitSccOptions.Current.UseTGitIconSet;
}
return _usingVisualStudio2010Icons.Value;
}
}
private static bool UsingTortoiseGitIcons
{
get
{
if (!UsingVisualStudio2010Icons)
return false;
// only reason to use the 2010 icons in 2012 is if we are using tortoise icons
if (GitSccOptions.IsVisualStudio2012)
return true;
return GitSccOptions.Current.UseTGitIconSet;
}
}
public static uint GetCustomGlyphList(uint baseIndex)
{
// If this is the first time we got called, construct the image list, remember the index, etc
if (_customSccGlyphsImageList == null)
{
// The shell calls this function when the provider becomes active to get our custom glyphs
// and to tell us what's the first index we can use for our glyphs
// Remember the index in the scc glyphs (VsStateIcon) where our custom glyphs will start
_customSccGlyphBaseIndex = baseIndex;
// Create a new imagelist
_customSccGlyphsImageList = new ImageList();
// Set the transparent color for the imagelist (the SccGlyphs.bmp uses magenta for background)
_customSccGlyphsImageList.TransparentColor = Color.FromArgb(255, 0, 255);
// Set the corret imagelist size (7x16 pixels, otherwise the system will either stretch the image or fill in with black blocks)
_customSccGlyphsImageList.ImageSize = new Size(7, 16);
// Add the custom scc glyphs we support to the list
// NOTE: VS2005 and VS2008 are limited to 4 custom scc glyphs (let's hope this will change in future versions)
Image sccGlyphs = UsingVisualStudio2010Icons ? Resources.SccGlyphs : Resources.SccGlyphs2012;
_customSccGlyphsImageList.Images.AddStrip(sccGlyphs);
}
// Return a Win32 HIMAGELIST handle to our imagelist to the shell (by keeping the ImageList a member of the class we guarantee the Win32 object is still valid when the shell needs it)
return (uint)_customSccGlyphsImageList.Handle;
}
}
}