-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
WindowEvents.cs
124 lines (105 loc) · 3.96 KB
/
WindowEvents.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
using System;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
namespace Community.VisualStudio.Toolkit
{
public partial class Events
{
private WindowEvents? _windowEvents;
/// <summary>
/// Events related to the window frames.
/// </summary>
public WindowEvents WindowEvents => _windowEvents ??= new();
}
/// <summary>
/// Events related to the window frames.
/// </summary>
public class WindowEvents : IVsWindowFrameEvents
{
internal WindowEvents()
{
ThreadHelper.ThrowIfNotOnUIThread();
IVsUIShell7 svc = VS.GetRequiredService<SVsUIShell, IVsUIShell7>();
svc.AdviseWindowFrameEvents(this);
}
/// <summary>
/// Fires when a window frame is created
/// </summary>
public event Action<WindowFrame>? Created;
/// <summary>
/// Fires when a window frame is destroyed.
/// </summary>
public event Action<WindowFrame>? Destroyed;
/// <summary>
/// Fires when a changes happens to a frame's visibility.
/// </summary>
public event Action<FrameVisibilityEventArgs>? FrameIsVisibleChanged;
/// <summary>
/// Fires when a changes happens to a frames location on the screen.
/// </summary>
public event Action<FrameOnScreenEventArgs>? FrameIsOnScreenChanged;
/// <summary>
/// Fires when the active frame changes.
/// </summary>
public event Action<ActiveFrameChangeEventArgs>? ActiveFrameChanged;
void IVsWindowFrameEvents.OnFrameCreated(IVsWindowFrame frame)
{
Created?.Invoke(new WindowFrame(frame));
}
void IVsWindowFrameEvents.OnFrameDestroyed(IVsWindowFrame frame)
{
Destroyed?.Invoke(new WindowFrame(frame));
}
void IVsWindowFrameEvents.OnFrameIsVisibleChanged(IVsWindowFrame frame, bool newIsVisible)
{
FrameIsVisibleChanged?.Invoke(new FrameVisibilityEventArgs(frame, newIsVisible));
}
void IVsWindowFrameEvents.OnFrameIsOnScreenChanged(IVsWindowFrame frame, bool newIsOnScreen)
{
FrameIsOnScreenChanged?.Invoke(new FrameOnScreenEventArgs(frame, newIsOnScreen));
}
void IVsWindowFrameEvents.OnActiveFrameChanged(IVsWindowFrame oldFrame, IVsWindowFrame newFrame)
{
ActiveFrameChanged?.Invoke(new ActiveFrameChangeEventArgs(oldFrame, newFrame));
}
}
/// <inheritdoc/>
public class FrameVisibilityEventArgs : EventArgs
{
internal FrameVisibilityEventArgs(IVsWindowFrame frame, bool isNewVisible)
{
Frame = frame;
IsNewVisible = isNewVisible;
}
/// <summary>The Window frame object.</summary>
public IVsWindowFrame Frame { get; }
/// <summary>A value indicating if the new frame is visible.</summary>
public bool IsNewVisible { get; }
}
/// <inheritdoc/>
public class FrameOnScreenEventArgs : EventArgs
{
internal FrameOnScreenEventArgs(IVsWindowFrame frame, bool isOnScreen)
{
Frame = new WindowFrame(frame);
IsOnScreen = isOnScreen;
}
/// <summary>The Window frame object.</summary>
public WindowFrame Frame { get; }
/// <summary>A value indicating if the frame is on screen.</summary>
public bool IsOnScreen { get; }
}
/// <inheritdoc/>
public class ActiveFrameChangeEventArgs : EventArgs
{
internal ActiveFrameChangeEventArgs(IVsWindowFrame oldFrame, IVsWindowFrame newFrame)
{
OldFrame = new WindowFrame(oldFrame);
NewFrame = new WindowFrame(newFrame);
}
/// <summary>The frame that lost its active state.</summary>
public WindowFrame OldFrame { get; }
/// <summary>The frame became active.</summary>
public WindowFrame NewFrame { get; }
}
}