Skip to content

Commit ffc480c

Browse files
committed
Visual Studio 2012 gets its own set of "lighter" glyphs
1 parent b308da7 commit ffc480c

9 files changed

+215
-57
lines changed

BasicSccProvider.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
<DesignTime>True</DesignTime>
135135
<DependentUpon>Resources.resx</DependentUpon>
136136
</Compile>
137+
<Compile Include="SccGlyphsHelper.cs" />
137138
<Compile Include="SccOnIdleEvent.cs" />
138139
<Compile Include="SccProviderOptions.cs">
139140
<SubType>Component</SubType>
@@ -181,6 +182,7 @@
181182
</Content>
182183
<Content Include="Resources\Images_24bit.bmp" />
183184
<Content Include="Resources\Images_32bit.bmp" />
185+
<Content Include="Resources\SccGlyphs2012.png" />
184186
<Resource Include="Resources\Loading.png" />
185187
<Content Include="Resources\Images_32bit.png" />
186188
<Content Include="Resources\SccGlyphs.bmp" />

GitApi/GitFileStatus.cs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public enum GitFileStatus
1616
Added,
1717
Deleted,
1818
Conflict,
19+
Merged,
1920
Ignored,
2021
Renamed,
2122
Copied

GitSccOptions.cs

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
2+
using System.Diagnostics;
53
using System.IO;
64
using System.Xml.Serialization;
75
using Microsoft.VisualStudio.Shell;
@@ -31,6 +29,7 @@ public class GitSccOptions
3129

3230
private static GitSccOptions gitSccOptions;
3331

32+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
3433
public static GitSccOptions Current
3534
{
3635
get
@@ -43,6 +42,24 @@ public static GitSccOptions Current
4342
}
4443
}
4544

