3
3
using Microsoft . Vbe . Interop ;
4
4
using NLog ;
5
5
using Rubberduck . Common ;
6
- using Rubberduck . Common . Dispatch ;
7
6
using Rubberduck . Parsing ;
8
7
using Rubberduck . Parsing . Symbols ;
9
8
using Rubberduck . Parsing . VBA ;
10
9
using Rubberduck . Settings ;
11
10
using Rubberduck . UI ;
12
11
using Rubberduck . UI . Command . MenuItems ;
13
12
using System ;
14
- using System . Collections . Generic ;
15
- using System . Diagnostics ;
16
13
using System . Globalization ;
17
- using System . Linq ;
18
- using System . Runtime . InteropServices . ComTypes ;
19
14
using System . Threading . Tasks ;
20
15
using System . Windows . Forms ;
21
- using Rubberduck . UI . SourceControl ;
22
- using Rubberduck . VBEditor . Extensions ;
23
16
24
17
namespace Rubberduck
25
18
{
26
19
public sealed class App : IDisposable
27
20
{
28
- private const string FILE_TARGET_NAME = "file" ;
29
21
private readonly VBE _vbe ;
30
22
private readonly IMessageBox _messageBox ;
31
- private IRubberduckParser _parser ;
23
+ private readonly IRubberduckParser _parser ;
32
24
private AutoSave . AutoSave _autoSave ;
33
25
private IGeneralConfigService _configService ;
34
26
private readonly IAppMenu _appMenus ;
35
27
private RubberduckCommandBar _stateBar ;
36
28
private IRubberduckHooks _hooks ;
37
- private bool _handleSinkEvents = true ;
38
- private readonly BranchesViewViewModel _branchesVM ;
39
- private readonly SourceControlViewViewModel _sourceControlPanelVM ;
40
29
private readonly UI . Settings . Settings _settings ;
41
30
42
31
private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
43
-
44
- private VBProjectsEventsSink _sink ;
32
+
45
33
private Configuration _config ;
46
34
47
- private readonly IConnectionPoint _projectsEventsConnectionPoint ;
48
- private readonly int _projectsEventsCookie ;
49
-
50
- private readonly IDictionary < string , Tuple < IConnectionPoint , int > > _componentsEventsConnectionPoints =
51
- new Dictionary < string , Tuple < IConnectionPoint , int > > ( ) ;
52
- private readonly IDictionary < string , Tuple < IConnectionPoint , int > > _referencesEventsConnectionPoints =
53
- new Dictionary < string , Tuple < IConnectionPoint , int > > ( ) ;
54
-
55
35
public App ( VBE vbe , IMessageBox messageBox ,
56
36
UI . Settings . Settings settings ,
57
37
IRubberduckParser parser ,
58
38
IGeneralConfigService configService ,
59
39
IAppMenu appMenus ,
60
40
RubberduckCommandBar stateBar ,
61
- IRubberduckHooks hooks ,
62
- SourceControlDockablePresenter sourceControlPresenter )
41
+ IRubberduckHooks hooks )
63
42
{
64
43
_vbe = vbe ;
65
44
_messageBox = messageBox ;
@@ -71,52 +50,14 @@ public App(VBE vbe, IMessageBox messageBox,
71
50
_stateBar = stateBar ;
72
51
_hooks = hooks ;
73
52
74
- var sourceControlPanel = ( SourceControlPanel ) sourceControlPresenter . Window ( ) ;
75
- _sourceControlPanelVM = ( SourceControlViewViewModel ) sourceControlPanel . ViewModel ;
76
- _branchesVM = ( BranchesViewViewModel ) _sourceControlPanelVM . TabItems . Single ( t => t . ViewModel . Tab == SourceControlTab . Branches ) . ViewModel ;
77
-
78
- _sourceControlPanelVM . OpenRepoStarted += DisableSinkEventHandlers ;
79
- _sourceControlPanelVM . OpenRepoCompleted += EnableSinkEventHandlersAndUpdateCache ;
80
-
81
- _branchesVM . LoadingComponentsStarted += DisableSinkEventHandlers ;
82
- _branchesVM . LoadingComponentsCompleted += EnableSinkEventHandlersAndUpdateCache ;
83
-
84
53
_hooks . MessageReceived += _hooks_MessageReceived ;
85
54
_configService . SettingsChanged += _configService_SettingsChanged ;
86
55
_parser . State . StateChanged += Parser_StateChanged ;
87
56
_parser . State . StatusMessageUpdate += State_StatusMessageUpdate ;
88
57
_stateBar . Refresh += _stateBar_Refresh ;
89
-
90
- _sink = new VBProjectsEventsSink ( ) ;
91
- var connectionPointContainer = ( IConnectionPointContainer ) _vbe . VBProjects ;
92
- var interfaceId = typeof ( _dispVBProjectsEvents ) . GUID ;
93
- connectionPointContainer . FindConnectionPoint ( ref interfaceId , out _projectsEventsConnectionPoint ) ;
94
-
95
- _sink . ProjectAdded += sink_ProjectAdded ;
96
- _sink . ProjectRemoved += sink_ProjectRemoved ;
97
- _sink . ProjectActivated += sink_ProjectActivated ;
98
- _sink . ProjectRenamed += sink_ProjectRenamed ;
99
-
100
- _projectsEventsConnectionPoint . Advise ( _sink , out _projectsEventsCookie ) ;
101
58
UiDispatcher . Initialize ( ) ;
102
59
}
103
60
104
- private void EnableSinkEventHandlersAndUpdateCache ( object sender , EventArgs e )
105
- {
106
- _handleSinkEvents = true ;
107
-
108
- // update cache
109
- _parser . State . RemoveProject ( _vbe . ActiveVBProject . HelpFile ) ;
110
- _parser . State . AddProject ( _vbe . ActiveVBProject ) ;
111
-
112
- _parser . State . OnParseRequested ( this ) ;
113
- }
114
-
115
- private void DisableSinkEventHandlers ( object sender , EventArgs e )
116
- {
117
- _handleSinkEvents = false ;
118
- }
119
-
120
61
private void State_StatusMessageUpdate ( object sender , RubberduckStatusMessageEventArgs e )
121
62
{
122
63
var message = e . Message ;
@@ -216,7 +157,7 @@ public void Shutdown()
216
157
}
217
158
}
218
159
219
- #region sink handlers. todo: move to another class
160
+ /* #region sink handlers.
220
161
async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
221
162
{
222
163
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
@@ -232,33 +173,10 @@ async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
232
173
var projectId = e.Item.HelpFile;
233
174
Debug.Assert(projectId != null);
234
175
235
- _componentsEventsSinks . Remove ( projectId ) ;
236
- _referencesEventsSinks . Remove ( projectId ) ;
237
176
_parser.State.RemoveProject(e.Item);
238
177
_parser.State.OnParseRequested(this);
239
-
240
- Logger . Debug ( "Project '{0}' was removed." , e . Item . Name ) ;
241
- Tuple < IConnectionPoint , int > componentsTuple ;
242
- if ( _componentsEventsConnectionPoints . TryGetValue ( projectId , out componentsTuple ) )
243
- {
244
- componentsTuple . Item1 . Unadvise ( componentsTuple . Item2 ) ;
245
- _componentsEventsConnectionPoints . Remove ( projectId ) ;
246
- }
247
-
248
- Tuple < IConnectionPoint , int > referencesTuple ;
249
- if ( _referencesEventsConnectionPoints . TryGetValue ( projectId , out referencesTuple ) )
250
- {
251
- referencesTuple . Item1 . Unadvise ( referencesTuple . Item2 ) ;
252
- _referencesEventsConnectionPoints . Remove ( projectId ) ;
253
- }
254
178
}
255
179
256
- private readonly IDictionary < string , VBComponentsEventsSink > _componentsEventsSinks =
257
- new Dictionary < string , VBComponentsEventsSink > ( ) ;
258
-
259
- private readonly IDictionary < string , ReferencesEventsSink > _referencesEventsSinks =
260
- new Dictionary < string , ReferencesEventsSink > ( ) ;
261
-
262
180
async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
263
181
{
264
182
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
@@ -285,37 +203,6 @@ async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
285
203
_parser.State.OnParseRequested(sender);
286
204
}
287
205
288
- private void RegisterComponentsEventSink ( VBComponents components , string projectId )
289
- {
290
- if ( _componentsEventsSinks . ContainsKey ( projectId ) )
291
- {
292
- // already registered - this is caused by the initial load+rename of a project in the VBE
293
- Logger . Debug ( "Components sink already registered." ) ;
294
- return ;
295
- }
296
-
297
- var connectionPointContainer = ( IConnectionPointContainer ) components ;
298
- var interfaceId = typeof ( _dispVBComponentsEvents ) . GUID ;
299
-
300
- IConnectionPoint connectionPoint ;
301
- connectionPointContainer . FindConnectionPoint ( ref interfaceId , out connectionPoint ) ;
302
-
303
- var componentsSink = new VBComponentsEventsSink ( ) ;
304
- componentsSink . ComponentActivated += sink_ComponentActivated ;
305
- componentsSink . ComponentAdded += sink_ComponentAdded ;
306
- componentsSink . ComponentReloaded += sink_ComponentReloaded ;
307
- componentsSink . ComponentRemoved += sink_ComponentRemoved ;
308
- componentsSink . ComponentRenamed += sink_ComponentRenamed ;
309
- componentsSink . ComponentSelected += sink_ComponentSelected ;
310
- _componentsEventsSinks . Add ( projectId , componentsSink ) ;
311
-
312
- int cookie ;
313
- connectionPoint . Advise ( componentsSink , out cookie ) ;
314
-
315
- _componentsEventsConnectionPoints . Add ( projectId , Tuple . Create ( connectionPoint , cookie ) ) ;
316
- Logger . Debug ( "Components sink registered and advising." ) ;
317
- }
318
-
319
206
async void sink_ComponentSelected(object sender, DispatcherEventArgs<VBComponent> e)
320
207
{
321
208
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
@@ -324,8 +211,6 @@ async void sink_ComponentSelected(object sender, DispatcherEventArgs<VBComponent
324
211
{
325
212
return;
326
213
}
327
-
328
- // todo: keep Code Explorer in sync with Project Explorer
329
214
}
330
215
331
216
async void sink_ComponentRenamed(object sender, DispatcherRenamedEventArgs<VBComponent> e)
@@ -356,25 +241,8 @@ async void sink_ComponentRenamed(object sender, DispatcherRenamedEventArgs<VBCom
356
241
// with two Document-component types just skip the Worksheet component
357
242
((ClassModuleDeclaration) componentDeclaration).Supertypes.All(a => a.IdentifierName != "Worksheet"))
358
243
{
359
- _componentsEventsSinks . Remove ( projectId ) ;
360
- _referencesEventsSinks . Remove ( projectId ) ;
361
244
_parser.State.RemoveProject(projectId);
362
245
363
- Logger . Debug ( "Project '{0}' was removed." , e . Item . Name ) ;
364
- Tuple < IConnectionPoint , int > componentsTuple ;
365
- if ( _componentsEventsConnectionPoints . TryGetValue ( projectId , out componentsTuple ) )
366
- {
367
- componentsTuple . Item1 . Unadvise ( componentsTuple . Item2 ) ;
368
- _componentsEventsConnectionPoints . Remove ( projectId ) ;
369
- }
370
-
371
- Tuple < IConnectionPoint , int > referencesTuple ;
372
- if ( _referencesEventsConnectionPoints . TryGetValue ( projectId , out referencesTuple ) )
373
- {
374
- referencesTuple . Item1 . Unadvise ( referencesTuple . Item2 ) ;
375
- _referencesEventsConnectionPoints . Remove ( projectId ) ;
376
- }
377
-
378
246
_parser.State.AddProject(e.Item.Collection.Parent);
379
247
}
380
248
else
@@ -431,18 +299,6 @@ async void sink_ComponentAdded(object sender, DispatcherEventArgs<VBComponent> e
431
299
_parser.State.OnParseRequested(sender, e.Item);
432
300
}
433
301
434
- async void sink_ComponentActivated ( object sender , DispatcherEventArgs < VBComponent > e )
435
- {
436
- if ( ! _handleSinkEvents || ! _vbe . IsInDesignMode ( ) ) { return ; }
437
-
438
- if ( ! _parser . State . AllDeclarations . Any ( ) )
439
- {
440
- return ;
441
- }
442
-
443
- // do something?
444
- }
445
-
446
302
async void sink_ProjectRenamed(object sender, DispatcherRenamedEventArgs<VBProject> e)
447
303
{
448
304
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
@@ -461,19 +317,7 @@ async void sink_ProjectRenamed(object sender, DispatcherRenamedEventArgs<VBProje
461
317
462
318
_parser.State.OnParseRequested(sender);
463
319
}
464
-
465
- async void sink_ProjectActivated ( object sender , DispatcherEventArgs < VBProject > e )
466
- {
467
- if ( ! _handleSinkEvents || ! _vbe . IsInDesignMode ( ) ) { return ; }
468
-
469
- if ( ! _parser . State . AllDeclarations . Any ( ) )
470
- {
471
- return ;
472
- }
473
-
474
- // todo: keep Code Explorer in sync with Project Explorer
475
- }
476
- #endregion
320
+ #endregion*/
477
321
478
322
private void _stateBar_Refresh ( object sender , EventArgs e )
479
323
{
@@ -509,28 +353,13 @@ private void LoadConfig()
509
353
}
510
354
511
355
private bool _disposed ;
512
-
513
356
public void Dispose ( )
514
357
{
515
358
if ( _disposed )
516
359
{
517
360
return ;
518
361
}
519
362
520
- if ( _sourceControlPanelVM != null )
521
- {
522
- _sourceControlPanelVM . OpenRepoStarted -= DisableSinkEventHandlers ;
523
- _sourceControlPanelVM . OpenRepoCompleted -= EnableSinkEventHandlersAndUpdateCache ;
524
- }
525
-
526
- if ( _branchesVM != null )
527
- {
528
- _branchesVM . LoadingComponentsStarted -= DisableSinkEventHandlers ;
529
- _branchesVM . LoadingComponentsCompleted -= EnableSinkEventHandlersAndUpdateCache ;
530
- }
531
-
532
- _handleSinkEvents = false ;
533
-
534
363
if ( _parser != null && _parser . State != null )
535
364
{
536
365
_parser . State . StateChanged -= Parser_StateChanged ;
@@ -564,41 +393,12 @@ public void Dispose()
564
393
_stateBar = null ;
565
394
}
566
395
567
- if ( _sink != null )
568
- {
569
- _sink . ProjectAdded -= sink_ProjectAdded ;
570
- _sink . ProjectRemoved -= sink_ProjectRemoved ;
571
- _sink . ProjectActivated -= sink_ProjectActivated ;
572
- _sink . ProjectRenamed -= sink_ProjectRenamed ;
573
- _sink = null ;
574
- }
575
-
576
- foreach ( var item in _componentsEventsSinks )
577
- {
578
- item . Value . ComponentActivated -= sink_ComponentActivated ;
579
- item . Value . ComponentAdded -= sink_ComponentAdded ;
580
- item . Value . ComponentReloaded -= sink_ComponentReloaded ;
581
- item . Value . ComponentRemoved -= sink_ComponentRemoved ;
582
- item . Value . ComponentRenamed -= sink_ComponentRenamed ;
583
- item . Value . ComponentSelected -= sink_ComponentSelected ;
584
- }
585
-
586
396
if ( _autoSave != null )
587
397
{
588
398
_autoSave . Dispose ( ) ;
589
399
_autoSave = null ;
590
400
}
591
401
592
- _projectsEventsConnectionPoint . Unadvise ( _projectsEventsCookie ) ;
593
- foreach ( var item in _componentsEventsConnectionPoints )
594
- {
595
- item . Value . Item1 . Unadvise ( item . Value . Item2 ) ;
596
- }
597
- foreach ( var item in _referencesEventsConnectionPoints )
598
- {
599
- item . Value . Item1 . Unadvise ( item . Value . Item2 ) ;
600
- }
601
-
602
402
UiDispatcher . Shutdown ( ) ;
603
403
604
404
_disposed = true ;
0 commit comments