Skip to content

Commit 6eac8f7

Browse files
committed
#1231 encapsulate field is cancellable
1 parent f250fdf commit 6eac8f7

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

RetailCoder.VBE/Inspections/CodeInspectionQuickFix.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public CodeInspectionQuickFix(ParserRuleContext context, QualifiedSelection sele
2020
public ParserRuleContext Context { get { return _context; } }
2121
public QualifiedSelection Selection { get { return _selection; } }
2222

23+
public bool IsCancelled { get; protected set; }
24+
2325
public abstract void Fix();
2426

2527
/// <summary>

RetailCoder.VBE/Inspections/EncapsulatePublicFieldInspectionResult.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Windows.Forms;
23
using Antlr4.Runtime;
34
using Rubberduck.Parsing.Symbols;
45
using Rubberduck.Parsing.VBA;
@@ -56,6 +57,7 @@ public override void Fix()
5657
var factory = new EncapsulateFieldPresenterFactory(_parseResult, new ActiveCodePaneEditor(vbe, _wrapperFactory), view);
5758
var refactoring = new EncapsulateFieldRefactoring(factory, new ActiveCodePaneEditor(vbe, _wrapperFactory));
5859
refactoring.Refactor(_target);
60+
IsCancelled = view.DialogResult == DialogResult.Cancel;
5961
}
6062
}
6163

RetailCoder.VBE/UI/CodeInspections/InspectionResultsViewModel.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,30 @@ private async void _state_StateChanged(object sender, EventArgs e)
181181

182182
private void ExecuteQuickFixes(IEnumerable<CodeInspectionQuickFix> quickFixes)
183183
{
184-
foreach (var quickFix in quickFixes)
184+
var fixes = quickFixes.ToList();
185+
var completed = 0;
186+
foreach (var quickFix in fixes)
185187
{
186-
quickFix.Fix();
188+
// if we have more than 1 fix to run, one cancelled should cancel all remaining fixes:
189+
if (!fixes.Any(fix => fix.IsCancelled))
190+
{
191+
quickFix.Fix();
192+
if (quickFix.IsCancelled)
193+
{
194+
completed++;
195+
}
196+
}
197+
else
198+
{
199+
break; // no need to keep iterating
200+
}
187201
}
188202

189-
Task.Run(() => ExecuteRefreshCommandAsync(null));
203+
// refresh if any quickfix has completed without cancelling:
204+
if (completed != 0)
205+
{
206+
Task.Run(() => ExecuteRefreshCommandAsync(null));
207+
}
190208
}
191209

192210
private void ExecuteQuickFixCommand(object parameter)

0 commit comments

Comments
 (0)