The full project can be found at: http://vscoloroutput.codeplex.com.
I use the following code to register and respond to color change events in the Fonts and Colors dialog of Visual Studio. This code works in VS 2010 and not in VS 11 Beta
namespace BlueOnionSoftware
{
public class TextManagerEvents : IVsTextManagerEvents
{
private Guid _guidColorService = Guid.Empty;
public static IVsTextManager2 Override;
private static IVsTextManager2 GetService()
{
return Override ?? ServiceProvider.GlobalProvider.GetService(typeof(SVsTextManager)) as IVsTextManager2;
}
public static void RegisterForTextManagerEvents()
{
var textManager = GetService();
var container = textManager as IConnectionPointContainer;
IConnectionPoint textManagerEventsConnection;
var eventGuid = typeof(IVsTextManagerEvents).GUID;
container.FindConnectionPoint(ref eventGuid, out textManagerEventsConnection);
var textManagerEvents = new TextManagerEvents();
uint textManagerCookie;
textManagerEventsConnection.Advise(textManagerEvents, out textManagerCookie);
}
public void OnRegisterMarkerType(int iMarkerType)
{
}
public void OnRegisterView(IVsTextView pView)
{
}
public void OnUnregisterView(IVsTextView pView)
{
}
public void OnUserPreferencesChanged(
VIEWPREFERENCES[] pViewPrefs,
FRAMEPREFERENCES[] pFramePrefs,
LANGPREFERENCES[] pLangPrefs,
FONTCOLORPREFERENCES[] pColorPrefs)
{
if (pColorPrefs != null && pColorPrefs.Length > 0 && pColorPrefs[0].pColorTable != null)
{
var guidFontCategory = (Guid)Marshal.PtrToStructure(pColorPrefs[0].pguidFontCategory, typeof(Guid));
var guidColorService = (Guid)Marshal.PtrToStructure(pColorPrefs[0].pguidColorService, typeof(Guid));
if (_guidColorService == Guid.Empty)
{
_guidColorService = guidColorService;
}
if (guidFontCategory == DefGuidList.guidTextEditorFontCategory && _guidColorService == guidColorService)
{
FontAndColorStorage.UpdateColors();
}
}
}
}
}I logged the issue with VS 11 here. The response is odd on two counts.
- The response suggests that the OnUserPrefrencesChanged method is called. In my debugging sessions, this method is never called. To be clear, a break point on the first line of OnUserPreferencesChanged is never hit.
- The part about the GUID makes even less sense. The GUID listed doesn't exist.
I asked for clarification but never received a response.
Could someone please look at this issue and help me understand the response I've received? I'm having difficulty believing this behavior is by design.