fix(desktop): avoid AutoNest stock grid hang and name the busy export target

DataGridView.EndEdit() hangs/throws instead of returning false when
CellValidating has already cancelled the pending edit, so an unparsable
stock size froze TryGetPlateOptions. Validate the pending edit text
ourselves before ever asking EndEdit() to commit or discard it.

Also include the nest name in the export-busy message, matching how
the invalid-name rejection already does.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Sonnet 5 committed 2026-10-04 18:24:13 -04:00
1 parent 2a5ebf1e8a
commit 3ba8f4e3b2
2 files changed
+40 -2

No files matched your search

+39 -1
View File
@@ -158,6 +158,7 @@ namespace OpenNest.Forms
);
plateGrid.CellValidating += PlateGrid_CellValidating;
plateGrid.DataError += PlateGrid_DataError;
}
private void LoadDrawings(Nest nest)
@@ -214,7 +215,36 @@ namespace OpenNest.Forms
{
options = new List<PlateOption>();
error = null;
if (!plateGrid.EndEdit())
// CellValidating cancels an unparsable size and leaves the cell in edit mode;
// calling EndEdit() on that cancelled edit hangs/throws instead of returning
// false for it. Catch an unparsable pending edit ourselves first so EndEdit()
// is never asked to commit or discard it.
if (
plateGrid.IsCurrentCellInEditMode
&& plateGrid.CurrentCell != null
&& plateGrid.Columns[plateGrid.CurrentCell.ColumnIndex].DataPropertyName == "Size"
&& plateGrid.EditingControl != null
)
{
var pending = plateGrid.EditingControl.Text;
if (!string.IsNullOrWhiteSpace(pending) && !TryParseSize(pending, out _, out _))
{
error = $"Invalid stock size '{Preview(pending)}'. Enter positive dimensions as W x L.";
return false;
}
}
bool committed;
try
{
committed = plateGrid.EndEdit();
}
catch (InvalidOperationException)
{
committed = false;
}
if (!committed)
{
var value = plateGrid.EditingControl?.Text ?? plateGrid.CurrentCell?.Value?.ToString();
error = $"Invalid stock size '{Preview(value)}'. Enter positive dimensions as W x L.";
@@ -424,6 +454,14 @@ namespace OpenNest.Forms
);
}
// CellValidating and TryGetPlateOptions already surface invalid sizes to the user;
// this only stops the grid from throwing when a commit is forced outside that path
// (e.g. a BindingContext change while a cell is mid-edit).
private void PlateGrid_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
e.ThrowException = false;
}
private DataGridViewItem GetDataGridViewItem(Drawing dwg)
{
var item = new DataGridViewItem();
+1 -1
View File
@@ -520,7 +520,7 @@ namespace OpenNest.Forms
if (isJobBusy() || IsReportTargetBusy(nest))
throw new InvalidOperationException(
"Finish or cancel the current nesting or plate action before exporting the nest report."
$"Finish or cancel the current nesting or plate action before exporting the report for '{nest.Name}'."
);
return new NestReportTargets(nest, $"{nest.Name}.report.pdf");