2
2
using System . Collections . Generic ;
3
3
using System . Globalization ;
4
4
using System . Linq ;
5
+ using System . Runtime . InteropServices ;
5
6
using Rubberduck . Resources ;
6
- using Rubberduck . Parsing ;
7
7
using Rubberduck . Parsing . Symbols ;
8
8
using Rubberduck . Parsing . UIContext ;
9
9
using Rubberduck . Parsing . VBA ;
@@ -14,18 +14,18 @@ namespace Rubberduck.UI.Command.MenuItems.CommandBars
14
14
public class RubberduckCommandBar : AppCommandBarBase , IDisposable
15
15
{
16
16
private readonly IContextFormatter _formatter ;
17
- private readonly IParseCoordinator _parser ;
17
+ private readonly RubberduckParserState _state ;
18
18
private readonly ISelectionChangeService _selectionService ;
19
19
20
- public RubberduckCommandBar ( IParseCoordinator parser , IEnumerable < ICommandMenuItem > items , IContextFormatter formatter , ISelectionChangeService selectionService , IUiDispatcher uiDispatcher )
20
+ public RubberduckCommandBar ( RubberduckParserState state , IEnumerable < ICommandMenuItem > items , IContextFormatter formatter , ISelectionChangeService selectionService , IUiDispatcher uiDispatcher )
21
21
: base ( "Rubberduck" , CommandBarPosition . Top , items , uiDispatcher )
22
22
{
23
- _parser = parser ;
23
+ _state = state ;
24
24
_formatter = formatter ;
25
25
_selectionService = selectionService ;
26
26
27
- _parser . State . StateChanged += OnParserStateChanged ;
28
- _parser . State . StatusMessageUpdate += OnParserStatusMessageUpdate ;
27
+ _state . StateChangedHighPriority += OnParserStateChanged ;
28
+ _state . StatusMessageUpdate += OnParserStatusMessageUpdate ;
29
29
_selectionService . SelectionChanged += OnSelectionChange ;
30
30
}
31
31
@@ -35,14 +35,14 @@ public override void Initialize()
35
35
{
36
36
base . Initialize ( ) ;
37
37
SetStatusLabelCaption ( ParserState . Pending ) ;
38
- EvaluateCanExecute ( _parser . State ) ;
38
+ EvaluateCanExecute ( _state ) ;
39
39
}
40
40
41
41
private Declaration _lastDeclaration ;
42
42
private ParserState _lastStatus = ParserState . None ;
43
43
private void EvaluateCanExecute ( RubberduckParserState state , Declaration selected )
44
44
{
45
- var currentStatus = _parser . State . Status ;
45
+ var currentStatus = _state . Status ;
46
46
if ( _lastStatus == currentStatus &&
47
47
( selected == null || selected . Equals ( _lastDeclaration ) ) &&
48
48
( selected != null || _lastDeclaration == null ) )
@@ -68,7 +68,7 @@ private void OnSelectionChange(object sender, DeclarationChangedEventArgs e)
68
68
var description = e . Declaration ? . DescriptionString ?? string . Empty ;
69
69
//& renders the next character as if it was an accelerator.
70
70
SetContextSelectionCaption ( caption ? . Replace ( "&" , "&&" ) , refCount , description ) ;
71
- EvaluateCanExecute ( _parser . State , e . Declaration ) ;
71
+ EvaluateCanExecute ( _state , e . Declaration ) ;
72
72
}
73
73
74
74
@@ -81,14 +81,14 @@ private void OnParserStatusMessageUpdate(object sender, RubberduckStatusMessageE
81
81
message = RubberduckUI . ParserState_LoadingReference ;
82
82
}
83
83
84
- SetStatusLabelCaption ( message , _parser . State . ModuleExceptions . Count ) ;
84
+ SetStatusLabelCaption ( message , _state . ModuleExceptions . Count ) ;
85
85
}
86
86
87
87
private void OnParserStateChanged ( object sender , EventArgs e )
88
88
{
89
- _lastStatus = _parser . State . Status ;
90
- EvaluateCanExecute ( _parser . State ) ;
91
- SetStatusLabelCaption ( _parser . State . Status , _parser . State . ModuleExceptions . Count ) ;
89
+ _lastStatus = _state . Status ;
90
+ EvaluateCanExecute ( _state ) ;
91
+ SetStatusLabelCaption ( _state . Status , _state . ModuleExceptions . Count ) ;
92
92
}
93
93
94
94
public void SetStatusLabelCaption ( ParserState state , int ? errorCount = null )
@@ -99,11 +99,19 @@ public void SetStatusLabelCaption(ParserState state, int? errorCount = null)
99
99
100
100
private void SetStatusLabelCaption ( string caption , int ? errorCount = null )
101
101
{
102
- var reparseCommandButton = FindChildByTag ( typeof ( ReparseCommandMenuItem ) . FullName ) as ReparseCommandMenuItem ;
103
- if ( reparseCommandButton == null ) { return ; }
102
+ var reparseCommandButton =
103
+ FindChildByTag ( typeof ( ReparseCommandMenuItem ) . FullName ) as ReparseCommandMenuItem ;
104
+ if ( reparseCommandButton == null )
105
+ {
106
+ return ;
107
+ }
104
108
105
- var showErrorsCommandButton = FindChildByTag ( typeof ( ShowParserErrorsCommandMenuItem ) . FullName ) as ShowParserErrorsCommandMenuItem ;
106
- if ( showErrorsCommandButton == null ) { return ; }
109
+ var showErrorsCommandButton =
110
+ FindChildByTag ( typeof ( ShowParserErrorsCommandMenuItem ) . FullName ) as ShowParserErrorsCommandMenuItem ;
111
+ if ( showErrorsCommandButton == null )
112
+ {
113
+ return ;
114
+ }
107
115
108
116
_uiDispatcher . Invoke ( ( ) =>
109
117
{
@@ -119,7 +127,8 @@ private void SetStatusLabelCaption(string caption, int? errorCount = null)
119
127
}
120
128
catch ( Exception exception )
121
129
{
122
- Logger . Error ( exception , "Exception thrown trying to set the status label caption on the UI thread." ) ;
130
+ Logger . Error ( exception ,
131
+ "Exception thrown trying to set the status label caption on the UI thread." ) ;
123
132
}
124
133
} ) ;
125
134
Localize ( ) ;
@@ -162,8 +171,8 @@ protected virtual void Dispose(bool disposing)
162
171
}
163
172
164
173
_selectionService . SelectionChanged -= OnSelectionChange ;
165
- _parser . State . StateChanged -= OnParserStateChanged ;
166
- _parser . State . StatusMessageUpdate -= OnParserStatusMessageUpdate ;
174
+ _state . StateChangedHighPriority -= OnParserStateChanged ;
175
+ _state . StatusMessageUpdate -= OnParserStatusMessageUpdate ;
167
176
168
177
RemoveCommandBar ( ) ;
169
178
0 commit comments