@@ -30,6 +30,8 @@ public class App : IDisposable
30
30
private RubberduckMenu _menu ;
31
31
private FormContextMenu _formContextMenu ;
32
32
private CodeInspectionsToolbar _codeInspectionsToolbar ;
33
+ private bool displayToolbar = false ;
34
+ private Point toolbarCoords = new Point ( - 1 , - 1 ) ;
33
35
34
36
public App ( VBE vbe , AddIn addIn )
35
37
{
@@ -42,11 +44,19 @@ public App(VBE vbe, AddIn addIn)
42
44
_editor = new ActiveCodePaneEditor ( vbe ) ;
43
45
44
46
LoadConfig ( ) ;
47
+
48
+ CleanUp ( ) ;
49
+
50
+ Setup ( ) ;
45
51
}
46
52
47
53
private void _configService_SettingsChanged ( object sender , EventArgs e )
48
54
{
49
55
LoadConfig ( ) ;
56
+
57
+ CleanUp ( ) ;
58
+
59
+ Setup ( ) ;
50
60
}
51
61
52
62
private void LoadConfig ( )
@@ -64,48 +74,15 @@ private void LoadConfig()
64
74
_config . UserSettings . LanguageSetting . Code = currentCulture . Name ;
65
75
_configService . SaveConfiguration ( _config ) ;
66
76
}
77
+ }
67
78
68
- if ( _menu != null )
69
- {
70
- _menu . Dispose ( ) ;
71
- }
72
-
73
- if ( _formContextMenu != null )
74
- {
75
- _formContextMenu . Dispose ( ) ;
76
- }
77
-
78
- var displayToolbar = false ;
79
- var toolbarCoords = new Point ( - 1 , - 1 ) ;
80
- if ( _codeInspectionsToolbar != null )
81
- {
82
- displayToolbar = _codeInspectionsToolbar . ToolbarVisible ;
83
- toolbarCoords = _codeInspectionsToolbar . ToolbarCoords ;
84
- _codeInspectionsToolbar . Dispose ( ) ;
85
- }
86
-
87
- if ( _inspector != null )
88
- {
89
- _inspector . Dispose ( ) ;
90
- }
91
-
92
- if ( _parserErrorsPresenter != null )
93
- {
94
- _parserErrorsPresenter . Dispose ( ) ;
95
- }
96
-
97
- if ( _parser != null )
98
- {
99
- _parser . ParseStarted -= _parser_ParseStarted ;
100
- _parser . ParserError -= _parser_ParserError ;
101
- }
79
+ private void Setup ( )
80
+ {
102
81
_parser = new RubberduckParser ( ) ;
103
82
_parser . ParseStarted += _parser_ParseStarted ;
104
83
_parser . ParserError += _parser_ParserError ;
105
84
106
- _inspections = _configService . GetImplementedCodeInspections ( ) ;
107
- _inspector = new Inspector ( _parser , _inspections ) ;
108
- EnableCodeInspections ( _config ) ;
85
+ _inspector = new Inspector ( _parser , _configService ) ;
109
86
110
87
_parserErrorsPresenter = new ParserErrorsPresenter ( _vbe , _addIn ) ;
111
88
@@ -136,20 +113,6 @@ private void _parser_ParserError(object sender, ParseErrorEventArgs e)
136
113
_parserErrorsPresenter . Show ( ) ;
137
114
}
138
115
139
- private void EnableCodeInspections ( Configuration config )
140
- {
141
- foreach ( var inspection in _inspections )
142
- {
143
- foreach ( var setting in config . UserSettings . CodeInspectionSettings . CodeInspections )
144
- {
145
- if ( inspection . Description == setting . Description )
146
- {
147
- inspection . Severity = setting . Severity ;
148
- }
149
- }
150
- }
151
- }
152
-
153
116
public void Dispose ( )
154
117
{
155
118
Dispose ( true ) ;
@@ -159,6 +122,11 @@ protected virtual void Dispose(bool disposing)
159
122
{
160
123
if ( ! disposing ) { return ; }
161
124
125
+ CleanUp ( ) ;
126
+ }
127
+
128
+ private void CleanUp ( )
129
+ {
162
130
if ( _menu != null )
163
131
{
164
132
_menu . Dispose ( ) ;
@@ -171,6 +139,8 @@ protected virtual void Dispose(bool disposing)
171
139
172
140
if ( _codeInspectionsToolbar != null )
173
141
{
142
+ displayToolbar = _codeInspectionsToolbar . ToolbarVisible ;
143
+ toolbarCoords = _codeInspectionsToolbar . ToolbarCoords ;
174
144
_codeInspectionsToolbar . Dispose ( ) ;
175
145
}
176
146
@@ -183,6 +153,12 @@ protected virtual void Dispose(bool disposing)
183
153
{
184
154
_parserErrorsPresenter . Dispose ( ) ;
185
155
}
156
+
157
+ if ( _parser != null )
158
+ {
159
+ _parser . ParseStarted -= _parser_ParseStarted ;
160
+ _parser . ParserError -= _parser_ParserError ;
161
+ }
186
162
}
187
163
}
188
164
}
0 commit comments