Skip to content

Commit 6b7f1d7

Browse files
authored
Merge pull request #1834 from Hosch250/Issue1826
Close #1826
2 parents 74ad470 + 89ade92 commit 6b7f1d7

File tree

8 files changed

+57
-54
lines changed

8 files changed

+57
-54
lines changed

RetailCoder.VBE/App.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public App(VBE vbe, IMessageBox messageBox,
7979

8080
_hooks.MessageReceived += _hooks_MessageReceived;
8181
_configService.SettingsChanged += _configService_SettingsChanged;
82-
_configService.LanguageChanged += ConfigServiceLanguageChanged;
8382
_parser.State.StateChanged += Parser_StateChanged;
8483
_parser.State.StatusMessageUpdate += State_StatusMessageUpdate;
8584
_stateBar.Refresh += _stateBar_Refresh;
@@ -156,13 +155,18 @@ private bool ShouldEvaluateCanExecute(Declaration selectedDeclaration, ParserSta
156155
(selectedDeclaration == null && _lastSelectedDeclaration != null);
157156
}
158157

159-
private void _configService_SettingsChanged(object sender, EventArgs e)
158+
private void _configService_SettingsChanged(object sender, ConfigurationChangedEventArgs e)
160159
{
161160
_config = _configService.LoadConfiguration();
162161
_hooks.HookHotkeys();
163162
// also updates the ShortcutKey text
164163
_appMenus.Localize();
165164
UpdateLoggingLevel();
165+
166+
if (e.LanguageChanged)
167+
{
168+
LoadConfig();
169+
}
166170
}
167171

168172
private void UpdateLoggingLevel()
@@ -172,7 +176,7 @@ private void UpdateLoggingLevel()
172176

173177
public void Startup()
174178
{
175-
CleanReloadConfig();
179+
LoadConfig();
176180
_appMenus.Initialize();
177181
_hooks.HookHotkeys(); // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts
178182
_appMenus.Localize();
@@ -417,16 +421,6 @@ private void Parser_StateChanged(object sender, EventArgs e)
417421
_appMenus.EvaluateCanExecute(_parser.State);
418422
}
419423

420-
private void CleanReloadConfig()
421-
{
422-
LoadConfig();
423-
}
424-
425-
private void ConfigServiceLanguageChanged(object sender, EventArgs e)
426-
{
427-
CleanReloadConfig();
428-
}
429-
430424
private void LoadConfig()
431425
{
432426
_logger.Debug("Loading configuration");
@@ -488,7 +482,6 @@ public void Dispose()
488482
if (_configService != null)
489483
{
490484
_configService.SettingsChanged -= _configService_SettingsChanged;
491-
_configService.LanguageChanged -= ConfigServiceLanguageChanged;
492485
_configService = null;
493486
}
494487

RetailCoder.VBE/AutoSave/AutoSave.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private void Dispose(bool disposing)
6969

7070
if (_configService != null)
7171
{
72-
_configService.LanguageChanged -= ConfigServiceSettingsChanged;
72+
_configService.SettingsChanged -= ConfigServiceSettingsChanged;
7373
}
7474

7575
if (_timer != null)

RetailCoder.VBE/Inspections/Inspector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Inspector(IGeneralConfigService configService, IEnumerable<IInspection> i
2424
_inspections = inspections;
2525

2626
_configService = configService;
27-
configService.LanguageChanged += ConfigServiceLanguageChanged;
27+
configService.SettingsChanged += ConfigServiceLanguageChanged;
2828
}
2929

3030
private void ConfigServiceLanguageChanged(object sender, EventArgs e)
@@ -121,7 +121,7 @@ public void Dispose()
121121
{
122122
if (_configService != null)
123123
{
124-
_configService.LanguageChanged -= ConfigServiceLanguageChanged;
124+
_configService.SettingsChanged -= ConfigServiceLanguageChanged;
125125
}
126126
}
127127
}

RetailCoder.VBE/Settings/ConfigurationLoader.cs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66

77
namespace Rubberduck.Settings
88
{
9+
public class ConfigurationChangedEventArgs : EventArgs
10+
{
11+
public bool LanguageChanged { get; private set; }
12+
public bool InspectionSettingsChanged { get; private set; }
13+
14+
public ConfigurationChangedEventArgs(bool languageChanged, bool inspectionSettingsChanged)
15+
{
16+
LanguageChanged = languageChanged;
17+
InspectionSettingsChanged = inspectionSettingsChanged;
18+
}
19+
}
20+
921
public interface IGeneralConfigService : IConfigurationService<Configuration>
1022
{
1123
Configuration GetDefaultConfiguration();
@@ -88,42 +100,25 @@ public Configuration GetDefaultConfiguration()
88100
)
89101
};
90102
}
91-
92-
103+
93104
public void SaveConfiguration(Configuration toSerialize)
94105
{
106+
var langChanged = _generalProvider.Create().Language.Code != toSerialize.UserSettings.GeneralSettings.Language.Code;
107+
var oldInspectionSettings = _inspectionProvider.Create(_inspections).CodeInspections.Select(s => Tuple.Create(s.Name, s.Severity));
108+
var newInspectionSettings = toSerialize.UserSettings.CodeInspectionSettings.CodeInspections.Select(s => Tuple.Create(s.Name, s.Severity));
109+
95110
_generalProvider.Save(toSerialize.UserSettings.GeneralSettings);
96111
_hotkeyProvider.Save(toSerialize.UserSettings.HotkeySettings);
97112
_todoProvider.Save(toSerialize.UserSettings.ToDoListSettings);
98113
_inspectionProvider.Save(toSerialize.UserSettings.CodeInspectionSettings);
99114
_unitTestProvider.Save(toSerialize.UserSettings.UnitTestSettings);
100115
_indenterProvider.Save(toSerialize.UserSettings.IndenterSettings);
101-
}
102-
103-
public void SaveConfiguration(Configuration toSerialize, bool languageChanged)
104-
{
105-
SaveConfiguration(toSerialize);
106-
107-
if (languageChanged)
108-
{
109-
OnLanguageChanged(EventArgs.Empty);
110-
}
111-
112-
OnSettingsChanged(EventArgs.Empty);
113-
}
114116

