@@ -41,8 +41,10 @@ public class App : IDisposable
41
41
private readonly IConnectionPoint _projectsEventsConnectionPoint ;
42
42
private readonly int _projectsEventsCookie ;
43
43
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 > > ( ) ;
46
48
47
49
private readonly IDictionary < Type , Action > _hookActions ;
48
50
@@ -159,14 +161,21 @@ async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
159
161
_parser . State . RemoveProject ( e . Item ) ;
160
162
161
163
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 ) )
164
166
{
165
- value . Item1 . Unadvise ( value . Item2 ) ;
166
- _componentsEventsConnectionPoints . Remove ( e . Item . VBComponents ) ;
167
+ componentsTuple . Item1 . Unadvise ( componentsTuple . Item2 ) ;
168
+ _componentsEventsConnectionPoints . Remove ( sink ) ;
169
+ }
167
170
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 ) ;
169
176
}
177
+
178
+ _parser . State . ClearDeclarations ( e . Item ) ;
170
179
}
171
180
172
181
private readonly IDictionary < VBProjectsEventsSink , VBComponentsEventsSink > _componentsEventSinks =
@@ -189,9 +198,17 @@ async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
189
198
}
190
199
191
200
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
+
195
212
IConnectionPoint connectionPoint ;
196
213
connectionPointContainer . FindConnectionPoint ( ref interfaceId , out connectionPoint ) ;
197
214
@@ -204,16 +221,28 @@ async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
204
221
componentsSink . ComponentSelected += sink_ComponentSelected ;
205
222
_componentsEventSinks . Add ( sink , componentsSink ) ;
206
223
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
+
207
238
var referencesSink = new ReferencesEventsSink ( ) ;
208
239
referencesSink . ReferenceAdded += referencesSink_ReferenceAdded ;
209
240
referencesSink . ReferenceRemoved += referencesSink_ReferenceRemoved ;
210
241
_referencesEventsSinks . Add ( sink , referencesSink ) ;
211
242
212
243
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 ) ) ;
217
246
}
218
247
219
248
private void referencesSink_ReferenceRemoved ( object sender , DispatcherEventArgs < Reference > e )
0 commit comments