Preflight: add finding row context menus

This commit is contained in:
Ruchir committed 2026-12-01 19:39:01 +05:30
1 parent e186fab028
commit 8a73135d7f
3 files changed
+139 -22

No files matched your search

+55 -17
View File
@@ -13,6 +13,7 @@ use craft::ui::contract::{Bind, CollectionEvent, Entry, Props as _, Show as _, S
use craft::ui::display::{Divider, Shade, Text};
use craft::ui::form::{Field, FieldGroup};
use craft::ui::list::{Finding, FindingsList, FindingsWords, ListRow, Severity};
use craft::ui::menu::{Menu, MenuItem};
use craft::ui::notices::{Notice, NoticeLayout};
use craft::ui::pickers::Select;
use craft::ui::runtime::frame::clock;
@@ -30,6 +31,8 @@ const RECHECK: f64 = 2.0;
pub(crate) struct PreflightPanel {
pub(crate) options: Options,
pub(crate) cache: Cache,
/// The document and finding for the open row menu. Report positions can change on recheck.
menu: Option<(u64, Value)>,
}
/// What the user chose to check.
@@ -213,6 +216,15 @@ fn heading_row<'r>(check: &Value, pending: &'r Pending) -> ListRow<'r> {
row
}
fn link_action(finding: &Value) -> Option<(&str, &'static str, u64)> {
let id = finding["sourceId"].as_u64()?;
match finding["code"].as_str()? {
"missingLink" => Some((tl!("Relink…"), "ui.relinkDialog", id)),
"modifiedLink" => Some((tl!("Update Link"), "links.update", id)),
_ => None,
}
}
/// The row of one finding, with the button that repairs a link under it.
fn finding_row<'r>(key: u64, finding: &Value, words: &FindingsWords, pending: &'r Pending) -> ListRow<'r> {
let code = finding["code"].as_str().unwrap_or_default();
@@ -221,14 +233,9 @@ fn finding_row<'r>(key: u64, finding: &Value, words: &FindingsWords, pending: &'
let values = ppi.iter().filter_map(Value::as_f64).map(|n| format!("{n:.0}")).collect::<Vec<_>>();
detail = format!("{detail}; {}", effective_ppi_line(&values));
}
let row = Finding::new(key, Severity::Warning, finding["name"].as_str().unwrap_or_default()).detail(detail).row(words);
let action = match code {
"missingLink" => Some((tl!("Relink…"), "ui.relinkDialog")),
"modifiedLink" => Some((tl!("Update Link"), "links.update")),
_ => None,
};
match (action, finding["sourceId"].as_u64()) {
(Some((label, command)), Some(id)) => row.below(Button::new(label.to_owned()), move |out| {
let row = Finding::new(key, Severity::Warning, finding["name"].as_str().unwrap_or_default()).detail(detail).row(words).row_menu();
match link_action(finding) {
Some((label, command, id)) => row.below(Button::new(label.to_owned()), move |out| {
if out.clicks == 1 {
pending.borrow_mut().push((command, json!({ "ids": [id] })));
}
@@ -280,43 +287,74 @@ fn options(app: &mut VectorcraftApp, ui: &mut Ui) -> bool {
}
pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
if app.session.active().is_none() {
let Some(document) = app.session.active().map(|st| st.uid) else {
app.ui.preflight_panel.menu = None;
Notice::new(Tone::Neutral, tl!("Open a document to check it before delivery.").to_owned())
.title(tl!("Production Preflight").to_owned())
.layout(NoticeLayout::Centred)
.show(ui);
return;
}
};
let force = options(app, ui);
Divider::horizontal().show(ui);
if app.session.active().is_some_and(|st| st.interaction.is_some()) || app.session.tool_busy() {
app.ui.preflight_panel.menu = None;
Notice::new(Tone::Neutral, tl!("Preflight updates when the edit finishes.").to_owned()).layout(NoticeLayout::Centred).show(ui);
return;
}
let cache = cached(app, ui, force);
if let Some(error) = cache.error {
app.ui.preflight_panel.menu = None;
Notice::new(Tone::Bad, crate::i18n::msg(&error)).title(tl!("Preflight could not complete").to_owned()).layout(NoticeLayout::Centred).show(ui);
return;
}
results(app, ui, &cache.report);
results(app, ui, document, &cache.report);
}
fn results(app: &mut VectorcraftApp, ui: &mut Ui, report: &Value) {
fn results(app: &mut VectorcraftApp, ui: &mut Ui, document: u64, report: &Value) {
let rows = PreflightRows::new(report);
let pending = Pending::default();
let out = FindingsList::new(tl!("Findings")).show_items(ui, &rows, &mut |key, icx| match rows.entries.get(*key as usize) {
let list = FindingsList::new(tl!("Findings")).id(ui.scope_id().with(("preflight-findings", document)));
let out = list.show_items(ui, &rows, &mut |key, icx| match rows.entries.get(*key as usize) {
Some(Entry_::Heading(c)) => heading_row(&rows.checks[*c], &pending),
Some(Entry_::Finding(f)) => finding_row(*key, &rows.findings[*f], &icx.words::<FindingsWords>(), &pending),
None => ListRow::new(String::new()),
});
let mut located = None;
let finding_at = |key: u64| match rows.entries.get(rows.index_of(&key)?)? {
Entry_::Finding(f) => rows.findings.get(*f),
Entry_::Heading(_) => None,
};
let menu = &mut app.ui.preflight_panel.menu;
for event in out.events {
if let CollectionEvent::Activate(key) = event
&& let Some(Entry_::Finding(f)) = usize::try_from(key).ok().and_then(|at| rows.entries.get(at))
{
located = rows.findings.get(*f);
match event {
CollectionEvent::ContextMenu(request) => *menu = finding_at(request.key).map(|f| (document, f.clone())),
CollectionEvent::Activate(key) => located = finding_at(key),
_ => {}
}
}
// Resolve the captured finding in the current report even if another row now occupies its old slot.
let target = menu.as_ref().filter(|(uid, _)| *uid == document).and_then(|(_, saved)| rows.findings.iter().find(|f| *f == saved));
if let Some(finding) = target {
let shown = Menu::context(tl!("Findings"), &out.response).show(ui, |ui, _| {
if MenuItem::new(tl!("Select and Zoom")).show(ui).ran {
located = Some(finding);
}
if finding["kind"] == "fonts" && MenuItem::new(tl!("Find Font…")).show(ui).ran {
pending.borrow_mut().push(("type.findFont", json!({})));
}
if let Some((label, command, id)) = link_action(finding)
&& MenuItem::new(label.to_owned()).show(ui).ran
{
pending.borrow_mut().push((command, json!({ "ids": [id] })));
}
});
if shown.output.closed.is_some() || located.is_some() || !pending.borrow().is_empty() {
*menu = None;
}
} else {
*menu = None;
}
if let Some(finding) = located {
locate(app, finding);
}
+79 -1
View File
@@ -131,6 +131,77 @@ fn clicking_a_preflight_finding_selects_and_zooms_to_its_artwork() {
assert!(app.view().unwrap().zoom > 1.0);
}
#[test]
fn a_finding_menu_can_be_opened_dismissed_and_run_from_the_keyboard() {
use egui::{Key, Modifiers};
let (mut app, id) = app();
app.run("select.set", json!({ "ids": [] })).unwrap();
big_canvas(&mut app);
let overflow = row(&mut app, "overflow");
let mut panel = Panel::new(app, show);
panel.focus(&overflow);
assert!(panel.focused(&overflow));
panel.key(Key::F10, Modifiers::SHIFT);
panel.frame();
panel.frame();
assert!(panel.focused("Select and Zoom"));
assert!(panel.app().session.active().unwrap().selection.objects.is_empty());
panel.key(Key::Escape, Modifiers::NONE);
panel.frame();
panel.frame();
assert!(!panel.shows("Select and Zoom"));
assert!(panel.focused(&overflow));
panel.key(Key::F10, Modifiers::SHIFT);
panel.frame();
panel.frame();
panel.key(Key::Enter, Modifiers::NONE);
app_frame(&mut panel.app());
let app = panel.app();
assert_eq!(app.session.active().unwrap().selection.objects, vec![vectorcraft_doc::NodeId(id.as_u64().unwrap())]);
assert!(app.view().unwrap().fitted);
}
#[test]
fn a_finding_menu_stays_on_its_original_finding_after_recheck() {
let (mut app, first) = app();
let second = app.run("text.create", json!({ "x": 120, "y": 10, "text": "Ab\nCd\nEf\nGh", "font": "Preflight UI Missing 917", "size": 12, "area": { "width": 100, "height": 20 } })).unwrap()["id"].clone();
app.run("object.setProps", json!({ "ids": [second], "name": "Back page" })).unwrap();
app.run("select.set", json!({ "ids": [] })).unwrap();
let overflow = |name: &str| format!("{name}, {}, Warning", reason("overflow"));
let mut panel = Panel::new(app, show);
panel.secondary_click(&overflow("Back page"));
panel.frame();
assert!(panel.shows("Select and Zoom"));
panel.app().run("text.areaOptions", json!({ "ids": [first], "height": 150 })).unwrap();
panel.frame();
assert!(!panel.shows(&overflow("Delivery headline")));
panel.click_menu_item("Select and Zoom");
assert_eq!(panel.app().session.active().unwrap().selection.objects, vec![vectorcraft_doc::NodeId(second.as_u64().unwrap())]);
}
#[test]
fn switching_documents_dismisses_the_finding_menu() {
let (mut app, _) = app();
let font = row(&mut app, "missingFont");
let mut panel = Panel::new(app, show);
panel.secondary_click(&font);
panel.frame();
assert!(panel.shows_role("Find Font…", craft::ui::contract::Role::MENU_ITEM));
panel.app().run("file.new", json!({ "width": 500, "height": 400 })).unwrap();
panel.frame();
assert!(!panel.shows("Select and Zoom"));
panel.app().run("document.activate", json!({ "index": 0 })).unwrap();
panel.frame();
assert!(panel.shows(&font));
assert!(!panel.shows("Select and Zoom"));
}
#[test]
fn clicking_a_preflight_finding_on_a_locked_artboard_reports_the_problem() {
let (mut app, id) = app();
@@ -218,8 +289,15 @@ fn preflight_panel_rechecks_missing_files_on_its_timer_and_on_request() {
panel.frame();
assert!(panel.shows(&missing));
assert_eq!(rev, panel.app().session.active().unwrap().revision);
panel.secondary_click(&missing);
panel.frame();
assert!(panel.shows_role("Relink…", craft::ui::contract::Role::MENU_ITEM));
std::fs::write(&path, &bytes).unwrap();
panel.click("Recheck");
panel.advance(2.0);
panel.frame();
assert!(!panel.shows("Select and Zoom"), "the timer dismissed the menu for a resolved finding");
assert!(!panel.shows(&missing));
std::fs::remove_file(&path).unwrap();
panel.click("Recheck");
assert!(panel.shows(&missing), "Recheck notices a newly missing file before the timer");
}
+5 -4
View File
@@ -13,10 +13,11 @@ The panel checks:
- **Image Resolution:** effective resolution along both pixel axes at the image's placed size.
Print includes the job's page transform, so enlarging the print can lower effective resolution.
Click a finding to select and zoom to the affected artwork. A font finding can select several
objects. A finding inside a symbol, pattern, brush or opacity mask locates its first visible
canvas owner. If some artwork cannot be selected, the status bar reports it; any selectable
objects are still located without unlocking artwork or artboards. **Find Font…**, **Relink…** and
Click a finding to select and zoom to the affected artwork. Right-click a finding or press
Shift+F10 on its focused row for **Select and Zoom** and any available repair action.
A font finding can select several objects. A finding inside a symbol, pattern, brush or opacity
mask locates its first visible canvas owner. If some artwork cannot be selected, the status bar
reports it and the panel still locates any selectable objects. **Find Font…**, **Relink…** and
**Update Link** open the existing repair workflows;
they do not apply an automatic font substitution or change artwork just by checking it.