diff --git a/crates/ui-egui/src/addons/packaging.rs b/crates/ui-egui/src/addons/packaging.rs index a6aa04dfc7..7a0de94cb4 100644 --- a/crates/ui-egui/src/addons/packaging.rs +++ b/crates/ui-egui/src/addons/packaging.rs @@ -23,7 +23,7 @@ use craft::ui::display::{Divider, Text}; use craft::ui::form::Field; use craft::ui::layout_components::Row as Line; use craft::ui::list::{Finding, Findings, FindingsList, FindingsWords, List, ListRow, Severity, ThumbSize}; -use craft::ui::menu::PanelRow; +use craft::ui::menu::{Menu, MenuItem, PanelRow}; use craft::ui::runtime::commands::{CommandState, CommandStates}; use craft::ui::runtime::env::UnitKind; use craft::ui::text::NumberField; @@ -149,6 +149,8 @@ fn doc_key(app: &VectorcraftApp) -> Option { pub(crate) struct FoldLines { /// The last check of each document. checks: Checks, + /// The immutable check and row on which the context menu opened. + menu: Option<(Weak, usize)>, /// The role rows for the document state they were read for. rows: Rows, } @@ -210,22 +212,45 @@ fn show_check(app: &mut VectorcraftApp, ui: &mut Ui) { { app.status(e); } - let Some(checked) = last_check(app) else { return }; + let Some(checked) = last_check(app) else { + app.addon_panels.fold.menu = None; + return; + }; Text::new(crate::i18n::msg(&checked.summary())).show(ui); let findings: Vec = (0u64..) .zip(&checked.issues) .map(|(id, issue)| Finding::new(id, if issue.error { Severity::Error } else { Severity::Warning }, crate::i18n::msg(&issue.message))) .collect(); - let out = - FindingsList::new(tl!("Issues").to_string()).show_items(ui, &Findings::new(&findings), &mut |key, icx| match findings.get(*key as usize) { - Some(finding) => finding.row(&icx.words::()), - None => ListRow::spacer(), - }); - for event in &out.events { - if let CollectionEvent::Activate(n) = event { - select_issue(app, &checked, *n as usize); + let list = FindingsList::new(tl!("Issues").to_string()).id(ui.scope_id().with(("fold-issues", Arc::as_ptr(&checked)))); + let out = list.show_items(ui, &Findings::new(&findings), &mut |key, icx| match findings.get(*key as usize) { + Some(finding) => finding.row(&icx.words::()).row_menu(), + None => ListRow::spacer(), + }); + for event in out.events { + match event { + CollectionEvent::Activate(n) => select_issue(app, &checked, n as usize), + CollectionEvent::ContextMenu(request) => app.addon_panels.fold.menu = Some((Arc::downgrade(&checked), request.key as usize)), + _ => {} } } + let Some((owner, n)) = &app.addon_panels.fold.menu else { return }; + let n = *n; + let Some(issue) = checked.issues.get(n).filter(|_| owner.as_ptr() == Arc::as_ptr(&checked)) else { + app.addon_panels.fold.menu = None; + return; + }; + let shown = Menu::context(tl!("Issues"), &out.response).show(ui, |ui, _| { + if MenuItem::new(tl!("Select Affected Objects")).enabled(!issue.ids.is_empty()).show(ui).ran { + select_issue(app, &checked, n); + } + if MenuItem::new(tl!("Copy Finding")).show(ui).ran { + app.clipboard_out = Some(crate::i18n::msg(&issue.message)); + app.status(tl!("Copied finding")); + } + }); + if shown.output.closed.is_some() { + app.addon_panels.fold.menu = None; + } } /// One role row: (role id, swatch name, the swatch's paint if the document has it, count). @@ -346,6 +371,7 @@ fn role_label(role: &str) -> &str { pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let Some(selected) = app.session.active().map(|st| !st.selection.is_empty()) else { + app.addon_panels.fold.menu = None; empty_state(ui, "scissors", tl!("No document"), tl!("Open a document to mark its fold lines.")); return; }; diff --git a/crates/ui-egui/src/addons/packaging/tests.rs b/crates/ui-egui/src/addons/packaging/tests.rs index 26d9ac729b..ea89dcd928 100644 --- a/crates/ui-egui/src/addons/packaging/tests.rs +++ b/crates/ui-egui/src/addons/packaging/tests.rs @@ -116,6 +116,58 @@ fn each_document_keeps_its_own_check() { assert!(last_check(&app).is_some_and(|kept| Arc::ptr_eq(&kept, &second))); } +#[test] +fn a_finding_menu_selects_its_objects_and_restores_keyboard_focus_on_escape() { + let (mut app, slit) = blank(); + let checked = run_check(&mut app, json!({})).unwrap(); + let row = format!("{}, Error", checked.issues[0].message); + let mut panel = Panel::new(app, super::show_check); + panel.focus(&row); + panel.key(Key::F10, Modifiers::SHIFT); + panel.frame(); + panel.frame(); + assert!(panel.focused("Select Affected Objects")); + panel.key(Key::Escape, Modifiers::NONE); + panel.frame(); + panel.frame(); + assert!(panel.focused(&row)); + panel.secondary_click(&row); + panel.frame(); + panel.click_menu_item("Select Affected Objects"); + assert_eq!(panel.app().session.active().unwrap().selection.objects, [vectorcraft_doc::NodeId(slit)]); +} + +#[test] +fn a_recheck_and_a_document_switch_dismiss_the_menu_and_an_objectless_finding_can_be_copied() { + let (mut app, a, _) = app(); + app.run("select.set", json!({"ids": [a]})).unwrap(); + let checked = run_check(&mut app, json!({})).unwrap(); + let row = format!("{}, Error", checked.issues[0].message); + let mut panel = Panel::new(app, super::show_check); + panel.secondary_click(&row); + panel.frame(); + assert!(!panel.menu_item_enabled("Select Affected Objects")); + panel.click_menu_item("Copy Finding"); + assert_eq!(panel.app().clipboard_out.as_deref(), Some(checked.issues[0].message.as_str())); + assert_eq!(panel.app().session.active().unwrap().selection.objects, [vectorcraft_doc::NodeId(a)]); + + panel.secondary_click(&row); + panel.frame(); + assert!(panel.shows("Copy Finding")); + let replacement = run_check(&mut panel.app(), json!({"ids": [a]})).unwrap(); + panel.frame(); + assert!(!panel.shows("Copy Finding")); + assert!(!panel.shows("Select Affected Objects")); + panel.secondary_click(&format!("{}, Error", replacement.issues[0].message)); + panel.frame(); + assert!(panel.shows("Copy Finding")); + panel.app().run("file.new", json!({"width": 100, "height": 100})).unwrap(); + run_check(&mut panel.app(), json!({})).unwrap(); + panel.frame(); + assert!(!panel.shows("Copy Finding")); + assert!(!panel.shows("Select Affected Objects")); +} + /// The messages `addon.packaging.check` gives its issues, one for each code (three for `noCut`). const ISSUE_MESSAGES: [&str; 17] = [ "No cut lines are in the selection.", diff --git a/docs/mcp.md b/docs/mcp.md index 3e8da28cc7..3dc3fafd22 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -18718,7 +18718,7 @@ Result: `{ok, blanks, panels, hinges, holes, issues: [{severity, code, message, no issue is an error. `message` is in English, and the Fold Lines panel shows it in the interface language. `ids` names the objects each issue is about. With `select: true`, those objects become the selection; when no issue names an object, the selection stays as it is. The Fold Lines panel's Check button runs the same check, shows a summary line -(panels, hinges, errors and warnings) and lists the issues; clicking an issue or its Select button selects its objects. +(panels, hinges, errors and warnings) and lists the issues; clicking an issue or choosing Select Affected Objects from its row menu selects its objects. Copy Finding copies the displayed message, including for issues that name no objects. The list is shown until the document changes. ```json diff --git a/docs/ui-parity.md b/docs/ui-parity.md index f1d3be52e4..a2b7812ee9 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -194,7 +194,7 @@ tools, never checked side by side) isn't captured row by row. ## Headless (RFC-0052) -**Headless ([RFC-0052](https://github.com/storytold/craft-contrib/blob/main/rfcs/0052-headless-reach.md)): 0 yes, 0 no (window 0, os 0, engine-gap 0), 0 partial, 365 unknown.** +**Headless ([RFC-0052](https://github.com/storytold/craft-contrib/blob/main/rfcs/0052-headless-reach.md)): 0 yes, 0 no (window 0, os 0, engine-gap 0), 0 partial, 366 unknown.** Every parity table on this page has a Headless column: the Summary table (12 area rows, including the overall row) and the behaviour tables (353 rows). Every row is `unknown` until it is checked. A checked row may be marked `no ()` or `partial ()` by hand, where the reach is `window` (needs the desktop window, a dialog or the pointer), `os` (needs an OS or online service the engine doesn't wrap) or `engine-gap` (could be a command, isn't one yet). A `partial` row's notes say which part a headless client can do. `yes` only when the row cites a command id from the engine registry that `vectorcraft-cli` and the MCP server load (LightCraft's `cmd:` check is the model). Some rows already cite command ids such as `toolbar.show`, `tool.select` and `guide.add`; those are not enough for `yes` until they are registry ids, and desktop-only ids (including the generated list in `crates/mcp/src/ui_catalog.rs`) do not count. Update the counts in this line when you mark rows. @@ -597,6 +597,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po | Anchor Inspector fields restore canceled edits | done | Canceling an X, Y, handle Length or Angle edit restores the anchor, with no undo step, and canceling a Points per segment edit restores its count. An accepted anchor edit is one undo step. | unknown | | Corner and Shared Edge Merge options restore canceled edits | done | Canceling a control gesture restores its opening draft values. Confirmed changes remain available to the tool. | unknown | | Parametric Shape panel restores canceled edits | done | Canceling a field edit or Shape menu choice restores the selected shape, with no undo step, or the tool's next shape. An accepted edit of a selected shape is one undo step. With no shape selected, a highlighted Shape entry applies only once chosen. | unknown | +| Fold Lines check-result row menu | done | Select Affected Objects selects the lines named by the finding. Copy Finding copies its displayed message, including for findings without objects. | unknown | | Fold Lines panel restores a canceled Fold Angle edit | done | Canceling a Fold Angle edit restores the selected lines' angles, with no undo step. An accepted edit is one undo step. | unknown | | Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Divide into Dashes… (Dash and Gap in any unit, Fit to Corners and Ends, Remove Gaps; Preview) cuts the selected paths, or only their direct-selected segments, into open pieces along the curve, keeping their appearance, one undo step | done | #4950; `addon.pathtools.divideDashes`, `crates/pathops/src/addons/pathtools/dashes.rs`, `crates/ui-egui/src/addons/pathtools/dashes.rs` and their tests; not a feature of the reference app, so it is not scored | unknown | | Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Set Corners… (also a button in the Anchor Inspector's Corners section: Radius in any unit, Corner kind, Anchors: All, Odd-Numbered or Even-Numbered, counted from each path's first anchor; Angle: from … to …°, only the corners whose sides meet at an angle in that range; Preview) cuts corners on the chosen anchors of every selected path, one undo step | done | #5546, #5545; `addon.pathtools.cornerSet` (`every`, `minAngle`, `maxAngle`), `crates/ui-egui/src/addons/pathtools/set_corners.rs` and their tests; not a feature of the reference app, so it is not scored | unknown |