mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-31 06:16:51 -06:00
Keep the active layout when saving DWG/DXF (#1735)
* Keep the active layout when saving DWG/DXF The layout a file marks active (block *Paper_Space) was not kept on read, and on write *Paper_Space always went to the first tab, so every save made the first sheet active. Store it as Drawing::active_layout and write it as *Paper_Space again; tab order is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Match the active layout by name without regard to case paper_space_layouts and layout.rename now compare the active layout's name case-insensitively, as Drawing::layout() does, so an active layout stored as "s2" still resolves the "S2" tab. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Test case-insensitive active layout matching Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: ffishman <20211677+ffishman@users.noreply.github.com> Co-authored-by: Brandon Thomas <echelon@gmail.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
ffishman
Brandon Thomas
parent
a94fc0898b
commit
1c35d7f8c1
@@ -270,9 +270,13 @@ fn run_rename(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let from = layout_name("layout.rename", s.doc()?, &from)?;
|
||||
let to = str_param(p, "to").ok_or_else(|| bad("layout.rename", "`to` is required"))?;
|
||||
let to = check_name("layout.rename", s.doc()?, to, Some(&from))?;
|
||||
if let Some(l) = s.doc_mut()?.layouts.iter_mut().find(|l| l.name == from) {
|
||||
let d = s.doc_mut()?;
|
||||
if let Some(l) = d.layouts.iter_mut().find(|l| l.name == from) {
|
||||
l.name = to.clone();
|
||||
}
|
||||
if d.active_layout.as_ref().is_some_and(|a| a.eq_ignore_ascii_case(&from)) {
|
||||
d.active_layout = Some(to.clone());
|
||||
}
|
||||
let (old, new) = (Space::Paper(from.clone()), Space::Paper(to.clone()));
|
||||
let st = s.state_mut()?;
|
||||
for (sp, _) in st.views.iter_mut() {
|
||||
@@ -928,6 +932,14 @@ mod tests {
|
||||
assert!(s.doc().unwrap().layout("Layout3").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_keeps_the_active_layout_whatever_its_case() {
|
||||
let mut s = session_with_model();
|
||||
s.doc_mut().unwrap().active_layout = Some("layout1".into());
|
||||
s.execute("layout.rename", &json!({"from": "Layout1", "to": "Sheet A"})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().active_layout.as_deref(), Some("Sheet A"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_copy_delete() {
|
||||
let mut s = session_with_model();
|
||||
|
||||
Reference in New Issue
Block a user