From fc5bd2fa111c727b13b4bbbb3178d5f88e642173 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 02:04:36 -0800 Subject: [PATCH] New Document: Recent is headed as recent items and Saved is the second tab On the Recent tab the heading read "Blank Document Presets (n)", the same as the preset categories, and Saved was the last tab, after every category. Before the move to the shared dialog, Recent had its own heading and Saved came right after it. The dialog now turns on the shared dialog's recent_items and saved_after_recent options: Recent reads "Your Recent Items (n)" over four cards to a row, and the tabs read Recent, Saved, then the categories. --- crates/ui-egui/src/dialogs/new_document.rs | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/new_document.rs b/crates/ui-egui/src/dialogs/new_document.rs index 213f96b27a..23fd139c29 100644 --- a/crates/ui-egui/src/dialogs/new_document.rs +++ b/crates/ui-egui/src/dialogs/new_document.rs @@ -709,7 +709,7 @@ pub fn open(app: &mut VectorcraftApp) { } let recent: Vec = app.session.prefs.recent_new_docs.iter().cloned().map(VcNewDocument::of).collect(); let mut dialog = HostedNewDocument::::new(&ctx, first, move |options| { - NewDocumentDialog::over(Bind::bound(options)).categories(categories.clone()).setup(setup.clone()) + NewDocumentDialog::over(Bind::bound(options)).categories(categories.clone()).setup(setup.clone()).saved_after_recent(true).recent_items(true) }) .saved(saved) .recent(recent); @@ -1238,6 +1238,38 @@ mod tests { } } + /// Recent is headed as the recent documents it lists, and Saved is the second tab, right after Recent; before, + /// Recent read "Blank Document Presets (n)" and Saved was the last tab. + #[test] + fn recent_heads_its_documents_and_saved_follows_it() { + use egui::accesskit::Role; + let mut app = app(); + app.run("file.new", json!({"preset": "Letter"})).unwrap(); + app.run("file.new", json!({"preset": "Web 1920×1080"})).unwrap(); + open(&mut app); + let out = laid_out(&mut app); + let drawn: Vec = crate::tests_labels::text_shapes(&out).into_iter().map(|(t, _)| t.galley.text().to_uppercase()).collect(); + assert!(drawn.iter().any(|t| t == "YOUR RECENT ITEMS (2)"), "Recent counts its two documents: {drawn:?}"); + assert!(!drawn.iter().any(|t| t.starts_with("BLANK DOCUMENT PRESETS")), "Recent is not headed as presets: {drawn:?}"); + // The Home screen behind the dialog has tabs of its own: only the dialog's are read. + let nodes = out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default(); + let by_id: std::collections::HashMap<_, _> = nodes.iter().map(|(id, n)| (*id, n)).collect(); + let mut stack: Vec<_> = nodes.iter().filter(|(_, n)| n.role() == Role::Dialog).map(|(id, _)| *id).collect(); + let mut tabs = Vec::new(); + while let Some(id) = stack.pop() { + if let Some(node) = by_id.get(&id) { + if let (Role::Tab, Some(label), Some(b)) = (node.role(), node.label(), node.bounds()) { + tabs.push((b.x0, label.to_owned())); + } + stack.extend(node.children().iter().copied()); + } + } + tabs.sort_by(|a, b| a.0.total_cmp(&b.0)); + let order: Vec<&str> = tabs.iter().map(|(_, label)| label.as_str()).collect(); + assert!(order.len() > 2, "the dialog's tabs: {order:?}"); + assert_eq!(order[..2], ["Recent", "Saved"], "Saved follows Recent: {order:?}"); + } + #[test] fn a_preset_fills_the_details_and_create_makes_the_document() { let mut app = app();