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,37 +50,15 @@ 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 )
61
+ /* private void EnableSinkEventHandlersAndUpdateCache(object sender, EventArgs e)
105
62
{
106
63
_handleSinkEvents = true;
107
64
@@ -115,7 +72,7 @@ private void EnableSinkEventHandlersAndUpdateCache(object sender, EventArgs e)
115
72
private void DisableSinkEventHandlers(object sender, EventArgs e)
116
73
{
117
74
_handleSinkEvents = false;
118
- }
75
+ }*/
119
76
120
77
private void State_StatusMessageUpdate ( object sender , RubberduckStatusMessageEventArgs e )
121
78
{
@@ -216,7 +173,7 @@ public void Shutdown()
216
173
}
217
174
}
218
175
219
- #region sink handlers. todo: move to another class
176
+ /* #region sink handlers.
220
177
async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
221
178
{
222
179
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
@@ -253,12 +210,6 @@ async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
253
210
}
254
211
}
255
212
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
213
async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
263
214
{
264
215
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
@@ -285,37 +236,6 @@ async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
285
236
_parser.State.OnParseRequested(sender);
286
237
}
287
238
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
239
async void sink_ComponentSelected(object sender, DispatcherEventArgs<VBComponent> e)
320
240
{
321
241
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
@@ -324,8 +244,6 @@ async void sink_ComponentSelected(object sender, DispatcherEventArgs<VBComponent
324
244
{
325
245
return;
326
246
}
327
-
328
- // todo: keep Code Explorer in sync with Project Explorer
329
247
}
330
248
331
249
async void sink_ComponentRenamed(object sender, DispatcherRenamedEventArgs<VBComponent> e)
@@ -473,7 +391,7 @@ async void sink_ProjectActivated(object sender, DispatcherEventArgs<VBProject> e
473
391
474
392
// todo: keep Code Explorer in sync with Project Explorer
475
393
}
476
- #endregion
394
+ #endregion*/
477
395
478
396
private void _stateBar_Refresh ( object sender , EventArgs e )
479
397
{
@@ -509,28 +427,13 @@ private void LoadConfig()
509
427
}
510
428
511
429
private bool _disposed ;
512
-
513
430
public void Dispose ( )
514
431
{
515
432
if ( _disposed )
516
433
{
517
434
return ;
518
435
}
519
436
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
437
if ( _parser != null && _parser . State != null )
535
438
{
536
439
_parser . State . StateChanged -= Parser_StateChanged ;
@@ -564,41 +467,12 @@ public void Dispose()
564
467
_stateBar = null ;
565
468
}
566
469
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
470
if ( _autoSave != null )
587
471
{
588
472
_autoSave . Dispose ( ) ;
589
473
_autoSave = null ;
590
474
}
591
475
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
476
UiDispatcher . Shutdown ( ) ;
603
477
604
478
_disposed = true ;
0 commit comments