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
- using Rubberduck . VBEditor . Events ;
19
- using Rubberduck . VBEditor . SafeComWrappers ;
20
14
using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
21
- using Rubberduck . VBEditor . SafeComWrappers . MSForms ;
22
- using Rubberduck . VBEditor . SafeComWrappers . Office . Core . Abstract ;
23
15
using Rubberduck . VersionCheck ;
24
16
using Application = System . Windows . Forms . Application ;
25
17
26
18
namespace Rubberduck
27
19
{
28
20
public sealed class App : IDisposable
29
21
{
30
- private readonly IVBE _vbe ;
31
22
private readonly IMessageBox _messageBox ;
32
- private readonly IParseCoordinator _parser ;
33
23
private readonly AutoSave . AutoSave _autoSave ;
34
24
private readonly IGeneralConfigService _configService ;
35
25
private readonly IAppMenu _appMenus ;
@@ -44,171 +34,27 @@ public sealed class App : IDisposable
44
34
45
35
public App ( IVBE vbe ,
46
36
IMessageBox messageBox ,
47
- IParseCoordinator parser ,
48
37
IGeneralConfigService configService ,
49
38
IAppMenu appMenus ,
50
39
RubberduckCommandBar stateBar ,
51
40
IRubberduckHooks hooks ,
52
41
IVersionCheck version ,
53
42
CommandBase checkVersionCommand )
54
43
{
55
- _vbe = vbe ;
56
44
_messageBox = messageBox ;
57
- _parser = parser ;
58
45
_configService = configService ;
59
- _autoSave = new AutoSave . AutoSave ( _vbe , _configService ) ;
46
+ _autoSave = new AutoSave . AutoSave ( vbe , _configService ) ;
60
47
_appMenus = appMenus ;
61
48
_stateBar = stateBar ;
62
49
_hooks = hooks ;
63
50
_version = version ;
64
51
_checkVersionCommand = checkVersionCommand ;
65
52
66
- VBENativeServices . SelectionChanged += _vbe_SelectionChanged ;
67
- VBENativeServices . WindowFocusChange += _vbe_FocusChanged ;
68
-
69
53
_configService . SettingsChanged += _configService_SettingsChanged ;
70
- _parser . State . StateChanged += Parser_StateChanged ;
71
- _parser . State . StatusMessageUpdate += State_StatusMessageUpdate ;
72
-
54
+
73
55
UiDispatcher . Initialize ( ) ;
74
56
}
75
57
76
- //TODO - This should be able to move to the appropriate handling classes now.
77
- #region Statusbar
78
-
79
- private void State_StatusMessageUpdate ( object sender , RubberduckStatusMessageEventArgs e )
80
- {
81
- var message = e . Message ;
82
- if ( message == ParserState . LoadingReference . ToString ( ) )
83
- {
84
- // note: ugly hack to enable Rubberduck.Parsing assembly to do this
85
- message = RubberduckUI . ParserState_LoadingReference ;
86
- }
87
-
88
- _stateBar . SetStatusLabelCaption ( message , _parser . State . ModuleExceptions . Count ) ;
89
- }
90
-
91
- private void _vbe_SelectionChanged ( object sender , SelectionChangedEventArgs e )
92
- {
93
- RefreshSelection ( e . CodePane ) ;
94
- }
95
-
96
- private void _vbe_FocusChanged ( object sender , WindowChangedEventArgs e )
97
- {
98
- if ( e . EventType == FocusType . GotFocus )
99
- {
100
- switch ( e . Window . Type )
101
- {
102
- case WindowKind . Designer :
103
- //Designer or control on designer form selected.
104
- RefreshSelection ( e . Window ) ;
105
- break ;
106
- case WindowKind . CodeWindow :
107
- //Caret changed in a code pane.
108
- RefreshSelection ( e . CodePane ) ;
109
- break ;
110
- }
111
- }
112
- else if ( e . EventType == FocusType . ChildFocus )
113
- {
114
- //Treeview selection changed in project window.
115
- RefreshSelection ( ) ;
116
- }
117
- }
118
-
119
- private ParserState _lastStatus ;
120
- private Declaration _lastSelectedDeclaration ;
121
- private void RefreshSelection ( ICodePane pane )
122
- {
123
- if ( pane == null || pane . IsWrappingNullReference )
124
- {
125
- return ;
126
- }
127
-
128
- var selectedDeclaration = _parser . State . FindSelectedDeclaration ( pane ) ;
129
- var caption = _stateBar . GetContextSelectionCaption ( _vbe . ActiveCodePane , selectedDeclaration ) ;
130
- UpdateStatusbarAndCommandState ( caption , selectedDeclaration ) ;
131
- }
132
-
133
- private void RefreshSelection ( IWindow window )
134
- {
135
- if ( window == null || window . IsWrappingNullReference || window . Type != WindowKind . Designer )
136
- {
137
- return ;
138
- }
139
-
140
- var component = _vbe . SelectedVBComponent ;
141
- var caption = GetComponentControlsCaption ( component ) ;
142
- //TODO: Need to find the selected declaration for the Form\Control.
143
- UpdateStatusbarAndCommandState ( caption , null ) ;
144
- }
145
-
146
- private void RefreshSelection ( )
147
- {
148
- var caption = string . Empty ;
149
- var component = _vbe . SelectedVBComponent ;
150
- if ( component == null || component . IsWrappingNullReference )
151
- {
152
- //The user might have selected the project node in Project Explorer
153
- //If they've chosen a folder, we'll return the project anyway
154
- caption = ! _vbe . ActiveVBProject . IsWrappingNullReference
155
- ? _vbe . ActiveVBProject . Name
156
- : null ;
157
- }
158
- else
159
- {
160
- caption = component . Type == ComponentType . UserForm && component . HasOpenDesigner
161
- ? GetComponentControlsCaption ( component )
162
- : string . Format ( "{0}.{1} ({2})" , component . ParentProject . Name , component . Name , component . Type ) ;
163
- }
164
- //TODO: Need to find the selected declaration for the selected treeview item.
165
- UpdateStatusbarAndCommandState ( caption , null ) ;
166
- }
167
-
168
- private void UpdateStatusbarAndCommandState ( string caption , Declaration selectedDeclaration )
169
- {
170
- var refCount = selectedDeclaration == null ? 0 : selectedDeclaration . References . Count ( ) ;
171
- _stateBar . SetContextSelectionCaption ( caption , refCount ) ;
172
-
173
- var currentStatus = _parser . State . Status ;
174
- if ( ShouldEvaluateCanExecute ( selectedDeclaration , currentStatus ) )
175
- {
176
- _appMenus . EvaluateCanExecute ( _parser . State ) ;
177
- _stateBar . EvaluateCanExecute ( _parser . State ) ;
178
- }
179
-
180
- _lastStatus = currentStatus ;
181
- _lastSelectedDeclaration = selectedDeclaration ;
182
- }
183
-
184
- private string GetComponentControlsCaption ( IVBComponent component )
185
- {
186
- switch ( component . SelectedControls . Count )
187
- {
188
- case 0 :
189
- //TODO get the real designer for VB6
190
- return String . Format ( "{0}.{1} ({2})" , component . ParentProject . Name , component . Name , "MSForms.UserForm" ) ;
191
- break ;
192
- case 1 :
193
- //TODO return the libraryName.className of the control
194
- IControl control = component . SelectedControls . First ( ) ;
195
- return String . Format ( "{0}.{1}.{2} ({3})" , component . ParentProject . Name , component . Name , control . Name , control . TypeName ( ) ) ;
196
- break ;
197
- default :
198
- return String . Format ( "{0}.{1} ({2})" , component . ParentProject . Name , component . Name , RubberduckUI . ContextMultipleControlsSelection ) ;
199
- break ;
200
- }
201
- }
202
-
203
- private bool ShouldEvaluateCanExecute ( Declaration selectedDeclaration , ParserState currentStatus )
204
- {
205
- return _lastStatus != currentStatus ||
206
- ( selectedDeclaration != null && ! selectedDeclaration . Equals ( _lastSelectedDeclaration ) ) ||
207
- ( selectedDeclaration == null && _lastSelectedDeclaration != null ) ;
208
- }
209
-
210
- #endregion
211
-
212
58
private void _configService_SettingsChanged ( object sender , ConfigurationChangedEventArgs e )
213
59
{
214
60
_config = _configService . LoadConfiguration ( ) ;
@@ -254,8 +100,7 @@ public void Startup()
254
100
_stateBar . Initialize ( ) ;
255
101
_hooks . HookHotkeys ( ) ; // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts
256
102
_appMenus . Localize ( ) ;
257
- _stateBar . SetStatusLabelCaption ( ParserState . Pending ) ;
258
- _stateBar . EvaluateCanExecute ( _parser . State ) ;
103
+
259
104
UpdateLoggingLevel ( ) ;
260
105
261
106
if ( _config . UserSettings . GeneralSettings . CheckVersion )
@@ -276,14 +121,6 @@ public void Shutdown()
276
121
}
277
122
}
278
123
279
- private void Parser_StateChanged ( object sender , EventArgs e )
280
- {
281
- Logger . Debug ( "App handles StateChanged ({0}), evaluating menu states..." , _parser . State . Status ) ;
282
- _appMenus . EvaluateCanExecute ( _parser . State ) ;
283
- _stateBar . EvaluateCanExecute ( _parser . State ) ;
284
- _stateBar . SetStatusLabelCaption ( _parser . State . Status , _parser . State . ModuleExceptions . Count ) ;
285
- }
286
-
287
124
private void LoadConfig ( )
288
125
{
289
126
_config = _configService . LoadConfiguration ( ) ;
@@ -354,15 +191,6 @@ public void Dispose()
354
191
return ;
355
192
}
356
193
357
- if ( _parser != null && _parser . State != null )
358
- {
359
- _parser . State . StateChanged -= Parser_StateChanged ;
360
- _parser . State . StatusMessageUpdate -= State_StatusMessageUpdate ;
361
- }
362
-
363
- VBENativeServices . SelectionChanged += _vbe_SelectionChanged ;
364
- VBENativeServices . WindowFocusChange += _vbe_FocusChanged ;
365
-
366
194
if ( _configService != null )
367
195
{
368
196
_configService . SettingsChanged -= _configService_SettingsChanged ;
0 commit comments