45+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
46+
public static bool IsVisualStudio2010
47+
{
48+
get
49+
{
50+
return !IsVisualStudio2012 && BasicSccProvider.GetGlobalService(typeof(SVsSolution)) is IVsSolution4;
51+
}
52+
}
53+
54+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
55+
public static bool IsVisualStudio2012
56+
{
57+
get
58+
{
59+
return BasicSccProvider.GetGlobalService(typeof(SVsDifferenceService)) != null;
60+
}
61+
}
62+
4663
private GitSccOptions()
4764
{
4865

Resources.Designer.cs

+11-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources.resx

+3
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,7 @@
148148
<data name="HistoryToolWindowCaption" xml:space="preserve">
149149
<value>Git History</value>
150150
</data>
151+
<data name="SccGlyphs2012" type="System.Resources.ResXFileRef, System.Windows.Forms">
152+
<value>resources\SccGlyphs2012.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
153+
</data>
151154
</root>

Resources/SccGlyphs2012.png

3 KB
Loading

SccGlyphsHelper.cs

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
namespace GitScc
2+
{
3+
using Color = System.Drawing.Color;
4+
using Image = System.Drawing.Image;
5+
using ImageList = System.Windows.Forms.ImageList;
6+
using Size = System.Drawing.Size;
7+
using VsStateIcon = Microsoft.VisualStudio.Shell.Interop.VsStateIcon;
8+
9+
internal static class SccGlyphsHelper
10+
{
11+
// Remember the base index where our custom scc glyph start
12+
private static uint _customSccGlyphBaseIndex = 0;
13+
14+
// Our custom image list
15+
private static ImageList _customSccGlyphsImageList;
16+
17+
// Indexes of icons in our custom image list
18+
private enum CustomSccGlyphs2010
19+
{
20+
Untracked = 0,
21+
Staged = 1,
22+
Modified = 2,
23+
Tracked = 3,
24+
};
25+
26+
// Indexes of icons in our custom image list
27+
private enum CustomSccGlyphs2012
28+
{
29+
New = 0,
30+
Staged = 1,
31+
Conflicted = 2,
32+
Merged = 3,
33+
};
34+
35+
public static VsStateIcon Tracked
36+
{
37+
get
38+
{
39+
if (GitSccOptions.IsVisualStudio2010 && GitSccOptions.Current.UseTGitIconSet)
40+
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2010.Tracked);
41+
42+
return VsStateIcon.STATEICON_CHECKEDIN;
43+
}
44+
}
45+
46+
public static VsStateIcon Modified
47+
{
48+
get
49+
{
50+
if (GitSccOptions.IsVisualStudio2010 && GitSccOptions.Current.UseTGitIconSet)
51+
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2010.Modified);
52+
53+
return VsStateIcon.STATEICON_CHECKEDOUT;
54+
}
55+
}
56+
57+
public static VsStateIcon New
58+
{
59+
get
60+
{
61+
if (GitSccOptions.IsVisualStudio2010)
62+
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2010.Untracked);
63+
64+
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2012.New);
65+
}
66+
}
67+
68+
public static VsStateIcon Added
69+
{
70+
get
71+
{
72+
return Staged;
73+
}
74+
}
75+
76+
public static VsStateIcon Staged
77+
{
78+
get
79+
{
80+
if (GitSccOptions.IsVisualStudio2010)
81+
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2010.Staged);
82+
83+
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2012.Staged);
84+
}
85+
}
86+
87+
public static VsStateIcon NotControlled
88+
{
89+
get
90+
{
91+
return VsStateIcon.STATEICON_NOSTATEICON;
92+
}
93+
}
94+
95+
public static VsStateIcon Ignored
96+
{
97+
get
98+
{
99+
return VsStateIcon.STATEICON_EXCLUDEDFROMSCC;
100+
}
101+
}
102+
103+
public static VsStateIcon Conflict
104+
{
105+
get
106+
{
107+
if (GitSccOptions.IsVisualStudio2010)
108+
return VsStateIcon.STATEICON_DISABLED;
109+
110+
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2012.Conflicted);
111+
}
112+
}
113+
114+
public static VsStateIcon Merged
115+
{
116+
get
117+
{
118+
if (GitSccOptions.IsVisualStudio2010)
119+
return Modified;
120+
121+
return (VsStateIcon)(_customSccGlyphBaseIndex + (uint)CustomSccGlyphs2012.Merged);
122+
}
123+
}
124+
125+
public static VsStateIcon Default
126+
{
127+
get
128+
{
129+
return VsStateIcon.STATEICON_NOSTATEICON;
130+
}
131+
}
132+
133+
public static uint GetCustomGlyphList(uint baseIndex)
134+
{
135+
// If this is the first time we got called, construct the image list, remember the index, etc
136+
if (_customSccGlyphsImageList == null)
137+
{
138+
// The shell calls this function when the provider becomes active to get our custom glyphs
139+
// and to tell us what's the first index we can use for our glyphs
140+
// Remember the index in the scc glyphs (VsStateIcon) where our custom glyphs will start
141+
_customSccGlyphBaseIndex = baseIndex;
142+
143+
// Create a new imagelist
144+
_customSccGlyphsImageList = new ImageList();
145+
146+
// Set the transparent color for the imagelist (the SccGlyphs.bmp uses magenta for background)
147+
_customSccGlyphsImageList.TransparentColor = Color.FromArgb(255, 0, 255);
148+
149+
// Set the corret imagelist size (7x16 pixels, otherwise the system will either stretch the image or fill in with black blocks)
150+
_customSccGlyphsImageList.ImageSize = new Size(7, 16);
151+
152+
// Add the custom scc glyphs we support to the list
153+
// NOTE: VS2005 and VS2008 are limited to 4 custom scc glyphs (let's hope this will change in future versions)
154+
Image sccGlyphs = GitSccOptions.IsVisualStudio2010 ? Resources.SccGlyphs : Resources.SccGlyphs2012;
155+
_customSccGlyphsImageList.Images.AddStrip(sccGlyphs);
156+
}
157+
158+
// 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)
159+
return (uint)_customSccGlyphsImageList.Handle;
160+
161+
}
162+
}
163+
}

