mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-07 03:32:13 -04:00
fix(ui): show the newly selected plate when a Plates row is chosen
The plate preview read DataGridView.CurrentRow in SelectionChanged, but that event runs before CurrentCell moves, so CurrentRow still named the previous row. Choosing a row showed the plate that had been selected before it, and the next-plate button snapped the preview back to the old plate. Read the selected row instead. The Windows job of run 37341610182 caught it: PlatePreview_StepsThroughThePlates_AndFollowsThePlatesTable expected "Plate 2 of 2" after the next-plate button and got "Plate 1 of 2". The test now also checks that the selected row follows the button.
This commit is contained in:
1 parent
da0c54f280
commit
3a8419e6e9
2 files changed
+8
-3
No files matched your search
@@ -85,6 +85,7 @@ public class SavedNestsFormTests
|
||||
Assert.Equal("Plate 2 of 2", label.Text);
|
||||
Assert.Single(preview.Plate.Parts);
|
||||
Assert.Equal(1, plates.CurrentRow!.Index);
|
||||
Assert.Equal(1, plates.SelectedRows[0].Index);
|
||||
Assert.True(previous.Enabled);
|
||||
Assert.False(next.Enabled);
|
||||
|
||||
|
||||
@@ -139,8 +139,10 @@ public sealed class SavedNestsForm : Form
|
||||
AddColumn(platesGrid, "Utilization", "Utilization", 90, typeof(double), alignRight: true, format: "P1");
|
||||
platesGrid.SelectionChanged += (_, _) =>
|
||||
{
|
||||
if (platesGrid.CurrentRow is { } row)
|
||||
ShowPlate(row.Index);
|
||||
// Read the selected row: while this event runs, CurrentRow still names the
|
||||
// previously current row.
|
||||
if (SelectedPlateRow() is var row and >= 0)
|
||||
ShowPlate(row);
|
||||
};
|
||||
|
||||
drawingsGrid = CreateGrid();
|
||||
@@ -641,10 +643,12 @@ public sealed class SavedNestsForm : Form
|
||||
plateLabel.Text = $"Plate {index + 1:N0} of {previewPlates.Count:N0}";
|
||||
previousPlateButton.Enabled = index > 0;
|
||||
nextPlateButton.Enabled = index < previewPlates.Count - 1;
|
||||
if (index < platesGrid.Rows.Count && platesGrid.CurrentRow?.Index != index)
|
||||
if (index < platesGrid.Rows.Count && SelectedPlateRow() != index)
|
||||
platesGrid.CurrentCell = platesGrid.Rows[index].Cells[0];
|
||||
}
|
||||
|
||||
private int SelectedPlateRow() => platesGrid.SelectedRows.Count > 0 ? platesGrid.SelectedRows[0].Index : -1;
|
||||
|
||||
private void OpenSelected()
|
||||
{
|
||||
if (SelectedNestId() is not Guid id)
|
||||
|
||||
Reference in new issue
Block a user