4
4
using System . Linq ;
5
5
using System . Runtime . InteropServices ;
6
6
using Rubberduck . Resources ;
7
- using Rubberduck . Parsing ;
8
7
using Rubberduck . Parsing . Symbols ;
9
8
using Rubberduck . Parsing . UIContext ;
10
9
using Rubberduck . Parsing . VBA ;
@@ -15,18 +14,18 @@ namespace Rubberduck.UI.Command.MenuItems.CommandBars
15
14
public class RubberduckCommandBar : AppCommandBarBase , IDisposable
16
15
{
17
16
private readonly IContextFormatter _formatter ;
18
- private readonly IParseCoordinator _parser ;
17
+ private readonly RubberduckParserState _state ;
19
18
private readonly ISelectionChangeService _selectionService ;
20
19
21
- 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 )
22
21
: base ( "Rubberduck" , CommandBarPosition . Top , items , uiDispatcher )
23
22
{
24
- _parser = parser ;
23
+ _state = state ;
25
24
_formatter = formatter ;
26
25
_selectionService = selectionService ;
27
26
28
- _parser . State . StateChanged += OnParserStateChanged ;
29
- _parser . State . StatusMessageUpdate += OnParserStatusMessageUpdate ;
27
+ _state . StateChangedHighPriority += OnParserStateChanged ;
28
+ _state . StatusMessageUpdate += OnParserStatusMessageUpdate ;
30
29
_selectionService . SelectionChanged += OnSelectionChange ;
31
30
}
32
31
@@ -36,14 +35,14 @@ public override void Initialize()
36
35
{
37
36
base . Initialize ( ) ;
38
37
SetStatusLabelCaption ( ParserState . Pending ) ;
39
- EvaluateCanExecute ( _parser . State ) ;
38
+ EvaluateCanExecute ( _state ) ;
40
39
}
41
40
42
41
private Declaration _lastDeclaration ;
43
42
private ParserState _lastStatus = ParserState . None ;
44
43
private void EvaluateCanExecute ( RubberduckParserState state , Declaration selected )
45
44
{
46
- var currentStatus = _parser . State . Status ;
45
+ var currentStatus = _state . Status ;
47
46
if ( _lastStatus == currentStatus &&
48
47
( selected == null || selected . Equals ( _lastDeclaration ) ) &&
49
48
( selected != null || _lastDeclaration == null ) )
@@ -69,7 +68,7 @@ private void OnSelectionChange(object sender, DeclarationChangedEventArgs e)
69
68
var description = e . Declaration ? . DescriptionString ?? string . Empty ;
70
69
//& renders the next character as if it was an accelerator.
71
70
SetContextSelectionCaption ( caption ? . Replace ( "&" , "&&" ) , refCount , description ) ;
72
- EvaluateCanExecute ( _parser . State , e . Declaration ) ;
71
+ EvaluateCanExecute ( _state , e . Declaration ) ;
73
72
}
74
73
75
74
@@ -82,14 +81,14 @@ private void OnParserStatusMessageUpdate(object sender, RubberduckStatusMessageE
82
81
message = RubberduckUI . ParserState_LoadingReference ;
83
82
}
84
83
85
- SetStatusLabelCaption ( message , _parser . State . ModuleExceptions . Count ) ;
84
+ SetStatusLabelCaption ( message , _state . ModuleExceptions . Count ) ;
86
85
}
87
86
88
87
private void OnParserStateChanged ( object sender , EventArgs e )
89
88
{
90
- _lastStatus = _parser . State . Status ;
91
- EvaluateCanExecute ( _parser . State ) ;
92
- SetStatusLabelCaption ( _parser . State . Status , _parser . State . ModuleExceptions . Count ) ;
89
+ _lastStatus = _state . Status ;
90
+ EvaluateCanExecute ( _state ) ;
91
+ SetStatusLabelCaption ( _state . Status , _state . ModuleExceptions . Count ) ;
93
92
}
94
93
95
94
public void SetStatusLabelCaption ( ParserState state , int ? errorCount = null )
@@ -182,8 +181,8 @@ protected virtual void Dispose(bool disposing)
182
181
}
183
182
184
183
_selectionService . SelectionChanged -= OnSelectionChange ;
185
- _parser . State . StateChanged -= OnParserStateChanged ;
186
- _parser . State . StatusMessageUpdate -= OnParserStatusMessageUpdate ;
184
+ _state . StateChanged -= OnParserStateChanged ;
185
+ _state . StatusMessageUpdate -= OnParserStatusMessageUpdate ;
187
186
188
187
RemoveCommandBar ( ) ;
189
188
0 commit comments