21 using System.Collections.Generic;
23 using Microsoft.VisualStudio;
24 using Microsoft.VisualStudio.Shell.Interop;
25 using Microsoft.Win32;
27 namespace SiliconStudio.
Paradox.VisualStudio.Classifiers
31 private const uint WM_SYSCOLORCHANGE = 0x0015;
33 private readonly DTE2 dte;
34 private readonly IVsShell shellService;
35 private uint broadcastCookie;
37 private readonly Dictionary<Guid, VisualStudioTheme> availableThemes =
new Dictionary<Guid, VisualStudioTheme>
39 {
new Guid(
"DE3DBBCD-F642-433C-8353-8F1DF4370ABA"), VisualStudioTheme.Light },
40 {
new Guid(
"A4D6A176-B948-4B29-8C66-53C97A1ED7D0"), VisualStudioTheme.Blue },
41 {
new Guid(
"1DED0138-47CE-435E-84EF-9EC1F439B749"), VisualStudioTheme.Dark }
44 public event EventHandler OnThemeChanged;
46 public VisualStudioThemeEngine(IServiceProvider serviceProvider)
48 dte = (DTE2)serviceProvider.GetService(typeof(SDTE));
51 shellService = serviceProvider.GetService(typeof(SVsShell)) as IVsShell;
52 if (shellService != null)
53 ErrorHandler.ThrowOnFailure(shellService.AdviseBroadcastMessages(
this, out broadcastCookie));
58 if (shellService != null && broadcastCookie != 0)
60 shellService.UnadviseBroadcastMessages(broadcastCookie);
67 var currentUser32 = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32);
68 using (var subkey = currentUser32.OpenSubKey(string.Format(
@"{0}\General", dte.RegistryRoot)))
71 return VisualStudioTheme.Unknown;
73 var themeValue = (string)subkey.GetValue(
"CurrentTheme");
74 if (themeValue == null)
75 return VisualStudioTheme.Unknown;
78 if (!Guid.TryParse(themeValue, out themeGuid))
82 availableThemes.TryGetValue(themeGuid, out theme);
88 public int OnBroadcastMessage(uint msg, IntPtr wParam, IntPtr lParam)
90 if (msg == WM_SYSCOLORCHANGE)
92 if (OnThemeChanged != null)
97 return VSConstants.S_OK;