From bd3dcbe69f703e7bf989c6b4f2d1307be3097423 Mon Sep 17 00:00:00 2001 From: Meketreve <34199654+meketreve@users.noreply.github.com> Date: Mon, 17 Aug 2026 10:06:07 -0300 Subject: [PATCH] Make Enter save and Esc cancel in the New Item and New Robot dialogs The other sixteen AdminTool dialogs already pair IsDefault on their confirm button with IsCancel on Cancel. These two were the exceptions: Enter did nothing and Esc did nothing. IsDefault on its own would have been a regression. Enter activates the default button without moving focus, so a TextBox bound with the default LostFocus trigger is still holding an uncommitted value when Save runs, and roughly fifteen fields in these dialogs are bound that way -- Mass, Volume, Health and Quantity among them. Measured rather than assumed: with the hook removed, typing 555 into Mass and pressing Enter produced an INSERT carrying mass = 0. The PreviewKeyDown handler pushes the focused single-line TextBox to its source first. Multi-line boxes consume Enter themselves and are left alone. Verified by hand against the local database in SQL script mode, since no test tier covers the AdminTool: Enter saves and the typed value reaches the generated SQL, Esc closes without saving, Enter inserts a newline in the Note box, and Enter still commits a DataGrid cell rather than saving the item. Co-Authored-By: Claude Opus 5 --- src/Perpetuum.AdminTool/Views/NewItemDialog.xaml | 7 ++++--- .../Views/NewItemDialog.xaml.cs | 14 ++++++++++++++ src/Perpetuum.AdminTool/Views/NewRobotDialog.xaml | 7 ++++--- .../Views/NewRobotDialog.xaml.cs | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/Perpetuum.AdminTool/Views/NewItemDialog.xaml b/src/Perpetuum.AdminTool/Views/NewItemDialog.xaml index cae50c18..2ee61a1c 100644 --- a/src/Perpetuum.AdminTool/Views/NewItemDialog.xaml +++ b/src/Perpetuum.AdminTool/Views/NewItemDialog.xaml @@ -3,7 +3,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:common="clr-namespace:Perpetuum.AdminTool.Common" Title="New Item" Width="960" Height="720" - WindowStartupLocation="CenterOwner" ShowInTaskbar="False"> + WindowStartupLocation="CenterOwner" ShowInTaskbar="False" + PreviewKeyDown="OnPreviewKeyDown"> @@ -30,9 +31,9 @@