Skip to content

Commit e01ea34

Browse files
committed
actually registered IConnectionPoint for references sink
1 parent 398ab3e commit e01ea34

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

RetailCoder.VBE/App.cs

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ public class App : IDisposable
4141
private readonly IConnectionPoint _projectsEventsConnectionPoint;
4242
private readonly int _projectsEventsCookie;
4343

44-
private readonly IDictionary<VBComponents, Tuple<IConnectionPoint, int>> _componentsEventsConnectionPoints =
45-
new Dictionary<VBComponents, Tuple<IConnectionPoint, int>>();
44+
private readonly IDictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>> _componentsEventsConnectionPoints =
45+
new Dictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>>();
46+
private readonly IDictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>> _referencesEventsConnectionPoints =
47+
new Dictionary<VBProjectsEventsSink, Tuple<IConnectionPoint, int>>();
4648

4749
private readonly IDictionary<Type, Action> _hookActions;
4850

@@ -159,14 +161,21 @@ async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
159161
_parser.State.RemoveProject(e.Item);
160162

161163
Debug.WriteLine(string.Format("Project '{0}' was removed.", e.Item.Name));
162-
Tuple<IConnectionPoint, int> value;
163-
if (_componentsEventsConnectionPoints.TryGetValue(e.Item.VBComponents, out value))
164+
Tuple<IConnectionPoint, int> componentsTuple;
165+
if (_componentsEventsConnectionPoints.TryGetValue(sink, out componentsTuple))
164166
{
165-
value.Item1.Unadvise(value.Item2);
166-
_componentsEventsConnectionPoints.Remove(e.Item.VBComponents);
167+
componentsTuple.Item1.Unadvise(componentsTuple.Item2);
168+
_componentsEventsConnectionPoints.Remove(sink);
169+
}
167170

168-
_parser.State.ClearDeclarations(e.Item);
171+
Tuple<IConnectionPoint, int> referencesTuple;
172+
if (_referencesEventsConnectionPoints.TryGetValue(sink, out referencesTuple))
173+
{
174+
referencesTuple.Item1.Unadvise(referencesTuple.Item2);
175+
_referencesEventsConnectionPoints.Remove(sink);
169176
}
177+
178+
_parser.State.ClearDeclarations(e.Item);
170179
}
171180

172181
private readonly IDictionary<VBProjectsEventsSink, VBComponentsEventsSink> _componentsEventSinks =
@@ -189,9 +198,17 @@ async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
189198
}
190199

191200
Debug.WriteLine(string.Format("Project '{0}' was added.", e.Item.Name));
192-
var connectionPointContainer = (IConnectionPointContainer)e.Item.VBComponents;
193-
var interfaceId = typeof(_dispVBComponentsEvents).GUID;
194-
201+
RegisterComponentsEventSink(e, sink);
202+
RegisterReferencesEventsSink(e, sink);
203+
204+
_parser.State.OnParseRequested(sender);
205+
}
206+
207+
private void RegisterComponentsEventSink(DispatcherEventArgs<VBProject> e, VBProjectsEventsSink sink)
208+
{
209+
var connectionPointContainer = (IConnectionPointContainer) e.Item.VBComponents;
210+
var interfaceId = typeof (_dispVBComponentsEvents).GUID;
211+
195212
IConnectionPoint connectionPoint;
196213
connectionPointContainer.FindConnectionPoint(ref interfaceId, out connectionPoint);
197214

@@ -204,16 +221,28 @@ async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
204221
componentsSink.ComponentSelected += sink_ComponentSelected;
205222
_componentsEventSinks.Add(sink, componentsSink);
206223

224+
int cookie;
225+
connectionPoint.Advise(componentsSink, out cookie);
226+
227+
_componentsEventsConnectionPoints.Add(sink, Tuple.Create(connectionPoint, cookie));
228+
}
229+
230+
private void RegisterReferencesEventsSink(DispatcherEventArgs<VBProject> e, VBProjectsEventsSink sink)
231+
{
232+
var connectionPointContainer = (IConnectionPointContainer)e.Item.References;
233+
var interfaceId = typeof(_dispReferencesEvents).GUID;
234+
235+
IConnectionPoint connectionPoint;
236+
connectionPointContainer.FindConnectionPoint(ref interfaceId, out connectionPoint);
237+
207238
var referencesSink = new ReferencesEventsSink();
208239
referencesSink.ReferenceAdded += referencesSink_ReferenceAdded;
209240
referencesSink.ReferenceRemoved += referencesSink_ReferenceRemoved;
210241
_referencesEventsSinks.Add(sink, referencesSink);
211242

212243
int cookie;
213-
connectionPoint.Advise(componentsSink, out cookie);
214-
215-
_componentsEventsConnectionPoints.Add(e.Item.VBComponents, Tuple.Create(connectionPoint, cookie));
216-
_parser.State.OnParseRequested(sender);
244+
connectionPoint.Advise(referencesSink, out cookie);
245+
_referencesEventsConnectionPoints.Add(sink, Tuple.Create(connectionPoint, cookie));
217246
}
218247

219248
private void referencesSink_ReferenceRemoved(object sender, DispatcherEventArgs<Reference> e)

0 commit comments

Comments
 (0)