115-
public event EventHandler LanguageChanged;
116-
protected virtual void OnLanguageChanged(EventArgs e)
117-
{
118-
var handler = LanguageChanged;
119-
if (handler != null)
120-
{
121-
handler(this, e);
122-
}
117+
OnSettingsChanged(new ConfigurationChangedEventArgs(langChanged, !oldInspectionSettings.SequenceEqual(newInspectionSettings)));
123118
}
124119

125-
public event EventHandler SettingsChanged;
126-
protected virtual void OnSettingsChanged(EventArgs e)
120+
public event EventHandler<ConfigurationChangedEventArgs> SettingsChanged;
121+
protected virtual void OnSettingsChanged(ConfigurationChangedEventArgs e)
127122
{
128123
var handler = SettingsChanged;
129124
if (handler != null)

RetailCoder.VBE/Settings/GeneralConfigProvider.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ public interface IGeneralConfigProvider
99
GeneralSettings CreateDefaults();
1010

1111
void Save(GeneralSettings settings);
12-
13-
event EventHandler LanguageChanged;
14-
event EventHandler AutoSaveSettingsChanged;
1512
}
1613

1714
public class GeneralConfigProvider : IGeneralConfigProvider

RetailCoder.VBE/Settings/IConfigurationService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ public interface IConfigurationService<T>
66
{
77
T LoadConfiguration();
88
void SaveConfiguration(T toSerialize);
9-
void SaveConfiguration(T toSerialize, bool languageChanged);
10-
event EventHandler LanguageChanged;
11-
event EventHandler SettingsChanged;
9+
event EventHandler<ConfigurationChangedEventArgs> SettingsChanged;
1210
}
1311
}

