fix(annotative): stage scale-manager edits like the style managers

The scale manager now runs as a transaction, matching the style managers'
staging: New starts a blank editor draft (nothing is added to the drawing
until Apply), Delete removes immediately but staged, and closing the window
without Apply restores the snapshot taken on open — so a scale created or
deleted mid-session is discarded on cancel. Apply commits the staged list
changes as a single undo entry. This replaces the earlier behaviour where
New copied the selected scale and edits landed immediately.

A `changed` flag guards the commit so a no-op / failed Apply (blank or
invalid fields, or an edit that didn't apply) no longer dirties the drawing
or pushes a phantom undo entry. Set Current is deliberately outside the
transaction — it takes effect immediately like the scale pill (and syncs
CANNOSCALEVALUE), so it is never rolled back on close. Renaming the current
scale follows the pointer; editing one of the built-in fallback scales (shown
when the drawing has no scale list) materialises it as a real scale; the
snapshot restore touches only the ACAD_SCALELIST root entry.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-07-13 12:14:40 +03:00
commit cd766bc1f5
4 changed files with 221 additions and 49 deletions

View file

@ -664,6 +664,12 @@ pub(super) struct OpenCADStudio {
scale_manager_name_buf: String,
scale_manager_paper_buf: String,
scale_manager_drawing_buf: String,
/// The editor holds an unsaved *new* scale (created only on Apply) rather
/// than editing the selected one. Reset when a row is selected.
scale_manager_new: bool,
/// Open transaction for the scale manager — restored if the window closes
/// without Apply, mirroring the style managers' staging.
scale_stage: Option<crate::app::style_ops::ScaleStage>,
// ── Plot Style Panel ──────────────────────────────────────────────────
/// Selected ACI index in the panel (1-255).
@ -2257,6 +2263,8 @@ impl OpenCADStudio {
scale_manager_name_buf: String::new(),
scale_manager_paper_buf: String::new(),
scale_manager_drawing_buf: String::new(),
scale_manager_new: false,
scale_stage: None,
layout_manager_rename_buf: String::new(),
plotstyle_panel_aci: 1,
ps_color_buf: String::new(),