@@ -63,8 +63,8 @@ public App(IVBE vbe,
63
63
_version = version ;
64
64
_checkVersionCommand = checkVersionCommand ;
65
65
66
- VBEEvents . SelectionChanged += _vbe_SelectionChanged ;
67
- VBEEvents . WindowFocusChange += _vbe_FocusChanged ;
66
+ VBENativeServices . SelectionChanged += _vbe_SelectionChanged ;
67
+ VBENativeServices . WindowFocusChange += _vbe_FocusChanged ;
68
68
69
69
_configService . SettingsChanged += _configService_SettingsChanged ;
70
70
_parser . State . StateChanged += Parser_StateChanged ;
@@ -73,6 +73,9 @@ public App(IVBE vbe,
73
73
UiDispatcher . Initialize ( ) ;
74
74
}
75
75
76
+ //TODO - This should be able to move to the appropriate handling classes now.
77
+ #region Statusbar
78
+
76
79
private void State_StatusMessageUpdate ( object sender , RubberduckStatusMessageEventArgs e )
77
80
{
78
81
var message = e . Message ;
@@ -92,95 +95,79 @@ private void _vbe_SelectionChanged(object sender, SelectionChangedEventArgs e)
92
95
93
96
private void _vbe_FocusChanged ( object sender , WindowChangedEventArgs e )
94
97
{
95
- if ( e . EventType == WindowChangedEventArgs . FocusType . GotFocus )
98
+ if ( e . EventType == FocusType . GotFocus )
96
99
{
97
100
switch ( e . Window . Type )
98
101
{
99
102
case WindowKind . Designer :
103
+ //Designer or control on designer form selected.
100
104
RefreshSelection ( e . Window ) ;
101
105
break ;
102
106
case WindowKind . CodeWindow :
107
+ //Caret changed in a code pane.
103
108
RefreshSelection ( e . CodePane ) ;
104
109
break ;
105
110
}
106
- }
111
+ }
112
+ else if ( e . EventType == FocusType . ChildFocus )
113
+ {
114
+ //Treeview selection changed in project window.
115
+ RefreshSelection ( ) ;
116
+ }
107
117
}
108
118
109
119
private ParserState _lastStatus ;
110
120
private Declaration _lastSelectedDeclaration ;
111
121
private void RefreshSelection ( ICodePane pane )
112
122
{
113
- Declaration selectedDeclaration = null ;
114
- if ( ! pane . IsWrappingNullReference )
115
- {
116
- selectedDeclaration = _parser . State . FindSelectedDeclaration ( pane ) ;
117
- var refCount = selectedDeclaration == null ? 0 : selectedDeclaration . References . Count ( ) ;
118
- var caption = _stateBar . GetContextSelectionCaption ( _vbe . ActiveCodePane , selectedDeclaration ) ;
119
- _stateBar . SetContextSelectionCaption ( caption , refCount ) ;
120
- }
121
-
122
- var currentStatus = _parser . State . Status ;
123
- if ( ShouldEvaluateCanExecute ( selectedDeclaration , currentStatus ) )
123
+ if ( pane == null || pane . IsWrappingNullReference )
124
124
{
125
- _appMenus . EvaluateCanExecute ( _parser . State ) ;
126
- _stateBar . EvaluateCanExecute ( _parser . State ) ;
125
+ return ;
127
126
}
128
127
129
- _lastStatus = currentStatus ;
130
- _lastSelectedDeclaration = selectedDeclaration ;
128
+ var selectedDeclaration = _parser . State . FindSelectedDeclaration ( pane ) ;
129
+ var caption = _stateBar . GetContextSelectionCaption ( _vbe . ActiveCodePane , selectedDeclaration ) ;
130
+ UpdateStatusbarAndCommandState ( caption , selectedDeclaration ) ;
131
131
}
132
132
133
133
private void RefreshSelection ( IWindow window )
134
134
{
135
- if ( window . IsWrappingNullReference || window . Type != WindowKind . Designer )
135
+ if ( window == null || window . IsWrappingNullReference || window . Type != WindowKind . Designer )
136
136
{
137
137
return ;
138
138
}
139
- var caption = String . Empty ;
140
- var refCount = 0 ;
141
139
142
- WindowKind windowKind = _vbe . ActiveWindow . Type ;
143
- var pane = _vbe . ActiveCodePane ;
144
140
var component = _vbe . SelectedVBComponent ;
145
- var activeMDI = _vbe . ActiveMDIChild ( ) ;
146
-
147
- Declaration selectedDeclaration = null ;
148
-
149
- //TODO - Reinstate these lines once the host stops crashing - need to theck ParentProject doesn't return null
150
- ////TODO - I doubt this is the best way to check if the SelectedVBComponent and the ActiveCodePane are the same component.
151
- //if (windowKind == WindowKind.CodeWindow || (!_vbe.SelectedVBComponent.IsWrappingNullReference
152
- // && component.ParentProject.ProjectId == pane.CodeModule.Parent.ParentProject.ProjectId
153
- // && component.Name == pane.CodeModule.Parent.Name))
154
- //{
155
- // selectedDeclaration = _parser.State.FindSelectedDeclaration(pane);
156
- // refCount = selectedDeclaration == null ? 0 : selectedDeclaration.References.Count();
157
- // caption = _stateBar.GetContextSelectionCaption(_vbe.ActiveCodePane, selectedDeclaration);
158
- //}
159
- //else
160
- if ( windowKind == WindowKind . Designer )
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 )
161
151
{
162
- caption = GetComponentControlsCaption ( component ) ;
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 ;
163
157
}
164
158
else
165
159
{
166
- if ( _vbe . SelectedVBComponent . IsWrappingNullReference )
167
- {
168
- //The user might have selected the project node in Project Explorer
169
- //If they've chosen a folder, we'll return the project anyway
170
- caption = ! _vbe . ActiveVBProject . IsWrappingNullReference
171
- ? _vbe . ActiveVBProject . Name
172
- : null ;
173
- }
174
- else
175
- {
176
- caption = component . Type == ComponentType . UserForm
177
- && component . HasOpenDesigner
178
- && component . DesignerWindow ( ) . Caption == activeMDI . Caption
179
- ? GetComponentControlsCaption ( component )
180
- : String . Format ( "{0}.{1} ({2})" , component . ParentProject . Name , component . Name , component . Type ) ;
181
- }
160
+ caption = component . Type == ComponentType . UserForm && component . HasOpenDesigner
161
+ ? GetComponentControlsCaption ( component )
162
+ : string . Format ( "{0}.{1} ({2})" , component . ParentProject . Name , component . Name , component . Type ) ;
182
163
}
164
+ //TODO: Need to find the selected declaration for the selected treeview item.
165
+ UpdateStatusbarAndCommandState ( caption , null ) ;
166
+ }
183
167
168
+ private void UpdateStatusbarAndCommandState ( string caption , Declaration selectedDeclaration )
169
+ {
170
+ var refCount = selectedDeclaration == null ? 0 : selectedDeclaration . References . Count ( ) ;
184
171
_stateBar . SetContextSelectionCaption ( caption , refCount ) ;
185
172
186
173
var currentStatus = _parser . State . Status ;
@@ -191,7 +178,7 @@ private void RefreshSelection(IWindow window)
191
178
}
192
179
193
180
_lastStatus = currentStatus ;
194
- _lastSelectedDeclaration = selectedDeclaration ;
181
+ _lastSelectedDeclaration = selectedDeclaration ;
195
182
}
196
183
197
184
private string GetComponentControlsCaption ( IVBComponent component )
@@ -220,6 +207,8 @@ private bool ShouldEvaluateCanExecute(Declaration selectedDeclaration, ParserSta
220
207
( selectedDeclaration == null && _lastSelectedDeclaration != null ) ;
221
208
}
222
209
210
+ #endregion
211
+
223
212
private void _configService_SettingsChanged ( object sender , ConfigurationChangedEventArgs e )
224
213
{
225
214
_config = _configService . LoadConfiguration ( ) ;
@@ -371,8 +360,8 @@ public void Dispose()
371
360
_parser . State . StatusMessageUpdate -= State_StatusMessageUpdate ;
372
361
}
373
362
374
- VBEEvents . SelectionChanged += _vbe_SelectionChanged ;
375
- VBEEvents . WindowFocusChange += _vbe_FocusChanged ;
363
+ VBENativeServices . SelectionChanged += _vbe_SelectionChanged ;
364
+ VBENativeServices . WindowFocusChange += _vbe_FocusChanged ;
376
365
377
366
if ( _configService != null )
378
367
{
0 commit comments