Skip to content

Commit 7a05cc4

Browse files
authored
Merge pull request #3821 from bclothier/CompileBeforeParseFix
Work-around for "Compile on demand" VBE setting interfering with RD's "compile on parse" setting.
2 parents 017d134 + 3de091b commit 7a05cc4

17 files changed

+406
-46
lines changed

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@
501501
<Compile Include="UnitTesting\Stubs\Beep.cs" />
502502
<Compile Include="UnitTesting\IStub.cs" />
503503
<Compile Include="UnitTesting\StubBase.cs" />
504+
<Compile Include="VBERuntime\RegistryWrapper.cs" />
505+
<Compile Include="VBERuntime\IVBESettings.cs" />
506+
<Compile Include="VBERuntime\VBESettings.cs" />
504507
<Compile Include="VersionCheck\IVersionCheck.cs" />
505508
<Compile Include="UI\Command\MenuItems\CommandBars\AppCommandBarBase.cs" />
506509
<Compile Include="UI\Command\MenuItems\CommandBars\ContextSelectionLabelMenuItem.cs" />

RetailCoder.VBE/UI/Command/ReparseCommand.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Rubberduck.Settings;
99
using Rubberduck.SettingsProvider;
1010
using Rubberduck.UI.CodeExplorer.Commands;
11+
using Rubberduck.VBERuntime;
1112
using Rubberduck.VBEditor.ComManagement.TypeLibsAPI;
1213
using Rubberduck.VBEditor.SafeComWrappers;
1314
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
@@ -20,13 +21,15 @@ public class ReparseCommand : CommandBase
2021
{
2122
private readonly IVBE _vbe;
2223
private readonly IVBETypeLibsAPI _typeLibApi;
24+
private readonly IVBESettings _vbeSettings;
2325
private readonly IMessageBox _messageBox;
2426
private readonly RubberduckParserState _state;
2527
private readonly GeneralSettings _settings;
2628

27-
public ReparseCommand(IVBE vbe, IConfigProvider<GeneralSettings> settingsProvider, RubberduckParserState state, IVBETypeLibsAPI typeLibApi, IMessageBox messageBox) : base(LogManager.GetCurrentClassLogger())
29+
public ReparseCommand(IVBE vbe, IConfigProvider<GeneralSettings> settingsProvider, RubberduckParserState state, IVBETypeLibsAPI typeLibApi, IVBESettings vbeSettings, IMessageBox messageBox) : base(LogManager.GetCurrentClassLogger())
2830
{
2931
_vbe = vbe;
32+
_vbeSettings = vbeSettings;
3033
_typeLibApi = typeLibApi;
3134
_state = state;
3235
_settings = settingsProvider.Create();
@@ -46,7 +49,12 @@ protected override void OnExecute(object parameter)
4649
{
4750
if (_settings.CompileBeforeParse)
4851
{
49-
if (CompileAllProjects(out var failedNames))
52+
if (!VerifyCompileOnDemand())
53+
{
54+
return;
55+
}
56+
57+
if (AreAllProjectsCompiled(out var failedNames))
5058
{
5159
if (!PromptUserToContinue(failedNames))
5260
{
@@ -57,7 +65,19 @@ protected override void OnExecute(object parameter)
5765
_state.OnParseRequested(this);
5866
}
5967

60-
private bool CompileAllProjects(out List<string> failedNames)
68+
private bool VerifyCompileOnDemand()
69+
{
70+
if (_vbeSettings.CompileOnDemand)
71+
{
72+
return DialogResult.Yes == _messageBox.Show(RubberduckUI.Command_Reparse_CompileOnDemandEnabled,
73+
RubberduckUI.Command_Reparse_CompileOnDemandEnabled_Caption, MessageBoxButtons.YesNo,
74+
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
75+
}
76+
77+
return true;
78+
}
79+
80+
private bool AreAllProjectsCompiled(out List<string> failedNames)
6181
{
6282
failedNames = new List<string>();
6383
using (var projects = _vbe.VBProjects)

RetailCoder.VBE/UI/Command/SettingsCommand.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ namespace Rubberduck.UI.Command
1212
[ComVisible(false)]
1313
public class SettingsCommand : CommandBase
1414
{
15-
private readonly IGeneralConfigService _service;
16-
private readonly IOperatingSystem _operatingSystem;
17-
public SettingsCommand(IGeneralConfigService service, IOperatingSystem operatingSystem) : base(LogManager.GetCurrentClassLogger())
15+
private readonly ISettingsFormFactory _settingsFormFactory;
16+
17+
public SettingsCommand(ISettingsFormFactory settingsFormFactory) : base(LogManager.GetCurrentClassLogger())
1818
{
19-
_service = service;
20-
_operatingSystem = operatingSystem;
19+
_settingsFormFactory = settingsFormFactory;
2120
}
2221

2322
protected override void OnExecute(object parameter)
2423
{
25-
using (var window = new SettingsForm(_service, _operatingSystem))
24+
using (var window = _settingsFormFactory.Create())
2625
{
2726
window.ShowDialog();
27+
_settingsFormFactory.Release(window);
2828
}
2929
}
3030
}

RetailCoder.VBE/UI/Inspections/InspectionResultsViewModel.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ public sealed class InspectionResultsViewModel : ViewModelBase, INavigateSelecti
4040
private readonly IQuickFixProvider _quickFixProvider;
4141
private readonly IClipboardWriter _clipboard;
4242
private readonly IGeneralConfigService _configService;
43-
private readonly IOperatingSystem _operatingSystem;
43+
private readonly ISettingsFormFactory _settingsFormFactory;
4444

4545
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
4646

4747
public InspectionResultsViewModel(RubberduckParserState state, IInspector inspector, IQuickFixProvider quickFixProvider,
4848
INavigateCommand navigateCommand, ReparseCommand reparseCommand,
49-
IClipboardWriter clipboard, IGeneralConfigService configService, IOperatingSystem operatingSystem)
49+
IClipboardWriter clipboard, IGeneralConfigService configService, ISettingsFormFactory settingsFormFactory)
5050
{
5151
_state = state;
5252
_inspector = inspector;
5353
_quickFixProvider = quickFixProvider;
5454
NavigateCommand = navigateCommand;
5555
_clipboard = clipboard;
5656
_configService = configService;
57-
_operatingSystem = operatingSystem;
57+
_settingsFormFactory = settingsFormFactory;
5858
RefreshCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(),
5959
o =>
6060
{
@@ -238,9 +238,10 @@ public bool GroupByLocation
238238

239239
private void OpenSettings(object param)
240240
{
241-
using (var window = new SettingsForm(_configService, _operatingSystem, SettingsViews.InspectionSettings))
241+
using (var window = _settingsFormFactory.Create())
242242
{
243243
window.ShowDialog();
244+
_settingsFormFactory.Release(window);
244245
}
245246
}
246247

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,4 +1795,18 @@ Would you like to import them to Rubberduck?</value>
17951795
<data name="ParserState_UnexpectedError" xml:space="preserve">
17961796
<value>Unexpected Error</value>
17971797
</data>
1798+
<data name="Command_Reparse_CompileOnDemandEnabled" xml:space="preserve">
1799+
<value>The VBEsetting "Compile On Demand" is currently enabled. This is not recommended as this may hide compilation errors and cause problems with parsing. Do you want to parse anyway?</value>
1800+
</data>
1801+
<data name="Command_Reparse_CompileOnDemandEnabled_Caption" xml:space="preserve">
1802+
<value>Compile On Demand Setting</value>
1803+
</data>
1804+
<data name="GeneralSettings_CompileBeforeParse_WarnCompileOnDemandEnabled" xml:space="preserve">
1805+
<value>The VBE setting "Compile On Demand" is currently enabled. It is strongly recommended that you disable the setting via the VBE Options dialog under General tab in order to use the Compile Before Parse feature. Do you want to disable it now?
1806+
1807+
NOTE: Restart is required for the setting to take effect.</value>
1808+
</data>
1809+
<data name="GeneralSettings_CompileBeforeParse_WarnCompileOnDemandEnabled_Caption" xml:space="preserve">
1810+
<value>Compile On Demand currently enabled</value>
1811+
</data>
17981812
</root>

RetailCoder.VBE/UI/Settings/GeneralSettingsViewModel.cs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.Linq;
5+
using System.Windows.Forms;
56
using Rubberduck.Settings;
67
using Rubberduck.Common;
78
using NLog;
89
using Rubberduck.Parsing.Common;
910
using Rubberduck.Root;
1011
using Rubberduck.SettingsProvider;
1112
using Rubberduck.UI.Command;
13+
using Rubberduck.VBERuntime;
1214

1315
namespace Rubberduck.UI.Settings
1416
{
@@ -21,11 +23,17 @@ public enum DelimiterOptions
2123
public class GeneralSettingsViewModel : SettingsViewModelBase, ISettingsViewModel
2224
{
2325
private readonly IOperatingSystem _operatingSystem;
26+
private readonly IMessageBox _messageBox;
27+
private readonly IVBESettings _vbeSettings;
28+
2429
private bool _indenterPrompted;
2530

26-
public GeneralSettingsViewModel(Configuration config, IOperatingSystem operatingSystem)
31+
public GeneralSettingsViewModel(Configuration config, IOperatingSystem operatingSystem, IMessageBox messageBox, IVBESettings vbeSettings)
2732
{
2833
_operatingSystem = operatingSystem;
34+
_messageBox = messageBox;
35+
_vbeSettings = vbeSettings;
36+
2937
Languages = new ObservableCollection<DisplayLanguageSetting>(
3038
new[]
3139
{
@@ -125,20 +133,45 @@ public bool CheckVersionAtStartup
125133
}
126134

127135
private bool _compileBeforeParse;
128-
129136
public bool CompileBeforeParse
130137
{
131138
get => _compileBeforeParse;
132139
set
133140
{
134-
if (_compileBeforeParse != value)
141+
if (_compileBeforeParse == value)
135142
{
136-
_compileBeforeParse = value;
137-
OnPropertyChanged();
143+
return;
138144
}
145+
146+
if (value && _vbeSettings.CompileOnDemand)
147+
{
148+
if(!SynchronizeVBESettings())
149+
{
150+
return;
151+
}
152+
}
153+
154+
_compileBeforeParse = value;
155+
OnPropertyChanged();
139156
}
140157
}
141158

159+
private bool SynchronizeVBESettings()
160+
{
161+
var result = _messageBox.Show(RubberduckUI.GeneralSettings_CompileBeforeParse_WarnCompileOnDemandEnabled,
162+
RubberduckUI.GeneralSettings_CompileBeforeParse_WarnCompileOnDemandEnabled_Caption, MessageBoxButtons.YesNo,
163+
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
164+
165+
if (result == DialogResult.No)
166+
{
167+
return false;
168+
}
169+
170+
_vbeSettings.CompileOnDemand = false;
171+
_vbeSettings.BackGroundCompile = false;
172+
return true;
173+
}
174+
142175
private int _autoSavePeriod;
143176
public int AutoSavePeriod
144177
{

RetailCoder.VBE/UI/Settings/SettingsForm.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
using System.Windows.Forms;
22
using Rubberduck.Settings;
33
using Rubberduck.Common;
4+
using Rubberduck.VBERuntime;
45

56
namespace Rubberduck.UI.Settings
67
{
8+
public interface ISettingsFormFactory
9+
{
10+
SettingsForm Create();
11+
void Release(SettingsForm form);
12+
}
13+
714
public partial class SettingsForm : Form
815
{
916
public SettingsForm()
1017
{
1118
InitializeComponent();
1219
}
1320

14-
public SettingsForm(IGeneralConfigService configService, IOperatingSystem operatingSystem, SettingsViews activeView = SettingsViews.GeneralSettings) : this()
21+
public SettingsForm(IGeneralConfigService configService, IOperatingSystem operatingSystem, IMessageBox messageBox, IVBESettings vbeSettings, SettingsViews activeView = SettingsViews.GeneralSettings) : this()
1522
{
1623
var config = configService.LoadConfiguration();
1724

1825
ViewModel = new SettingsControlViewModel(configService,
1926
config,
2027
new SettingsView
2128
{
22-
Control = new GeneralSettings(new GeneralSettingsViewModel(config, operatingSystem)),
29+
Control = new GeneralSettings(new GeneralSettingsViewModel(config, operatingSystem, messageBox, vbeSettings)),
2330
View = SettingsViews.GeneralSettings
2431
},
2532
new SettingsView

RetailCoder.VBE/UI/ToDoItems/ToDoExplorerViewModel.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public sealed class ToDoExplorerViewModel : ViewModelBase, INavigateSelection, I
2121
{
2222
private readonly RubberduckParserState _state;
2323
private readonly IGeneralConfigService _configService;
24-
private readonly IOperatingSystem _operatingSystem;
24+
private readonly ISettingsFormFactory _settingsFormFactory;
2525

26-
public ToDoExplorerViewModel(RubberduckParserState state, IGeneralConfigService configService, IOperatingSystem operatingSystem)
26+
public ToDoExplorerViewModel(RubberduckParserState state, IGeneralConfigService configService, ISettingsFormFactory settingsFormFactory)
2727
{
2828
_state = state;
2929
_configService = configService;
30-
_operatingSystem = operatingSystem;
30+
_settingsFormFactory = settingsFormFactory;
3131
_state.StateChanged += HandleStateChanged;
3232

3333
SetMarkerGroupingCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), param =>
@@ -222,9 +222,10 @@ public CommandBase OpenTodoSettings
222222
}
223223
return _openTodoSettings = new DelegateCommand(LogManager.GetCurrentClassLogger(), _ =>
224224
{
225-
using (var window = new SettingsForm(_configService, _operatingSystem, SettingsViews.TodoSettings))
225+
using (var window = _settingsFormFactory.Create())
226226
{
227227
window.ShowDialog();
228+
_settingsFormFactory.Release(window);
228229
}
229230
});
230231
}

RetailCoder.VBE/UI/UnitTesting/TestExplorerViewModel.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ public class TestExplorerViewModel : ViewModelBase, INavigateSelection, IDisposa
2222
private readonly RubberduckParserState _state;
2323
private readonly ITestEngine _testEngine;
2424
private readonly IClipboardWriter _clipboard;
25-
private readonly IGeneralConfigService _configService;
26-
private readonly IOperatingSystem _operatingSystem;
25+
private readonly ISettingsFormFactory _settingsFormFactory;
26+
//private readonly IGeneralConfigService _configService;
27+
//private readonly IOperatingSystem _operatingSystem;
2728

2829
public TestExplorerViewModel(IVBE vbe,
2930
RubberduckParserState state,
3031
ITestEngine testEngine,
3132
TestExplorerModel model,
3233
IClipboardWriter clipboard,
3334
IGeneralConfigService configService,
34-
IOperatingSystem operatingSystem)
35+
ISettingsFormFactory settingsFormFactory)
3536
{
3637
_vbe = vbe;
3738
_state = state;
3839
_testEngine = testEngine;
3940
_testEngine.TestCompleted += TestEngineTestCompleted;
4041
Model = model;
4142
_clipboard = clipboard;
42-
_configService = configService;
43-
_operatingSystem = operatingSystem;
43+
_settingsFormFactory = settingsFormFactory;
4444

4545
_navigateCommand = new NavigateCommand(_state.ProjectsProvider);
4646

@@ -197,9 +197,10 @@ public bool GroupByLocation
197197

198198
private void OpenSettings(object param)
199199
{
200-
using (var window = new SettingsForm(_configService, _operatingSystem, SettingsViews.UnitTestSettings))
200+
using (var window = _settingsFormFactory.Create())
201201
{
202202
window.ShowDialog();
203+
_settingsFormFactory.Release(window);
203204
}
204205
}
205206

0 commit comments

Comments
 (0)