From ef0914ff9453cc88ed9030abd429f09b5d60607c Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Sat, 31 Oct 2026 16:04:22 +0000 Subject: [PATCH] Design tabs: optionally keep each design's dialog, tool and toolbar tab (#9360) (#9656) A switch between design tabs cancels the open dialog and tool of the design left and shows MODEL. With the new Interface preference "Keep dialogs and tools open when switching designs" (keep_work_on_tab_switch, off by default) each tab keeps its dialog (with its picks and values), its editing state, its tool and its toolbar tab, and has them back when it is shown again. A feature still computing after OK is cancelled as before. A feature edit's saved source revision follows the view refresh of the switch, so its Cancel still restores the history. Co-authored-by: Claude Opus 5.5 --- .../pending/keep-work-on-tab-switch.json | 34 ++++ crates/ui-egui/src/documents.rs | 166 +++++++++++++++++- crates/ui-egui/src/prefs.rs | 5 + crates/ui-egui/src/prefs/interface.rs | 5 + docs/control-protocol.md | 1 + 5 files changed, 205 insertions(+), 6 deletions(-) create mode 100644 assets/locales/pending/keep-work-on-tab-switch.json diff --git a/assets/locales/pending/keep-work-on-tab-switch.json b/assets/locales/pending/keep-work-on-tab-switch.json new file mode 100644 index 000000000..67d86cf3b --- /dev/null +++ b/assets/locales/pending/keep-work-on-tab-switch.json @@ -0,0 +1,34 @@ +{ + "en": { + "prefs.keep_work_on_tab_switch": "Keep dialogs and tools open when switching designs", + "prefs.keep_work_on_tab_switch_note": "Each design tab keeps its open dialog or tool, with what you picked and typed in it, and its toolbar tab. They are there again when you come back to the design. Off: switching designs cancels them and shows the Model tab." + }, + "ar": { + "prefs.keep_work_on_tab_switch": "إبقاء مربعات الحوار والأدوات مفتوحة عند التبديل بين التصاميم", + "prefs.keep_work_on_tab_switch_note": "تحتفظ كل علامة تبويب تصميم بمربع الحوار أو الأداة المفتوحة، بما حددته وكتبته فيها، وبعلامة تبويب شريط الأدوات. وتجدها كما هي عند العودة إلى التصميم. عند الإيقاف: يؤدي التبديل بين التصاميم إلى إلغائها وعرض علامة التبويب «النموذج»." + }, + "de": { + "prefs.keep_work_on_tab_switch": "Dialoge und Werkzeuge beim Wechsel zwischen Konstruktionen offen lassen", + "prefs.keep_work_on_tab_switch_note": "Jeder Konstruktions-Tab behält seinen offenen Dialog oder sein Werkzeug mit allem, was darin ausgewählt und eingegeben wurde, sowie seinen Werkzeugleisten-Tab. Beim Zurückkehren zur Konstruktion ist alles wieder da. Aus: Ein Wechsel bricht sie ab und zeigt den Tab Modell." + }, + "fr": { + "prefs.keep_work_on_tab_switch": "Garder dialogues et outils ouverts en changeant de conception", + "prefs.keep_work_on_tab_switch_note": "Chaque onglet de conception garde son dialogue ou son outil ouvert, avec ce que vous y avez sélectionné et saisi, ainsi que son onglet de barre d'outils. Vous les retrouvez en revenant à la conception. Désactivé : changer de conception les annule et affiche l'onglet Modèle." + }, + "he": { + "prefs.keep_work_on_tab_switch": "השארת תיבות דו־שיח וכלים פתוחים במעבר בין עיצובים", + "prefs.keep_work_on_tab_switch_note": "כל לשונית עיצוב שומרת את תיבת הדו־שיח או הכלי הפתוחים בה, עם מה שבחרת והקלדת בהם, ואת לשונית סרגל הכלים שלה. הם מחכים לך כשתחזור לעיצוב. כבוי: מעבר בין עיצובים מבטל אותם ומציג את הלשונית מודל." + }, + "ja": { + "prefs.keep_work_on_tab_switch": "デザインを切り替えてもダイアログとツールを開いたままにする", + "prefs.keep_work_on_tab_switch_note": "各デザインのタブが、開いているダイアログまたはツール(選択や入力した内容を含む)とツールバーのタブを保持します。デザインに戻ると元のまま表示されます。オフ: デザインを切り替えるとそれらはキャンセルされ、モデル タブが表示されます。" + }, + "vi": { + "prefs.keep_work_on_tab_switch": "Giữ hộp thoại và công cụ mở khi chuyển giữa các thiết kế", + "prefs.keep_work_on_tab_switch_note": "Mỗi thẻ thiết kế giữ hộp thoại hoặc công cụ đang mở, cùng những gì bạn đã chọn và nhập trong đó, và thẻ thanh công cụ của nó. Chúng vẫn còn đó khi bạn quay lại thiết kế. Tắt: chuyển thiết kế sẽ hủy chúng và hiển thị thẻ Mô hình." + }, + "zh": { + "prefs.keep_work_on_tab_switch": "切换设计时保持对话框和工具打开", + "prefs.keep_work_on_tab_switch_note": "每个设计标签页保留其打开的对话框或工具(包括其中已选择和输入的内容)以及工具栏选项卡。回到该设计时它们仍在原处。关闭时:切换设计会取消它们并显示“模型”选项卡。" + } +} diff --git a/crates/ui-egui/src/documents.rs b/crates/ui-egui/src/documents.rs index 93168a2f9..22562c4d2 100644 --- a/crates/ui-egui/src/documents.rs +++ b/crates/ui-egui/src/documents.rs @@ -34,6 +34,66 @@ pub struct DocSlot { /// Its linked design files as the design last read them (`Documents::link_stamps`). link_stamps: Vec<(u64, crate::linked_source::Stamp)>, edit_in_place: Option, + /// The dialog or tool it had open and its toolbar tab, kept while another design is shown. + work: DocWork, +} + +/// What a design was doing when its tab was left, with the "Keep dialogs and tools open when +/// switching designs" preference (`keep_work_on_tab_switch`, #9360): the open dialog with its +/// picks and values, the tool, and the toolbar tab. They act on that design's session, which +/// waits in the same slot, so showing the tab again picks up exactly where it was left. +#[derive(Default)] +struct DocWork { + dialog: Option, + editing_state: Option, + tool: Option, + /// The toolbar tab shown, its contextual tab and the tab a sketch returns to (`None`: the + /// design was left without the preference, and comes back on MODEL as before). + tab: Option<(String, Option, Option)>, +} + +/// Take the active design's dialog, tool and toolbar tab, to keep with its tab. A feature still +/// computing after OK can't wait (its result belongs to the window thread): that dialog is +/// cancelled, as without the preference. +fn take_work(app: &mut SolveApp) -> DocWork { + if !app.preferences.keep_work_on_tab_switch || app.applying.is_some() { + crate::dialogs::cancel(app); + app.tool = None; + return DocWork::default(); + } + DocWork { + dialog: app.dialog.take(), + editing_state: app.editing_state.take(), + tool: app.tool.take(), + tab: Some((app.ui.tab.clone(), app.ui.ribbon_context.clone(), app.ui.sketch_return_tab.clone())), + } +} + +/// Give the incoming design back what [`take_work`] kept of it, after its session is in the app. +/// Kept work comes back even when the preference was turned off since: the dialog may hold the +/// design's history rolled back for an edit, and only the dialog's Cancel or OK puts it back. +/// `before`: the session's revision before the switch moved it on to refresh the views. +fn put_work(app: &mut SolveApp, mut work: DocWork, before: u64) { + // That refresh is not a change to the design: the edit's Cancel must still see the design + // it left (`Session::restore_editor` compares revisions), as `PendingFeatureEdit` does. + if let Some(state) = &mut work.editing_state { + state.source.revision = state.source.revision.saturating_add(app.session.revision.saturating_sub(before)); + } + app.dialog = work.dialog; + app.editing_state = work.editing_state; + app.tool = work.tool; + match work.tab { + Some((tab, context, back)) => { + app.ui.tab = tab; + app.ui.ribbon_context = context; + app.ui.sketch_return_tab = back; + } + None => { + app.ui.ribbon_context = None; + app.ui.tab = "MODEL".into(); + } + } + crate::workspace::sync_context(app); } /// The per-design part of the UI state the session doesn't keep (what is hidden, shown or locked @@ -67,6 +127,7 @@ impl DocSlot { agent_chat: Default::default(), link_stamps: Vec::new(), edit_in_place: None, + work: DocWork::default(), } } } @@ -138,12 +199,12 @@ fn swap_in(app: &mut SolveApp, mut slot: DocSlot) -> DocSlot { if crate::render_workspace::active(app) { let _ = crate::render_workspace::enter(app, false); } - // Whatever was going on in the design leaves with it. + // Whatever was going on in the design leaves with it: cancelled, or kept with its tab + // (`take_work`). crate::timeline::stop_playback(app); crate::sketch_text_move::cancel_drag(app); - crate::dialogs::cancel(app); + let work = take_work(app); crate::dim_view::cancel(); - app.tool = None; app.params = None; app.design_properties = None; app.bom = None; @@ -170,6 +231,7 @@ fn swap_in(app: &mut SolveApp, mut slot: DocSlot) -> DocSlot { agent_chat: slot.agent_chat, link_stamps: std::mem::replace(&mut app.docs.link_stamps, slot.link_stamps), edit_in_place: std::mem::replace(&mut app.edit_in_place.active, slot.edit_in_place), + work, }; // Only the displayed design owns the process-wide crash replay journal. app.session.crash_journal = out.session.crash_journal; @@ -186,9 +248,7 @@ fn swap_in(app: &mut SolveApp, mut slot: DocSlot) -> DocSlot { if let Some(pending) = &mut app.pending_feature_edit { pending.view_changed(before, app.session.revision); } - app.ui.ribbon_context = None; - app.ui.tab = "MODEL".into(); - crate::workspace::sync_context(app); + put_work(app, slot.work, before); out } @@ -1788,4 +1848,98 @@ mod tests { assert_eq!(v["active"], 0); assert_eq!(v["documents"].as_array().map(Vec::len), Some(2)); } + + /// The items picked in the open dialog's first input. + fn dialog_picks(a: &SolveApp) -> Vec { + a.dialog.as_ref().and_then(|d| d.inputs.first()).map(|i| i.items.clone()).unwrap_or_default() + } + + /// Tab 1: a box measured between two corners, on INSPECT. Tab 2: a sketch with the Line tool. + fn measuring_and_drawing(keep: bool) -> (SolveApp, Vec) { + let mut a = app(); + a.preferences.keep_work_on_tab_switch = keep; + a.run("solid.box", json!({"length": 3, "width": 4, "height": 12, "body_name": "Box"})).unwrap(); + a.session.selection = + [[0.0, 0.0, 0.0], [3.0, 4.0, 12.0]].into_iter().map(|p| solidcraft_engine::Sel::Vertex { body: "Box".into(), point: p.into() }).collect(); + a.ui.tab = "INSPECT".into(); + a.start("inspect.measure"); + let picks = dialog_picks(&a); + assert_eq!(picks.len(), 2, "Measure opens on the two picked corners"); + new_design(&mut a); + a.run("sketch.create", json!({"plane": "XY"})).unwrap(); + crate::workspace::sync_context(&mut a); + a.start("sketch.line"); + assert!(a.tool.as_ref().is_some_and(|t| t.cmd == "sketch.line") && a.ui.tab == "SKETCH"); + (a, picks) + } + + /// #9360: with "Keep dialogs and tools open when switching designs", each design tab has its + /// open dialog (with its picks), its tool and its toolbar tab back when it is shown again, and + /// none of them shows in the other design. + #[test] + fn tabs_keep_their_dialog_tool_and_toolbar_tab_with_the_preference() { + let (mut a, picks) = measuring_and_drawing(true); + switch(&mut a, 0); + assert!(a.tool.is_none(), "the Line tool stays with the sketch's design"); + assert!(matches!(a.dialog.as_ref().map(|d| &d.kind), Some(crate::dialogs::Kind::Measure { .. })), "Measure is open again"); + assert_eq!(dialog_picks(&a), picks, "with the same two corners"); + assert_eq!(a.ui.tab, "INSPECT"); + assert!(a.session.active_sketch.is_none()); + switch(&mut a, 1); + assert!(a.dialog.is_none(), "Measure stays with the box's design"); + assert!(a.tool.as_ref().is_some_and(|t| t.cmd == "sketch.line"), "the Line tool is back"); + assert!(a.session.active_sketch.is_some()); + assert_eq!(a.ui.tab, "SKETCH"); + // Kept work comes back even once the preference is off; after that, a switch cancels. + a.preferences.keep_work_on_tab_switch = false; + switch(&mut a, 0); + assert!(dialog_picks(&a) == picks && a.ui.tab == "INSPECT"); + switch(&mut a, 1); + switch(&mut a, 0); + assert!(a.dialog.is_none() && a.ui.tab == "MODEL"); + } + + /// Without the preference (the default), a switch cancels the dialog and the tool and shows + /// MODEL, as before #9360. + #[test] + fn a_tab_switch_cancels_the_dialog_and_tool_by_default() { + assert!(!crate::prefs::Prefs::default().keep_work_on_tab_switch); + let (mut a, _) = measuring_and_drawing(false); + switch(&mut a, 0); + assert!(a.dialog.is_none() && a.tool.is_none()); + assert_eq!(a.ui.tab, "MODEL"); + switch(&mut a, 1); + assert!(a.dialog.is_none() && a.tool.is_none()); + // The sketch itself stays open in its design, so its tab is SKETCH. + assert_eq!(a.ui.tab, "SKETCH"); + } + + /// #9360: a feature being edited keeps its history rolled back to it in its own design only, + /// and its Cancel, after the switch back, puts that design's history back. + #[test] + fn a_feature_edit_waits_in_its_tab_and_cancels_there() { + let mut h = crate::scenario::Harness::new(); + h.app.home.open = false; + h.app.preferences.keep_work_on_tab_switch = true; + h.app.run("solid.box", json!({"length": 10, "width": 10, "height": 10})).unwrap(); + h.app.run("solid.box", json!({"length": 5, "width": 5, "height": 30})).unwrap(); + let features = h.app.session.doc.features.len(); + let first = h.app.session.doc.features.first().map(|f| f.id).unwrap(); + h.call("ui.editFeature", json!({"feature": first})); + h.frames(3); + let editing = |h: &crate::scenario::Harness| h.app.dialog.as_ref().and_then(|d| d.editing).map(|(id, _)| id); + assert_eq!(editing(&h), Some(first), "the first box's dialog is open"); + let marker = h.app.session.doc.marker; + new_design(&mut h.app); + h.frames(2); + assert!(h.app.dialog.is_none() && h.app.editing_state.is_none()); + assert!(h.app.session.doc.features.is_empty() && h.app.session.doc.marker.is_none(), "the new design is untouched"); + switch(&mut h.app, 0); + h.frames(2); + assert_eq!(editing(&h), Some(first), "the edit is open again"); + assert_eq!(h.app.session.doc.marker, marker, "with the history where the edit left it"); + crate::dialogs::cancel(&mut h.app); + assert!(h.app.dialog.is_none()); + assert_eq!((h.app.session.doc.features.len(), h.app.session.doc.marker), (features, None), "Cancel puts the history back"); + } } diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index f4f74443c..c07be4641 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -1094,6 +1094,10 @@ preference_settings! { /// Keep the SKETCH tab in the ribbon, right after MODEL, while no sketch is open; its drawing /// tools then start a sketch first (#7904). sketch_tab_always: bool = false, PAGE_INTERFACE => check_id("prefs.sketch_tab_always"); + /// Each design tab keeps its open dialog or tool, and its toolbar tab, while another design is + /// shown, and has them back when it is shown again (#9360). Off by default: a switch cancels + /// them and shows the MODEL tab. + keep_work_on_tab_switch: bool = false, PAGE_INTERFACE => check_id("prefs.keep_work_on_tab_switch"); /// Hovering a result in Search commands shows the command's place in the ribbon: its tab, /// its button or its row in a section's drop-down (#7287). A command started from the search /// blinks there, and a running command that sits in a drop-down marks its section label. Off @@ -5479,6 +5483,7 @@ mod tests { ("viewport_status_details", json!(false), PAGE_INTERFACE), ("viewport_status_summary", json!(false), PAGE_INTERFACE), ("sketch_tab_always", json!(true), PAGE_INTERFACE), + ("keep_work_on_tab_switch", json!(true), PAGE_INTERFACE), ("ribbon_reveal", json!(true), PAGE_INTERFACE), ("dialog_buttons", json!("top"), PAGE_INTERFACE), ("toast_place", json!("centre"), PAGE_INTERFACE), diff --git a/crates/ui-egui/src/prefs/interface.rs b/crates/ui-egui/src/prefs/interface.rs index e35f1ba47..47b066e30 100644 --- a/crates/ui-egui/src/prefs/interface.rs +++ b/crates/ui-egui/src/prefs/interface.rs @@ -120,6 +120,11 @@ pub(super) fn interface(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) { let check = setting::sketch_tab_always(app, ui).on_hover_text(app.tr("prefs.sketch_tab_always_note")); crate::scenario::publish_target("prefs:sketch_tab_always", check.rect); }); + // Each design tab keeps its dialog, tool and toolbar tab across a switch (#9360). + ui_kit::row(ui, "", |ui| { + let check = setting::keep_work_on_tab_switch(app, ui).on_hover_text(app.tr("prefs.keep_work_on_tab_switch_note")); + crate::scenario::publish_target("prefs:keep_work_on_tab_switch", check.rect); + }); // Search results point out their place in the ribbon (#7287). ui_kit::row(ui, "", |ui| { let check = setting::ribbon_reveal(app, ui).on_hover_text(app.tr("prefs.ribbon_reveal_note")); diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 155d3a3f4..511b3372c 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -444,6 +444,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own - `hole_snaps` (default false: a Single hole snaps to its face's middle and round edges' centres) - `joint_rotation_coarse` (default 10°): coarse Assembly Move rotation step, in 0.001…180°. - `joint_rotation_fine` (default 0.1°): fine Assembly Move rotation step, in 0.001…180°. +- `keep_work_on_tab_switch` (default false: each design tab keeps its open dialog or tool, with what was picked and typed in it, and its toolbar tab while another design is shown, and has them back when it is shown again; off, a switch cancels them and shows MODEL, #9360) - `language` (`en`, `ar`, `ja`, `de`, `fr`, `he`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md)) - `length_decimals` - `line_drag_draws_one` (default false: in the Line tool, a press, a drag and the release draw one line from the press to the release and end there, snapping as clicks do; clicks still chain, and a drag under 24 points is a click; off, a drag places a point where it is let go, #7247)