Skip to content

Commit c569257

Browse files
Added Shell events
/cc #63
1 parent 2ffce92 commit c569257

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/Community.VisualStudio.Toolkit.Shared/Events/Events.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ internal Events()
5050
/// </summary>
5151
public DocumentEvents DocumentEvents => new();
5252

53+
/// <summary>
54+
/// Events related to the Visual Studio Shell.
55+
/// </summary>
56+
public ShellEvents ShellEvents => new();
57+
5358

5459
private DTEEvents? _dteEvents;
5560
public DTEEvents? DTEEvents => _dteEvents ??= _events?.DTEEvents;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using Microsoft;
3+
using Microsoft.VisualStudio;
4+
using Microsoft.VisualStudio.Shell;
5+
using Microsoft.VisualStudio.Shell.Interop;
6+
7+
namespace Community.VisualStudio.Toolkit
8+
{
9+
/// <summary>
10+
/// Events related to the Visual Studio Shell.
11+
/// </summary>
12+
public class ShellEvents : IVsShellPropertyEvents, IVsBroadcastMessageEvents
13+
{
14+
private const uint _wM_SYSCOLORCHANGE = 0x0015;
15+
16+
internal ShellEvents()
17+
{
18+
ThreadHelper.ThrowIfNotOnUIThread();
19+
var svc = (IVsShell)ServiceProvider.GlobalProvider.GetService(typeof(SVsShell));
20+
Assumes.Present(svc);
21+
svc.AdviseShellPropertyChanges(this, out _);
22+
svc.AdviseBroadcastMessages(this, out _);
23+
}
24+
25+
/// <summary>
26+
/// When Visual Studio enters into an interactive state.
27+
/// </summary>
28+
public event Action? ShellAvailable;
29+
30+
/// <summary>
31+
/// When Visual Studio enters into an interactive state.
32+
/// </summary>
33+
public event Action? EnvironmentColorChanged;
34+
35+
int IVsShellPropertyEvents.OnShellPropertyChange(int propid, object var)
36+
{
37+
if (propid == (int)__VSSPROPID.VSSPROPID_Zombie || propid == (int)__VSSPROPID4.VSSPROPID_ShellInitialized)
38+
{
39+
if (!(bool)var)
40+
{
41+
ShellAvailable?.Invoke();
42+
}
43+
}
44+
45+
return VSConstants.S_OK;
46+
}
47+
48+
int IVsBroadcastMessageEvents.OnBroadcastMessage(uint msg, IntPtr wParam, IntPtr lParam)
49+
{
50+
if (msg == _wM_SYSCOLORCHANGE)
51+
{
52+
EnvironmentColorChanged?.Invoke();
53+
}
54+
55+
return VSConstants.S_OK;
56+
}
57+
}
58+
}

src/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<Compile Include="$(MSBuildThisFileDirectory)Commands\CommandAttribute.cs" />
1313
<Compile Include="$(MSBuildThisFileDirectory)Editor\WpfTextViewCreationListener.cs" />
1414
<Compile Include="$(MSBuildThisFileDirectory)Events\BuildEvents.cs" />
15+
<Compile Include="$(MSBuildThisFileDirectory)Events\ShellEvents.cs" />
1516
<Compile Include="$(MSBuildThisFileDirectory)Events\DebuggerEvents.cs" />
1617
<Compile Include="$(MSBuildThisFileDirectory)Events\SelectionEvents.cs" />
1718
<Compile Include="$(MSBuildThisFileDirectory)Events\SolutionEvents.cs" />

0 commit comments

Comments
 (0)