3
3
using Infralution . Localization . Wpf ;
4
4
using NLog ;
5
5
using Rubberduck . Common ;
6
- using Rubberduck . Parsing ;
7
- using Rubberduck . Parsing . Symbols ;
8
- using Rubberduck . Parsing . VBA ;
9
6
using Rubberduck . Settings ;
10
7
using Rubberduck . UI ;
11
8
using Rubberduck . UI . Command . MenuItems ;
12
9
using System ;
13
10
using System . Globalization ;
14
- using System . Linq ;
15
11
using System . Windows . Forms ;
16
12
using Rubberduck . UI . Command ;
17
13
using Rubberduck . UI . Command . MenuItems . CommandBars ;
18
14
using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
19
15
using Rubberduck . VersionCheck ;
16
+ using Application = System . Windows . Forms . Application ;
20
17
21
18
namespace Rubberduck
22
19
{
23
20
public sealed class App : IDisposable
24
21
{
25
- private readonly IVBE _vbe ;
26
22
private readonly IMessageBox _messageBox ;
27
- private readonly IParseCoordinator _parser ;
28
23
private readonly AutoSave . AutoSave _autoSave ;
29
24
private readonly IGeneralConfigService _configService ;
30
25
private readonly IAppMenu _appMenus ;
@@ -39,85 +34,27 @@ public sealed class App : IDisposable
39
34
40
35
public App ( IVBE vbe ,
41
36
IMessageBox messageBox ,
42
- IParseCoordinator parser ,
43
37
IGeneralConfigService configService ,
44
38
IAppMenu appMenus ,
45
39
RubberduckCommandBar stateBar ,
46
40
IRubberduckHooks hooks ,
47
41
IVersionCheck version ,
48
42
CommandBase checkVersionCommand )
49
43
{
50
- _vbe = vbe ;
51
44
_messageBox = messageBox ;
52
- _parser = parser ;
53
45
_configService = configService ;
54
- _autoSave = new AutoSave . AutoSave ( _vbe , _configService ) ;
46
+ _autoSave = new AutoSave . AutoSave ( vbe , _configService ) ;
55
47
_appMenus = appMenus ;
56
48
_stateBar = stateBar ;
57
49
_hooks = hooks ;
58
50
_version = version ;
59
51
_checkVersionCommand = checkVersionCommand ;
60
52
61
- _hooks . MessageReceived += _hooks_MessageReceived ;
62
53
_configService . SettingsChanged += _configService_SettingsChanged ;
63
- _parser . State . StateChanged += Parser_StateChanged ;
64
- _parser . State . StatusMessageUpdate += State_StatusMessageUpdate ;
65
-
54
+
66
55
UiDispatcher . Initialize ( ) ;
67
56
}
68
57
69
- private void State_StatusMessageUpdate ( object sender , RubberduckStatusMessageEventArgs e )
70
- {
71
- var message = e . Message ;
72
- if ( message == ParserState . LoadingReference . ToString ( ) )
73
- {
74
- // note: ugly hack to enable Rubberduck.Parsing assembly to do this
75
- message = RubberduckUI . ParserState_LoadingReference ;
76
- }
77
-
78
- _stateBar . SetStatusLabelCaption ( message , _parser . State . ModuleExceptions . Count ) ;
79
- }
80
-
81
- private void _hooks_MessageReceived ( object sender , HookEventArgs e )
82
- {
83
- RefreshSelection ( ) ;
84
- }
85
-
86
- private ParserState _lastStatus ;
87
- private Declaration _lastSelectedDeclaration ;
88
-
89
- private void RefreshSelection ( )
90
- {
91
- var pane = _vbe . ActiveCodePane ;
92
- {
93
- Declaration selectedDeclaration = null ;
94
- if ( ! pane . IsWrappingNullReference )
95
- {
96
- selectedDeclaration = _parser . State . FindSelectedDeclaration ( pane ) ;
97
- var refCount = selectedDeclaration == null ? 0 : selectedDeclaration . References . Count ( ) ;
98
- var caption = _stateBar . GetContextSelectionCaption ( _vbe . ActiveCodePane , selectedDeclaration ) ;
99
- _stateBar . SetContextSelectionCaption ( caption , refCount ) ;
100
- }
101
-
102
- var currentStatus = _parser . State . Status ;
103
- if ( ShouldEvaluateCanExecute ( selectedDeclaration , currentStatus ) )
104
- {
105
- _appMenus . EvaluateCanExecute ( _parser . State ) ;
106
- _stateBar . EvaluateCanExecute ( _parser . State ) ;
107
- }
108
-
109
- _lastStatus = currentStatus ;
110
- _lastSelectedDeclaration = selectedDeclaration ;
111
- }
112
- }
113
-
114
- private bool ShouldEvaluateCanExecute ( Declaration selectedDeclaration , ParserState currentStatus )
115
- {
116
- return _lastStatus != currentStatus ||
117
- ( selectedDeclaration != null && ! selectedDeclaration . Equals ( _lastSelectedDeclaration ) ) ||
118
- ( selectedDeclaration == null && _lastSelectedDeclaration != null ) ;
119
- }
120
-
121
58
private void _configService_SettingsChanged ( object sender , ConfigurationChangedEventArgs e )
122
59
{
123
60
_config = _configService . LoadConfiguration ( ) ;
@@ -163,8 +100,7 @@ public void Startup()
163
100
_stateBar . Initialize ( ) ;
164
101
_hooks . HookHotkeys ( ) ; // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts
165
102
_appMenus . Localize ( ) ;
166
- _stateBar . SetStatusLabelCaption ( ParserState . Pending ) ;
167
- _stateBar . EvaluateCanExecute ( _parser . State ) ;
103
+
168
104
UpdateLoggingLevel ( ) ;
169
105
170
106
if ( _config . UserSettings . GeneralSettings . CheckVersion )
@@ -185,14 +121,6 @@ public void Shutdown()
185
121
}
186
122
}
187
123
188
- private void Parser_StateChanged ( object sender , EventArgs e )
189
- {
190
- Logger . Debug ( "App handles StateChanged ({0}), evaluating menu states..." , _parser . State . Status ) ;
191
- _appMenus . EvaluateCanExecute ( _parser . State ) ;
192
- _stateBar . EvaluateCanExecute ( _parser . State ) ;
193
- _stateBar . SetStatusLabelCaption ( _parser . State . Status , _parser . State . ModuleExceptions . Count ) ;
194
- }
195
-
196
124
private void LoadConfig ( )
197
125
{
198
126
_config = _configService . LoadConfiguration ( ) ;
@@ -263,17 +191,6 @@ public void Dispose()
263
191
return ;
264
192
}
265
193
266
- if ( _parser != null && _parser . State != null )
267
- {
268
- _parser . State . StateChanged -= Parser_StateChanged ;
269
- _parser . State . StatusMessageUpdate -= State_StatusMessageUpdate ;
270
- }
271
-
272
- if ( _hooks != null )
273
- {
274
- _hooks . MessageReceived -= _hooks_MessageReceived ;
275
- }
276
-
277
194
if ( _configService != null )
278
195
{
279
196
_configService . SettingsChanged -= _configService_SettingsChanged ;
0 commit comments