RetailCoder.VBE/UI/Inspections/InspectionResultsViewModel.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ public InspectionResultsViewModel(RubberduckParserState state, IInspector inspec
4242
_clipboard = clipboard;
4343
_configService = configService;
4444
_operatingSystem = operatingSystem;
45-
_refreshCommand = new DelegateCommand(async param => await Task.Run(() => ExecuteRefreshCommandAsync(param)), CanExecuteRefreshCommand);
45+
_refreshCommand = new DelegateCommand(async param => await Task.Run(() => ExecuteRefreshCommandAsync()), CanExecuteRefreshCommand);
4646
_disableInspectionCommand = new DelegateCommand(ExecuteDisableInspectionCommand);
4747
_quickFixCommand = new DelegateCommand(ExecuteQuickFixCommand, CanExecuteQuickFixCommand);
4848
_quickFixInModuleCommand = new DelegateCommand(ExecuteQuickFixInModuleCommand);
4949
_quickFixInProjectCommand = new DelegateCommand(ExecuteQuickFixInProjectCommand);
5050
_copyResultsCommand = new DelegateCommand(ExecuteCopyResultsCommand, CanExecuteCopyResultsCommand);
5151
_openSettingsCommand = new DelegateCommand(OpenSettings);
5252

53+
_configService.SettingsChanged += _configService_SettingsChanged;
54+
5355
_setInspectionTypeGroupingCommand = new DelegateCommand(param =>
5456
{
5557
GroupByInspectionType = (bool)param;
@@ -65,6 +67,14 @@ public InspectionResultsViewModel(RubberduckParserState state, IInspector inspec
6567
_state.StateChanged += _state_StateChanged;
6668
}
6769

70+
private void _configService_SettingsChanged(object sender, ConfigurationChangedEventArgs e)
71+
{
72+
if (e.InspectionSettingsChanged)
73+
{
74+
RefreshInspections();
75+
}
76+
}
77+
6878
private ObservableCollection<ICodeInspectionResult> _results = new ObservableCollection<ICodeInspectionResult>();
6979
public ObservableCollection<ICodeInspectionResult> Results
7080
{
@@ -219,7 +229,7 @@ private set
219229
private bool _isBusy;
220230
public bool IsBusy { get { return _isBusy; } set { _isBusy = value; OnPropertyChanged(); } }
221231

222-
private async void ExecuteRefreshCommandAsync(object parameter)
232+
private async void ExecuteRefreshCommandAsync()
223233
{
224234
CanRefresh = _vbe.HostApplication() != null && _state.IsDirty();
225235
if (!CanRefresh)
@@ -239,7 +249,7 @@ private bool CanExecuteRefreshCommand(object parameter)
239249
return !IsBusy && _state.IsDirty();
240250
}
241251

242-
private async void _state_StateChanged(object sender, EventArgs e)
252+
private void _state_StateChanged(object sender, EventArgs e)
243253
{
244254
_logger.Debug("InspectionResultsViewModel handles StateChanged...");
245255
if (_state.Status != ParserState.Ready)
@@ -248,6 +258,11 @@ private async void _state_StateChanged(object sender, EventArgs e)
248258
return;
249259
}
250260

261+
RefreshInspections();
262+
}
263+
264+
private async void RefreshInspections()
265+
{
251266
_logger.Debug("Running code inspections...");
252267
IsBusy = true;
253268

@@ -301,7 +316,7 @@ private void ExecuteQuickFixes(IEnumerable<CodeInspectionQuickFix> quickFixes)
301316
// refresh if any quickfix has completed without cancelling:
302317
if (completed != 0 && cancelled < completed)
303318
{
304-
Task.Run(() => ExecuteRefreshCommandAsync(null));
319+
Task.Run(() => ExecuteRefreshCommandAsync());
305320
}
306321
}
307322

@@ -370,7 +385,7 @@ private void ExecuteDisableInspectionCommand(object parameter)
370385
var setting = config.UserSettings.CodeInspectionSettings.CodeInspections.Single(e => e.Name == _selectedInspection.Name);
371386
setting.Severity = CodeInspectionSeverity.DoNotShow;
372387

373-
Task.Run(() => _configService.SaveConfiguration(config)).ContinueWith(t => ExecuteRefreshCommandAsync(null));
388+
Task.Run(() => _configService.SaveConfiguration(config)).ContinueWith(t => ExecuteRefreshCommandAsync());
374389
}
375390

376391
private bool _canDisableInspection;
@@ -441,6 +456,11 @@ public void Dispose()
441456
{
442457
_state.StateChanged -= _state_StateChanged;
443458
}
459+
460+
if (_configService != null)
461+
{
462+
_configService.SettingsChanged -= _configService_SettingsChanged;
463+
}
444464
}
445465
}
446466
}

RetailCoder.VBE/UI/Settings/SettingsControlViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private void SaveConfig()
7676
vm.UpdateConfig(_config);
7777
}
7878

79-
_configService.SaveConfiguration(_config, _config.UserSettings.GeneralSettings.Language.Code != oldLangCode);
79+
_configService.SaveConfiguration(_config);
8080
}
8181

8282
private void CloseWindow()

0 commit comments

Comments
 (0)