@@ -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,90 +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 )
123
+ if ( pane == null || pane . IsWrappingNullReference )
115
124
{
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 ) )
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 ;
141
+ var caption = GetComponentControlsCaption ( component ) ;
142
+ //TODO: Need to find the selected declaration for the Form\Control.
143
+ UpdateStatusbarAndCommandState ( caption , null ) ;
144
+ }
145
145
146
- Declaration selectedDeclaration = null ;
147
-
148
- //TODO - I doubt this is the best way to check if the SelectedVBComponent and the ActiveCodePane are the same component.
149
- if ( windowKind == WindowKind . CodeWindow || ( ! _vbe . SelectedVBComponent . IsWrappingNullReference
150
- && component . ParentProject . ProjectId == pane . CodeModule . Parent . ParentProject . ProjectId
151
- && component . Name == pane . CodeModule . Parent . Name ) )
152
- {
153
- selectedDeclaration = _parser . State . FindSelectedDeclaration ( pane ) ;
154
- refCount = selectedDeclaration == null ? 0 : selectedDeclaration . References . Count ( ) ;
155
- caption = _stateBar . GetContextSelectionCaption ( _vbe . ActiveCodePane , selectedDeclaration ) ;
156
- }
157
- else if ( windowKind == WindowKind . Designer )
146
+ private void RefreshSelection ( )
147
+ {
148
+ var caption = string . Empty ;
149
+ var component = _vbe . SelectedVBComponent ;
150
+ if ( component == null || component . IsWrappingNullReference )
158
151
{
159
- 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 ;
160
157
}
161
158
else
162
159
{
163
- if ( _vbe . SelectedVBComponent . IsWrappingNullReference )
164
- {
165
- //The user might have selected the project node in Project Explorer
166
- //If they've chosen a folder, we'll return the project anyway
167
- caption = ! _vbe . ActiveVBProject . IsWrappingNullReference
168
- ? _vbe . ActiveVBProject . Name
169
- : null ;
170
- }
171
- else
172
- {
173
- caption = component . Type == ComponentType . UserForm && component . HasOpenDesigner
174
- ? GetComponentControlsCaption ( component )
175
- : String . Format ( "{0}.{1} ({2})" , component . ParentProject . Name , component . Name , component . Type ) ;
176
- }
160
+ caption = component . Type == ComponentType . UserForm && component . HasOpenDesigner
161
+ ? GetComponentControlsCaption ( component )
162
+ : string . Format ( "{0}.{1} ({2})" , component . ParentProject . Name , component . Name , component . Type ) ;
177
163
}
164
+ //TODO: Need to find the selected declaration for the selected treeview item.
165
+ UpdateStatusbarAndCommandState ( caption , null ) ;
166
+ }
178
167
168
+ private void UpdateStatusbarAndCommandState ( string caption , Declaration selectedDeclaration )
169
+ {
170
+ var refCount = selectedDeclaration == null ? 0 : selectedDeclaration . References . Count ( ) ;
179
171
_stateBar . SetContextSelectionCaption ( caption , refCount ) ;
180
172
181
173
var currentStatus = _parser . State . Status ;
@@ -186,7 +178,7 @@ private void RefreshSelection(IWindow window)
186
178
}
187
179
188
180
_lastStatus = currentStatus ;
189
- _lastSelectedDeclaration = selectedDeclaration ;
181
+ _lastSelectedDeclaration = selectedDeclaration ;
190
182
}
191
183
192
184
private string GetComponentControlsCaption ( IVBComponent component )
@@ -215,6 +207,8 @@ private bool ShouldEvaluateCanExecute(Declaration selectedDeclaration, ParserSta
215
207
( selectedDeclaration == null && _lastSelectedDeclaration != null ) ;
216
208
}
217
209
210
+ #endregion
211
+
218
212
private void _configService_SettingsChanged ( object sender , ConfigurationChangedEventArgs e )
219
213
{
220
214
_config = _configService . LoadConfiguration ( ) ;
@@ -366,8 +360,8 @@ public void Dispose()
366
360
_parser . State . StatusMessageUpdate -= State_StatusMessageUpdate ;
367
361
}
368
362
369
- VBEEvents . SelectionChanged += _vbe_SelectionChanged ;
370
- VBEEvents . WindowFocusChange += _vbe_FocusChanged ;
363
+ VBENativeServices . SelectionChanged += _vbe_SelectionChanged ;
364
+ VBENativeServices . WindowFocusChange += _vbe_FocusChanged ;
371
365
372
366
if ( _configService != null )
373
367
{
0 commit comments