fix(sheetset): safer sheet edits

- Place on Sheet gives its viewport a unique id (shared
  `Scene::next_viewport_id`, also used by the normal viewport commit).
- Renaming a sheet's layout in an open tab records undo and marks the tab
  modified; in a closed drawing the previous file is kept as `.bak`
  (ISAVEBAK) before it is written back.
- New Sheet saves the drawing before the `.dst`: a failed save leaves no
  sheet behind.
- Rename & Renumber Previous/Next no longer panics on an empty list.
- Leftovers: unused binding, a hard-coded localized Documents path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 5.5 committed 2026-10-06 09:29:23 +03:00
1 parent 8b9049c604
commit 40847d72a1
3 files changed
+79 -61

No files matched your search

+16
View File
@@ -4458,6 +4458,22 @@ impl Scene {
self.current_layout_block_handle()
}
/// A unique id for a new viewport on the current layout: one past the
/// largest id there, at least 2 (1 is the layout's own paper viewport).
pub fn next_viewport_id(&self) -> i16 {
let layout_block = self.current_layout_block_handle();
let max_id = self
.document
.entities()
.filter_map(|e| match e {
codec::EntityType::Viewport(v) if v.common.owner_handle == layout_block => Some(v.id),
_ => None,
})
.max()
.unwrap_or(1);
(max_id + 1).max(2)
}
/// True when an entity belongs to the active layout, including imported
/// DXF entities whose owner handle is NULL but whose BlockRecord still
/// lists the entity. Keep command validation aligned with the same