SccProviderOptionsControl.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ private void SccProviderOptionsControl_Load(object sender, EventArgs e)
357357
this.checkBox1.Checked = GitSccOptions.Current.NotExpandGitExtensions;
358358
this.checkBox2.Checked = GitSccOptions.Current.NotExpandTortoiseGit;
359359
this.checkBox3.Checked = GitSccOptions.Current.UseTGitIconSet;
360+
this.checkBox3.Enabled = GitSccOptions.IsVisualStudio2010;
360361
this.checkBox4.Checked = GitSccOptions.Current.DisableAutoRefresh;
361362
this.checkBox5.Checked = GitSccOptions.Current.DisableAutoLoad;
362363
this.checkBox6.Checked = GitSccOptions.Current.NotUseUTF8FileNames;
@@ -402,7 +403,7 @@ internal void Save()
402403
GitSccOptions.Current.TortoiseGitPath = this.textBox4.Text;
403404
GitSccOptions.Current.NotExpandGitExtensions = this.checkBox1.Checked;
404405
GitSccOptions.Current.NotExpandTortoiseGit = this.checkBox2.Checked;
405-
GitSccOptions.Current.UseTGitIconSet = this.checkBox3.Checked;
406+
GitSccOptions.Current.UseTGitIconSet = GitSccOptions.IsVisualStudio2010 && this.checkBox3.Checked;
406407
GitSccOptions.Current.DisableAutoRefresh = this.checkBox4.Checked;
407408
GitSccOptions.Current.DisableAutoLoad = this.checkBox5.Checked;
408409
GitSccOptions.Current.NotUseUTF8FileNames = this.checkBox6.Checked;

SccProviderService.cs

+13-52
Original file line numberDiff line numberDiff line change
@@ -183,45 +183,46 @@ public int GetSccGlyph([InAttribute] int cFiles, [InAttribute] string[] rgpszFul
183183
switch (status)
184184
{
185185
case GitFileStatus.Tracked:
186-
rgsiGlyphs[i] = GitSccOptions.Current.UseTGitIconSet ?
187-
(VsStateIcon)(this._customSccGlyphBaseIndex + (uint)CustomSccGlyphs.Tracked) :
188-
VsStateIcon.STATEICON_CHECKEDIN;
186+
rgsiGlyphs[i] = SccGlyphsHelper.Tracked;
189187
sccStatus = __SccStatus.SCC_STATUS_CONTROLLED;
190188
break;
191189

192190
case GitFileStatus.Modified:
193-
rgsiGlyphs[i] = GitSccOptions.Current.UseTGitIconSet ?
194-
(VsStateIcon)(this._customSccGlyphBaseIndex + (uint)CustomSccGlyphs.Modified) :
195-
VsStateIcon.STATEICON_CHECKEDOUT;
191+
rgsiGlyphs[i] = SccGlyphsHelper.Modified;
196192
sccStatus = __SccStatus.SCC_STATUS_CONTROLLED | __SccStatus.SCC_STATUS_CHECKEDOUT | __SccStatus.SCC_STATUS_OUTBYUSER;
197193
break;
198194

199195
case GitFileStatus.New:
200-
rgsiGlyphs[i] = (VsStateIcon)(this._customSccGlyphBaseIndex + (uint)CustomSccGlyphs.Untracked);
196+
rgsiGlyphs[i] = SccGlyphsHelper.New;
201197
sccStatus = __SccStatus.SCC_STATUS_CONTROLLED | __SccStatus.SCC_STATUS_CHECKEDOUT | __SccStatus.SCC_STATUS_OUTBYUSER;
202198
break;
203199

204200
case GitFileStatus.Added:
205201
case GitFileStatus.Staged:
206-
rgsiGlyphs[i] = (VsStateIcon)(this._customSccGlyphBaseIndex + (uint)CustomSccGlyphs.Staged);
202+
rgsiGlyphs[i] = status == GitFileStatus.Added ? SccGlyphsHelper.Added : SccGlyphsHelper.Staged;
207203
sccStatus = __SccStatus.SCC_STATUS_CONTROLLED | __SccStatus.SCC_STATUS_CHECKEDOUT | __SccStatus.SCC_STATUS_OUTBYUSER;
208204
break;
209205

210206
case GitFileStatus.NotControlled:
211-
rgsiGlyphs[i] = VsStateIcon.STATEICON_NOSTATEICON;
207+
rgsiGlyphs[i] = SccGlyphsHelper.NotControlled;
212208
sccStatus = __SccStatus.SCC_STATUS_NOTCONTROLLED;
213209
break;
214210

215211
case GitFileStatus.Ignored:
216-
rgsiGlyphs[i] = VsStateIcon.STATEICON_EXCLUDEDFROMSCC;
212+
rgsiGlyphs[i] = SccGlyphsHelper.Ignored;
217213
sccStatus = __SccStatus.SCC_STATUS_NOTCONTROLLED;
218214
break;
219215

220216
case GitFileStatus.Conflict:
221-
rgsiGlyphs[i] = VsStateIcon.STATEICON_DISABLED;
217+
rgsiGlyphs[i] = SccGlyphsHelper.Conflict;
222218
sccStatus = __SccStatus.SCC_STATUS_CONTROLLED | __SccStatus.SCC_STATUS_CHECKEDOUT | __SccStatus.SCC_STATUS_OUTBYUSER | __SccStatus.SCC_STATUS_MERGED;
223219
break;
224220

221+
case GitFileStatus.Merged:
222+
rgsiGlyphs[i] = SccGlyphsHelper.Merged;
223+
sccStatus = __SccStatus.SCC_STATUS_CONTROLLED | __SccStatus.SCC_STATUS_CHECKEDOUT | __SccStatus.SCC_STATUS_OUTBYUSER;
224+
break;
225+
225226
default:
226227
sccStatus = __SccStatus.SCC_STATUS_INVALID;
227228
break;
@@ -361,50 +362,10 @@ public int OnAfterMergeSolution([InAttribute] Object pUnkReserved)
361362

362363
#region IVsSccGlyphs Members
363364

364-
// Remember the base index where our custom scc glyph start
365-
private uint _customSccGlyphBaseIndex = 0;
366-
// Our custom image list
367-
ImageList _customSccGlyphsImageList;
368-
// Indexes of icons in our custom image list
369-
enum CustomSccGlyphs
370-
{
371-
Untracked = 0,
372-
Staged = 1,
373-
Modified = 2,
374-
Tracked = 3,
375-
};
376-
377365
public int GetCustomGlyphList(uint BaseIndex, out uint pdwImageListHandle)
378366
{
379-
// If this is the first time we got called, construct the image list, remember the index, etc
380-
if (this._customSccGlyphsImageList == null)
381-
{
382-
// The shell calls this function when the provider becomes active to get our custom glyphs
383-
// and to tell us what's the first index we can use for our glyphs
384-
// Remember the index in the scc glyphs (VsStateIcon) where our custom glyphs will start
385-
this._customSccGlyphBaseIndex = BaseIndex;
386-
387-
// Create a new imagelist
388-
this._customSccGlyphsImageList = new ImageList();
389-
390-
// Set the transparent color for the imagelist (the SccGlyphs.bmp uses magenta for background)
391-
this._customSccGlyphsImageList.TransparentColor = Color.FromArgb(255, 0, 255);
392-
393-
// Set the corret imagelist size (7x16 pixels, otherwise the system will either stretch the image or fill in with black blocks)
394-
this._customSccGlyphsImageList.ImageSize = new Size(7, 16);
395-
396-
// Add the custom scc glyphs we support to the list
397-
// NOTE: VS2005 and VS2008 are limited to 4 custom scc glyphs (let's hope this will change in future versions)
398-
Image sccGlyphs = (Image)Resources.SccGlyphs;
399-
this._customSccGlyphsImageList.Images.AddStrip(sccGlyphs);
400-
}
401-
402-
// 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)
403-
pdwImageListHandle = (uint)this._customSccGlyphsImageList.Handle;
404-
405-
// Return success (If you don't want to have custom glyphs return VSConstants.E_NOTIMPL)
367+
pdwImageListHandle = SccGlyphsHelper.GetCustomGlyphList(BaseIndex);
406368
return VSConstants.S_OK;
407-
408369
}
409370

410371
#endregion

0 commit comments

Comments
 (0)