export-w23: net change of 2 commits

- export-w23: written from its sheet
- export-w23: repair 1
This commit is contained in:
bflatastic
2026-11-21 23:42:07 +07:00
parent 7894c12b09
commit 2f04494f5c
3 changed files with 262 additions and 407 deletions
+193 -283
View File
@@ -1,16 +1,15 @@
//! File → Print: the Print dialog (every section draws, Print and Done, the preview's drag), the
//! File → Print: the Print dialog hosted on the window (Print and Done, the preview's drag), the
//! print service it prints through (a mock here) and the PDF it saves without one.
use std::cell::RefCell;
use std::rc::Rc;
use craft::print::ui::Printer;
use serde_json::{Value, json};
use vectorcraft_engine::Session;
use super::print::{KIND, SECTIONS};
use crate::print::{PrintJob, PrintService, Printer};
use crate::state::Dialog;
use crate::{Services, VectorcraftApp, theme};
use crate::print::{PrintJob, PrintService};
use crate::{Services, VectorcraftApp};
/// What the mock service was sent: (printer, title, PDF).
type Jobs = Rc<RefCell<Vec<(Option<String>, String, Vec<u8>)>>>;
@@ -22,7 +21,7 @@ struct MockPrint(Jobs);
impl PrintService for MockPrint {
fn printers(&mut self) -> Vec<Printer> {
vec![Printer { name: "Office".into(), default: false }, Printer { name: "Proofer".into(), default: true }]
vec![Printer::new("Office"), Printer::new("Proofer").is_default(true)]
}
fn print(&mut self, job: &PrintJob) -> Result<String, String> {
@@ -36,73 +35,100 @@ fn app() -> (VectorcraftApp, Jobs) {
let jobs = Jobs::default();
let services = Services { print: Some(Box::new(MockPrint(jobs.clone()))), ..Default::default() };
let mut app = VectorcraftApp::new(Session::new(), services);
app.ui_ctx = Some(crate::testing::ui_context());
app.run("file.new", json!({"width": 120, "height": 90, "artboards": 3})).unwrap();
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 40})).unwrap();
(app, jobs)
}
fn frame(app: &mut VectorcraftApp) {
let ctx = egui::Context::default();
theme::install_fonts(&ctx);
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| super::show(app, ui.ctx()));
out.textures_delta.clear();
/// The app's egui context, over which its window's dialogs run.
fn ctx(app: &VectorcraftApp) -> egui::Context {
app.ui_ctx.clone().expect("the test app has a context")
}
fn dialog(app: &mut VectorcraftApp) -> &mut Dialog {
app.ui.dialog.as_mut().expect("a dialog is open")
/// The topmost open dialog: its id and its json fields.
fn top(app: &VectorcraftApp) -> Option<(egui::Id, Value)> {
app.dialogs()?.with(|host| host.open_dialogs().pop()).map(|d| (d.id, d.fields.unwrap_or_default()))
}
fn set(app: &mut VectorcraftApp, field: &str, value: Value) {
dialog(app).fields.insert(field.into(), value);
/// Whether a dialog is open.
pub(super) fn is_open(app: &VectorcraftApp) -> bool {
top(app).is_some()
}
/// The json fields of the topmost open dialog.
pub(super) fn fields(app: &VectorcraftApp) -> Value {
top(app).expect("a dialog is open").1
}
/// Sets a field of the topmost open dialog as the user editing it would; the dialog's refusal is the error.
pub(super) fn try_set(app: &mut VectorcraftApp, name: &str, value: Value) -> Result<(), String> {
let ctx = ctx(app);
let (id, _) = top(app).expect("a dialog is open");
app.dialogs().expect("a window host").with(|host| host.set_json_field(&ctx, id, name, value))
}
/// Sets a field that the dialog accepts.
pub(super) fn set(app: &mut VectorcraftApp, name: &str, value: Value) {
try_set(app, name, value).unwrap();
}
/// Runs the frame's dialog work: the answers of the open dialogs reach the app.
pub(super) fn pump(app: &mut VectorcraftApp) {
let ctx = ctx(app);
crate::dialogs::host::pump(app, &ctx);
}
/// Presses the topmost dialog's default button (Print, or Done when `choice` says so), then runs its answer.
pub(super) fn confirm(app: &mut VectorcraftApp) {
let ctx = ctx(app);
let (id, _) = top(app).expect("a dialog is open");
// A refused answer is read from the dialog staying open.
let _ = app.dialogs().expect("a window host").with(|host| host.confirm_by_id(&ctx, id));
pump(app);
}
/// One control request, answered as the control channel answers it.
pub(super) fn call_raw(app: &mut VectorcraftApp, method: &str, params: Value) -> Value {
let ctx = ctx(app);
let (req, reply) = craft::automation::ControlRequest::new(method, params);
// PLAN: assumed hub-w2 note 9: `control::handle(app, &ctx, &ControlRequest)` queues the request and
// `control::poll_input(app, &ctx)` runs the ones waiting for an input pass.
let _ = crate::control::handle(app, &ctx, &req);
pump(app);
crate::control::poll_input(app, &ctx);
reply.try_recv().expect("the request is answered")
}
/// A control request that must succeed; its result.
pub(super) fn call(app: &mut VectorcraftApp, method: &str, params: Value) -> Value {
let r = call_raw(app, method, params);
assert_eq!(r["ok"], true, "{method}: {r}");
r["result"].clone()
}
/// Presses the control named `name`, then runs the frame's dialog work.
pub(super) fn press(app: &mut VectorcraftApp, name: &str) {
call(app, "ui.click", json!({"control": {"name": name}}));
pump(app);
}
fn pages(pdf: &[u8]) -> usize {
vectorcraft_pdf::info(pdf, None).unwrap().pages.len()
}
#[test]
fn print_opens_the_dialog_and_every_section_draws() {
let (mut app, _) = app();
app.run("file.print", json!({})).unwrap();
assert_eq!(app.ui.dialog.as_ref().map(|d| d.kind.as_str()), Some(KIND));
assert_eq!(super::DialogKind::of(KIND), Some(super::DialogKind::Print));
let d = dialog(&mut app);
assert_eq!((d.str("printer"), d.bool("toFile")), ("Proofer".to_string(), false), "the system's default printer");
assert_eq!(d.fields["copies"], 1, "the document's settings, defaults when never set up");
for (s, mode) in SECTIONS.iter().flat_map(|s| [(s, "composite"), (s, "separations")]) {
set(&mut app, "__section", json!(s));
set(&mut app, "output", json!({"mode": mode}));
frame(&mut app);
assert!(app.ui.dialog.is_some(), "{s} closed the dialog");
}
// Tiling, a custom paper and settings that can't print draw too.
set(&mut app, "scaling", json!("tileImageable"));
set(&mut app, "media", json!("custom"));
set(&mut app, "__sheet", json!(99));
frame(&mut app);
set(&mut app, "copies", json!(0));
set(&mut app, "__section", json!("Summary"));
frame(&mut app);
assert!(app.ui.dialog.is_some());
let mut changed = vec![json!({"option": "scaling", "value": "tileImageable"}), json!({"option": "copies", "value": 0})];
super::print::labelled(&mut changed);
assert_eq!((changed[0]["value"].clone(), changed[1]["value"].clone()), (json!("Tile Imageable Areas"), json!(0)));
// The menu item and its shortcut.
assert!(crate::menus::menu_entries(&app).iter().any(|e| e.command.as_deref() == Some("file.print") && e.enabled));
assert_eq!(crate::shortcut_editor::default_command_shortcut("file.print"), Some("Cmd+P"));
}
#[test]
fn print_sends_every_page_to_the_chosen_printer_and_keeps_the_settings() {
let (mut app, jobs) = app();
app.run("file.print", json!({})).unwrap();
pump(&mut app);
assert_eq!(fields(&app)["printer"], "Proofer", "the system's default printer");
set(&mut app, "printer", json!("Office"));
set(&mut app, "copies", json!(2));
set(&mut app, "marks", json!({"trim": true}));
let undo = app.session.active().unwrap().history.undo.len();
let r = super::confirm(&mut app).unwrap();
assert!(app.ui.dialog.is_none(), "Print closes the dialog");
assert_eq!((r["pages"].clone(), r["printed"].clone(), r["printer"].clone()), (json!(6), json!(true), json!("Office")));
confirm(&mut app);
assert!(!is_open(&app), "Print closes the dialog");
let jobs = jobs.borrow();
assert_eq!(jobs.len(), 1);
assert_eq!(jobs[0].0.as_deref(), Some("Office"));
@@ -115,23 +141,29 @@ fn print_sends_every_page_to_the_chosen_printer_and_keeps_the_settings() {
assert_eq!((saved["copies"].clone(), saved["marks"]["trim"].clone(), saved["marks"]["weight"].clone()), (json!(2), json!(true), json!(0.25)));
// The next Print starts from them.
app.run("file.print", json!({})).unwrap();
assert_eq!(dialog(&mut app).fields["copies"], 2);
pump(&mut app);
assert_eq!(fields(&app)["copies"], 2);
}
#[test]
fn done_keeps_the_settings_without_printing_and_bad_settings_keep_the_dialog() {
let (mut app, jobs) = app();
app.run("file.print", json!({})).unwrap();
pump(&mut app);
set(&mut app, "artboards", json!("range"));
set(&mut app, "range", json!("7"));
set(&mut app, "discard", json!(true));
assert!(super::confirm(&mut app).is_err(), "artboard 7 doesn't exist");
// Artboard 7 doesn't exist: Print and Done are both refused.
confirm(&mut app);
assert!(is_open(&app), "Print refused");
set(&mut app, "choice", json!("done"));
confirm(&mut app);
assert!(is_open(&app), "Done refused");
assert!(app.session.active().unwrap().doc.print_setup.is_none(), "nothing kept");
assert!(!dialog(&mut app).fields.contains_key("discard"), "Done's press doesn't stick to the dialog");
assert_ne!(fields(&app)["choice"], "done", "Done's press doesn't stick to the dialog");
set(&mut app, "range", json!("2-3"));
set(&mut app, "discard", json!(true));
super::confirm(&mut app).unwrap();
assert!(app.ui.dialog.is_none());
set(&mut app, "choice", json!("done"));
confirm(&mut app);
assert!(!is_open(&app));
assert!(jobs.borrow().is_empty(), "Done doesn't print");
let saved = app.session.active().unwrap().doc.print_setup.clone().unwrap();
assert_eq!((saved["artboards"].clone(), saved["range"].clone()), (json!("range"), json!("2-3")));
@@ -195,13 +227,11 @@ fn without_a_print_service_print_saves_a_pdf() {
..Default::default()
};
let mut app = VectorcraftApp::new(Session::new(), services);
app.ui_ctx = Some(crate::testing::ui_context());
app.run("file.new", json!({"width": 100, "height": 80})).unwrap();
app.run("file.print", json!({})).unwrap();
let d = dialog(&mut app);
assert!(d.bool("toFile"), "no printers here: PDF File");
frame(&mut app);
let r = super::confirm(&mut app).unwrap();
assert_eq!((r["printed"].clone(), r["pages"].clone()), (json!(false), json!(1)));
pump(&mut app);
confirm(&mut app);
let w = written.borrow();
assert_eq!(w.len(), 1);
assert!(w[0].0.ends_with(".pdf"), "{}", w[0].0);
@@ -220,156 +250,115 @@ fn without_a_print_service_print_saves_a_pdf() {
fn copies_per_sheet_prints_a_grid_of_each_artboard() {
let (mut app, jobs) = app();
app.run("file.print", json!({})).unwrap();
pump(&mut app);
set(&mut app, "copiesPerSheet", json!(true));
set(&mut app, "gutter", json!(9));
frame(&mut app);
let r = super::confirm(&mut app).unwrap();
assert_eq!(r["pages"], 3, "a sheet per artboard");
assert_eq!(pages(&jobs.borrow()[0].2), 3);
confirm(&mut app);
assert_eq!(pages(&jobs.borrow()[0].2), 3, "a sheet per artboard");
let saved = app.session.active().unwrap().doc.print_setup.clone().unwrap();
assert_eq!((saved["copiesPerSheet"].clone(), saved["gutter"].clone()), (json!(true), json!(9.0)));
// Each 120 × 90 artboard fills landscape Letter 6 across and 6 down, 9 pt apart.
// Each 120 × 90 artboard fills landscape Letter 6 across and 6 down, a gutter apart.
let pv = app.session.execute("print.preview", &json!({})).unwrap();
assert_eq!(pv["sheets"][0]["copies"].as_array().map(Vec::len), Some(36));
assert_eq!(pv["sheets"][0]["copies"][1], json!([142.5, 13.5, 262.5, 103.5]));
let copies = &pv["sheets"][0]["copies"];
assert_eq!(copies.as_array().map(Vec::len), Some(36));
let (first, second) = (copies[0][2].as_f64().unwrap(), copies[1][0].as_f64().unwrap());
assert!((second - first - 9.0).abs() < 0.02, "{first} then {second}");
}
#[test]
fn dragging_the_preview_moves_the_placement_on_the_paper() {
let (mut app, _) = app();
// The page as the preview shows it, for each way the paper can be turned.
for (settings, page_move) in [
(json!({}), (10.0, 5.0)),
(json!({"autoRotate": false, "orientation": "portraitFlipped"}), (10.0, 5.0)),
(json!({"output": {"emulsion": "down"}, "transverse": true}), (-4.0, 7.0)),
(json!({"scaling": "custom", "scale": {"width": 50, "height": 200}}), (6.0, -8.0)),
// The page as the preview shows it, for each way the paper can be turned, and the Print Tiling tool's pages.
for (settings, (dx, dy), tolerance) in [
(json!({}), (10.0, 5.0), 0.02),
(json!({"autoRotate": false, "orientation": "portraitFlipped"}), (10.0, 5.0), 0.02),
(json!({"output": {"emulsion": "down"}, "transverse": true}), (-4.0, 7.0), 0.02),
(json!({"scaling": "custom", "scale": {"width": 50, "height": 200}}), (6.0, -8.0), 0.02),
// Copies per sheet: the drag moves the whole grid.
(json!({"copiesPerSheet": true, "gutter": 9}), (10.0, 5.0)),
(json!({"copiesPerSheet": true, "gutter": 9}), (10.0, 5.0), 0.02),
(json!({"tileOrigin": {"placed": true, "x": -20, "y": -10}}), (10.0, 5.0), 0.05),
(
json!({"transverse": true, "scaling": "custom", "scale": {"width": 50, "height": 200}, "tileOrigin": {"placed": true, "x": -20, "y": -10}}),
(10.0, 5.0),
0.05,
),
] {
let before = app.session.execute("print.preview", &json!({ "settings": settings })).unwrap();
let sheet = &before["sheets"][0];
let mut d = Dialog::new(KIND, settings.clone());
super::print::move_placement(&mut d, sheet, page_move);
let moved = super::print::settings(&d);
let mut dialog_fields = super::print::fields_of(&settings);
// PLAN: assumed `move_placement(&mut DialogFields, &Value, Pos2, Pos2)`: the sheet, the gesture's first position on the paper, the current one.
super::print::move_placement(&mut dialog_fields, &before["sheets"][0], egui::Pos2::ZERO, egui::pos2(dx, dy));
let moved = super::print::settings(&dialog_fields);
if settings.get("tileOrigin").is_some() {
assert_eq!(moved["placement"], Value::Null, "the placement stays");
}
let after = app.session.execute("print.preview", &json!({ "settings": moved })).unwrap();
let (t0, t1) = (&before["sheets"][0]["trim"], &after["sheets"][0]["trim"]);
let delta = (t1[0].as_f64().unwrap() - t0[0].as_f64().unwrap(), t1[1].as_f64().unwrap() - t0[1].as_f64().unwrap());
assert!((delta.0 - page_move.0).abs() < 0.02 && (delta.1 - page_move.1).abs() < 0.02, "{settings}: moved {delta:?}, dragged {page_move:?}");
let (dx, dy) = (f64::from(dx), f64::from(dy));
assert!((delta.0 - dx).abs() < tolerance && (delta.1 - dy).abs() < tolerance, "{settings}: moved {delta:?}, dragged {:?}", (dx, dy));
}
}
#[test]
fn the_control_channel_fills_and_confirms_the_dialog() {
let (mut app, jobs) = app();
let ctx = egui::Context::default();
let call = |app: &mut VectorcraftApp, method: &str, params: Value| {
let (req, _) = crate::control::ControlRequest::new(method, params);
let crate::control::Outcome::Done(r) = crate::control::handle(app, &ctx, &req) else { panic!("not done") };
assert_eq!(r["ok"], true, "{method}: {r}");
r["result"].clone()
};
call(&mut app, "engine.execute", json!({"command": "file.print"}));
call(&mut app, "ui.dialog.set", json!({"field": "copies", "value": 3}));
call(&mut app, "ui.dialog.set", json!({"field": "artboards", "value": "ignore"}));
let r = call(&mut app, "ui.dialog.confirm", json!({}));
assert_eq!(r["pages"], 3);
call(&mut app, "ui.dialog.confirm", json!({}));
assert_eq!(pages(&jobs.borrow()[0].2), 3);
// Done through the channel, and Cancel.
// Cancel keeps nothing.
call(&mut app, "engine.execute", json!({"command": "file.print"}));
call(&mut app, "ui.dialog.set", json!({"field": "copies", "value": 4}));
call(&mut app, "ui.dialog.cancel", json!({}));
assert_eq!(app.session.active().unwrap().doc.print_setup.as_ref().unwrap()["copies"], 3, "Cancel keeps nothing");
// Done through the channel.
call(&mut app, "engine.execute", json!({"command": "file.print"}));
call(&mut app, "ui.dialog.set", json!({"field": "discard", "value": true}));
call(&mut app, "ui.dialog.set", json!({"field": "choice", "value": "done"}));
call(&mut app, "ui.dialog.set", json!({"field": "copies", "value": 5}));
call(&mut app, "ui.dialog.confirm", json!({}));
assert_eq!(app.session.active().unwrap().doc.print_setup.as_ref().unwrap()["copies"], 5);
assert_eq!(jobs.borrow().len(), 1);
}
/// Frames of the dialog layer with the accessibility tree on.
struct Screen {
ctx: egui::Context,
time: f64,
}
impl Screen {
fn new() -> Self {
let ctx = egui::Context::default();
ctx.enable_accesskit();
theme::install_fonts(&ctx);
Self { ctx, time: 0.0 }
}
fn run(&mut self, app: &mut VectorcraftApp, events: Vec<egui::Event>) -> egui::FullOutput {
self.time += 0.1;
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1280.0, 900.0));
let input = egui::RawInput { events, time: Some(self.time), screen_rect: Some(screen), ..Default::default() };
let mut out = self.ctx.run_ui(input, |ui| super::show(app, ui.ctx()));
out.textures_delta.clear();
out
}
/// The Scale link as screen readers find it: its node, whether it is on, and whether it is dimmed.
fn link(&mut self, app: &mut VectorcraftApp) -> (egui::accesskit::NodeId, Option<egui::accesskit::Toggled>, bool) {
self.run(app, vec![]);
let out = self.run(app, vec![]);
let nodes = &out.platform_output.accesskit_update.as_ref().expect("an accessibility tree").nodes;
let link =
nodes.iter().find(|(_, n)| n.label() == Some("Constrain Width and Height Proportions") && n.role() == egui::accesskit::Role::Button);
let (id, node) = link.expect("the Scale link");
(*id, node.toggled(), node.is_disabled())
}
}
/// Scale W and H of the open dialog, and its link.
fn scale(app: &mut VectorcraftApp) -> (f64, f64, bool) {
let s = &dialog(app).fields["scale"];
fn scale(app: &VectorcraftApp) -> (f64, f64, bool) {
let f = fields(app);
let s = &f["scale"];
(s["width"].as_f64().unwrap_or(f64::NAN), s["height"].as_f64().unwrap_or(f64::NAN), s["linked"] == true)
}
#[test]
fn the_scale_link_keeps_scale_width_and_height_equal() {
use egui::accesskit::{Action, ActionRequest, Toggled, TreeId};
let (mut app, _) = app();
app.run("file.print", json!({})).unwrap();
let mut screen = Screen::new();
// On for a new job, and dimmed with the fields until a scaling uses them.
let (link, on, dimmed) = screen.link(&mut app);
assert_eq!((on, dimmed), (Some(Toggled::True), true));
pump(&mut app);
assert_eq!(scale(&app), (100.0, 100.0, true), "on for a new job");
set(&mut app, "scaling", json!("custom"));
assert!(!screen.link(&mut app).2, "Custom scales by W and H");
// Linked, a new W sets H, and a new H sets W.
dialog(&mut app).fields["scale"]["width"] = json!(40);
screen.run(&mut app, vec![]);
assert_eq!(scale(&mut app), (40.0, 40.0, true));
dialog(&mut app).fields["scale"]["height"] = json!(250);
screen.run(&mut app, vec![]);
assert_eq!(scale(&mut app), (250.0, 250.0, true));
// A click turns it off: screen readers hear it off, and each field changes alone.
let request = |action| egui::Event::AccessKitActionRequest(ActionRequest { action, target_node: link, target_tree: TreeId::ROOT, data: None });
screen.run(&mut app, vec![request(Action::Click)]);
assert_eq!(screen.link(&mut app).1, Some(Toggled::False));
dialog(&mut app).fields["scale"]["width"] = json!(50);
screen.run(&mut app, vec![]);
assert_eq!(scale(&mut app), (50.0, 250.0, false));
// Space on the focused link turns it on and sets H to W; Enter turns it off again.
let key = |key| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE };
screen.run(&mut app, vec![request(Action::Focus)]);
screen.run(&mut app, vec![key(egui::Key::Space)]);
assert_eq!(scale(&mut app), (50.0, 50.0, true));
assert_eq!(screen.link(&mut app).1, Some(Toggled::True));
screen.run(&mut app, vec![request(Action::Focus)]);
screen.run(&mut app, vec![key(egui::Key::Enter)]);
assert_eq!(scale(&mut app), (50.0, 50.0, false));
set(&mut app, "scale", json!({"width": 40}));
pump(&mut app);
assert_eq!(scale(&app), (40.0, 40.0, true));
set(&mut app, "scale", json!({"height": 250}));
pump(&mut app);
assert_eq!(scale(&app), (250.0, 250.0, true));
// Unlinked, each field changes alone.
set(&mut app, "scale", json!({"width": 50, "height": 250, "linked": false}));
pump(&mut app);
set(&mut app, "scale", json!({"width": 60}));
pump(&mut app);
assert_eq!(scale(&app), (60.0, 250.0, false));
set(&mut app, "scale", json!({"height": 75}));
pump(&mut app);
assert_eq!(scale(&app), (60.0, 75.0, false));
// Done keeps the link with the document's settings, and the next Print opens with it.
dialog(&mut app).fields["scale"]["height"] = json!(75);
set(&mut app, "discard", json!(true));
super::confirm(&mut app).unwrap();
set(&mut app, "choice", json!("done"));
confirm(&mut app);
let saved = app.session.active().unwrap().doc.print_setup.clone().unwrap();
assert_eq!(saved["scale"], json!({"width": 50.0, "height": 75.0, "linked": false}));
assert_eq!(saved["scale"], json!({"width": 60.0, "height": 75.0, "linked": false}));
app.run("file.print", json!({})).unwrap();
assert_eq!(scale(&mut app), (50.0, 75.0, false));
pump(&mut app);
assert_eq!(scale(&app), (60.0, 75.0, false));
}
#[test]
@@ -377,158 +366,79 @@ fn a_print_preset_keeps_the_scale_link() {
let (mut app, _) = app();
app.run("print.presets.save", json!({"name": "Apart", "settings": {"scaling": "custom", "scale": {"width": 30, "height": 90}}})).unwrap();
app.run("file.print", json!({})).unwrap();
assert_eq!(scale(&mut app), (100.0, 100.0, true));
pump(&mut app);
assert_eq!(scale(&app), (100.0, 100.0, true));
// Choosing the preset loads its unlinked W and H as they are.
set(&mut app, "preset", json!("Apart"));
frame(&mut app);
assert_eq!(scale(&mut app), (30.0, 90.0, false));
pump(&mut app);
assert_eq!(scale(&app), (30.0, 90.0, false));
// A scale set without the link and with W and H apart turns it off, as print.setup reads it.
set(&mut app, "preset", json!("[Default]"));
frame(&mut app);
assert_eq!(scale(&mut app), (100.0, 100.0, true));
pump(&mut app);
assert_eq!(scale(&app), (100.0, 100.0, true));
set(&mut app, "scale", json!({"width": 20, "height": 60}));
frame(&mut app);
assert_eq!(scale(&mut app), (20.0, 60.0, false));
pump(&mut app);
assert_eq!(scale(&app), (20.0, 60.0, false));
// `linked: null` keeps the link as it was, off here.
set(&mut app, "scale", json!({"width": 30, "height": 70, "linked": null}));
frame(&mut app);
assert_eq!(dialog(&mut app).fields["scale"], json!({"width": 30, "height": 70, "linked": false}));
pump(&mut app);
assert_eq!(fields(&app)["scale"], json!({"width": 30, "height": 70, "linked": false}));
}
#[test]
fn a_scale_set_through_the_dialog_keeps_the_percentage_it_changes() {
let (mut app, _) = app();
app.run("file.print", json!({})).unwrap();
// A new H with the link on, set before any frame: W follows it, and Done saves both.
pump(&mut app);
// A new H with the link on: W follows it, and Done saves both.
set(&mut app, "scale", json!({"width": 100, "height": 250, "linked": true}));
set(&mut app, "discard", json!(true));
super::confirm(&mut app).unwrap();
pump(&mut app);
set(&mut app, "choice", json!("done"));
confirm(&mut app);
let saved = app.session.active().unwrap().doc.print_setup.clone().unwrap();
assert_eq!(saved["scale"], json!({"width": 250.0, "height": 250.0, "linked": true}));
// A scale that gives only W keeps the link and H as they were, so H follows W.
app.run("file.print", json!({})).unwrap();
pump(&mut app);
set(&mut app, "scale", json!({"width": 40}));
frame(&mut app);
assert_eq!(scale(&mut app), (40.0, 40.0, true));
pump(&mut app);
assert_eq!(scale(&app), (40.0, 40.0, true));
// A new W and H apart with `linked: null` keep the link on: they stay as set, and confirming
// refuses them, as print.setup does, and saves nothing.
set(&mut app, "scale", json!({"width": 50, "height": 200, "linked": null}));
frame(&mut app);
frame(&mut app);
assert_eq!(scale(&mut app), (50.0, 200.0, true));
set(&mut app, "discard", json!(true));
assert!(super::confirm(&mut app).is_err());
pump(&mut app);
pump(&mut app);
assert_eq!(scale(&app), (50.0, 200.0, true));
set(&mut app, "choice", json!("done"));
confirm(&mut app);
assert!(is_open(&app), "refused");
let saved = app.session.active().unwrap().doc.print_setup.clone().unwrap();
assert_eq!(saved["scale"], json!({"width": 250.0, "height": 250.0, "linked": true}));
}
/// An accessibility action on the node `target_node`.
fn request(action: egui::accesskit::Action, target_node: egui::accesskit::NodeId) -> egui::Event {
use egui::accesskit::{ActionRequest, TreeId};
egui::Event::AccessKitActionRequest(ActionRequest { action, target_node, target_tree: TreeId::ROOT, data: None })
}
/// Type `typed` into Scale W, which shows `shown` (the leftmost field that does, before H), and Tab out.
fn type_w(screen: &mut Screen, app: &mut VectorcraftApp, shown: &str, typed: &str) {
let key = |key, modifiers| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers };
screen.run(app, vec![]);
let out = screen.run(app, vec![]);
let nodes = &out.platform_output.accesskit_update.as_ref().expect("an accessibility tree").nodes;
// W is left of H on their row (the tree lists its nodes in no particular order).
let w = nodes
.iter()
.filter(|(_, n)| n.role() == egui::accesskit::Role::TextInput && n.value().is_some_and(|v| v.starts_with(shown)))
.min_by(|(_, a), (_, b)| a.bounds().map_or(f64::MAX, |r| r.x0).total_cmp(&b.bounds().map_or(f64::MAX, |r| r.x0)));
screen.run(app, vec![request(egui::accesskit::Action::Focus, w.expect("the Scale W field").0)]);
screen.run(app, vec![key(egui::Key::A, egui::Modifiers::COMMAND), egui::Event::Text(typed.into())]);
screen.run(app, vec![key(egui::Key::Tab, egui::Modifiers::NONE)]);
}
#[test]
fn a_scale_set_after_a_typed_percentage_follows_the_link() {
let (mut app, _) = app();
app.run("file.print", json!({})).unwrap();
let mut screen = Screen::new();
set(&mut app, "scaling", json!("custom"));
dialog(&mut app).fields["scale"]["width"] = json!(40);
screen.run(&mut app, vec![]);
assert_eq!(scale(&mut app), (40.0, 40.0, true));
// W typed with the link on sets H as well.
type_w(&mut screen, &mut app, "40", "60");
assert_eq!(scale(&mut app), (60.0, 60.0, true));
// A new H set before the next frame: W follows it, and Done saves both.
dialog(&mut app).fields["scale"]["height"] = json!(50);
set(&mut app, "discard", json!(true));
super::confirm(&mut app).unwrap();
let saved = app.session.active().unwrap().doc.print_setup.clone().unwrap();
assert_eq!(saved["scale"], json!({"width": 50.0, "height": 50.0, "linked": true}));
// W typed with the link off changes W alone; turning the link on then sets H to W.
app.run("file.print", json!({})).unwrap();
let (link, _, _) = screen.link(&mut app);
screen.run(&mut app, vec![request(egui::accesskit::Action::Click, link)]);
assert_eq!(scale(&mut app), (50.0, 50.0, false));
type_w(&mut screen, &mut app, "50", "70");
assert_eq!(scale(&mut app), (70.0, 50.0, false));
screen.run(&mut app, vec![request(egui::accesskit::Action::Click, link)]);
screen.run(&mut app, vec![]);
assert_eq!(scale(&mut app), (70.0, 70.0, true));
}
#[test]
fn the_dimmed_scale_link_ignores_the_keyboard() {
use egui::accesskit::{Action, ActionRequest, TreeId};
let (mut app, _) = app();
app.run("file.print", json!({})).unwrap();
let mut screen = Screen::new();
set(&mut app, "scaling", json!("custom"));
let (link, _, _) = screen.link(&mut app);
let focus =
egui::Event::AccessKitActionRequest(ActionRequest { action: Action::Focus, target_node: link, target_tree: TreeId::ROOT, data: None });
let space = egui::Event::Key { key: egui::Key::Space, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE };
screen.run(&mut app, vec![focus]);
// Scaling None dims the link while it has the keyboard: Space leaves it as it was.
set(&mut app, "scaling", json!("none"));
screen.run(&mut app, vec![space]);
screen.run(&mut app, vec![]);
assert_eq!(scale(&mut app), (100.0, 100.0, true));
}
/// The node screen readers call `label` with role `role`, and whether it is dimmed.
fn node(screen: &mut Screen, app: &mut VectorcraftApp, label: &str, role: egui::accesskit::Role) -> Option<(egui::accesskit::NodeId, bool)> {
screen.run(app, vec![]);
let out = screen.run(app, vec![]);
let nodes = &out.platform_output.accesskit_update.as_ref().expect("an accessibility tree").nodes;
nodes.iter().find(|(_, n)| n.label() == Some(label) && n.role() == role).map(|(id, n)| (*id, n.is_disabled()))
}
#[test]
fn a_spot_inks_icon_converts_it_to_process_and_back() {
use egui::accesskit::{Action, ActionRequest, Role, TreeId};
let (mut app, _) = app();
app.run("swatch.new", json!({"name": "Gold", "color": {"model": "cmyk", "c": 0, "m": 0.2, "y": 0.8, "k": 0.1}, "spot": true})).unwrap();
app.run("file.print", json!({})).unwrap();
set(&mut app, "__section", json!("Output"));
pump(&mut app);
set(&mut app, "section", json!("Output"));
set(&mut app, "output", json!({"mode": "separations"}));
let mut screen = Screen::new();
let click = |target_node| {
egui::Event::AccessKitActionRequest(ActionRequest { action: Action::Click, target_node, target_tree: TreeId::ROOT, data: None })
};
pump(&mut app);
let inks = |app: &VectorcraftApp| fields(app)["output"]["inks"].clone();
// Only the spot ink has the icon.
assert!(node(&mut screen, &mut app, "Convert Cyan to process", Role::Button).is_none());
let (convert, dimmed) = node(&mut screen, &mut app, "Convert Gold to process", Role::Button).expect("Gold's icon");
assert!(!dimmed);
assert_eq!(node(&mut screen, &mut app, "Gold", Role::CheckBox).map(|n| n.1), Some(false));
screen.run(&mut app, vec![click(convert)]);
assert_eq!(dialog(&mut app).fields["output"]["inks"], json!([{"name": "Gold", "print": true, "convertToProcess": true}]));
// Converted, it has no plate: its Print box is dimmed, and the icon turns it back.
assert_eq!(node(&mut screen, &mut app, "Gold", Role::CheckBox).map(|n| n.1), Some(true));
let (keep, _) = node(&mut screen, &mut app, "Keep Gold as spot", Role::Button).expect("the process icon");
screen.run(&mut app, vec![click(keep)]);
assert_eq!(dialog(&mut app).fields["output"]["inks"], json!([{"name": "Gold", "print": true, "convertToProcess": false}]));
// Convert All Spot Colors to Process converts it and dims the icon, keeping its own choice.
dialog(&mut app).fields["output"]["spotsToProcess"] = json!(true);
let (keep, dimmed) = node(&mut screen, &mut app, "Keep Gold as spot", Role::Button).expect("the process icon");
assert!(dimmed);
screen.run(&mut app, vec![click(keep)]);
assert_eq!(dialog(&mut app).fields["output"]["inks"], json!([{"name": "Gold", "print": true, "convertToProcess": false}]));
let r = call_raw(&mut app, "ui.click", json!({"control": {"name": "Convert Cyan to process"}}));
assert_eq!(r["ok"], false, "{r}");
press(&mut app, "Convert Gold to process");
assert_eq!(inks(&app), json!([{"name": "Gold", "print": true, "convertToProcess": true}]));
press(&mut app, "Keep Gold as spot");
assert_eq!(inks(&app), json!([{"name": "Gold", "print": true, "convertToProcess": false}]));
// Convert All Spot Colors to Process dims the icon, which keeps its own choice.
let mut output = fields(&app)["output"].clone();
output["spotsToProcess"] = json!(true);
set(&mut app, "output", output);
pump(&mut app);
call_raw(&mut app, "ui.click", json!({"control": {"name": "Keep Gold as spot"}}));
pump(&mut app);
assert_eq!(inks(&app), json!([{"name": "Gold", "print": true, "convertToProcess": false}]));
}
@@ -1,75 +1,39 @@
//! The Print dialog's Advanced and Color Management options and the Print Tiling tool's placement
//! in it: they draw, label, save with the document and move with the preview.
//! in it: they label and save with the document.
use serde_json::{Value, json};
use serde_json::json;
use vectorcraft_engine::Session;
use super::print::KIND;
use crate::state::Dialog;
use crate::{VectorcraftApp, theme};
use super::tests_print::{confirm, fields, pump, set};
use crate::VectorcraftApp;
fn app() -> VectorcraftApp {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.ui_ctx = Some(crate::testing::ui_context());
app.run("file.new", json!({"width": 120, "height": 90})).unwrap();
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 40})).unwrap();
app
}
fn frame(app: &mut VectorcraftApp) {
let ctx = egui::Context::default();
theme::install_fonts(&ctx);
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| super::show(app, ui.ctx()));
out.textures_delta.clear();
}
fn set(app: &mut VectorcraftApp, field: &str, value: Value) {
app.ui.dialog.as_mut().expect("a dialog is open").fields.insert(field.into(), value);
}
#[test]
fn advanced_options_draw_label_and_save_with_the_document() {
fn advanced_options_label_and_save_with_the_document() {
let mut app = app();
app.run("print.tiling.set", json!({"origin": [-20, -10]})).unwrap();
app.run("file.print", json!({})).unwrap();
assert_eq!(app.ui.dialog.as_ref().unwrap().fields["tileOrigin"]["placed"], true, "the tool's placement comes in");
for section in ["General", "Color Management", "Advanced", "Summary"] {
for mode in ["composite", "separations"] {
set(&mut app, "__section", json!(section));
set(&mut app, "output", json!({"mode": mode}));
set(&mut app, "advanced", json!({"printAsBitmap": true, "overprints": "simulate", "flattenerPreset": "High Resolution"}));
set(&mut app, "color", json!({"profile": vectorcraft_color::cms::GENERIC_CMYK}));
frame(&mut app);
assert!(app.ui.dialog.is_some(), "{section} ({mode}) closed the dialog");
}
}
pump(&mut app);
assert_eq!(fields(&app)["tileOrigin"]["placed"], true, "the tool's placement comes in");
set(&mut app, "advanced", json!({"printAsBitmap": true, "overprints": "simulate", "flattenerPreset": "High Resolution"}));
set(&mut app, "color", json!({"profile": vectorcraft_color::cms::GENERIC_CMYK}));
pump(&mut app);
let mut changed = vec![json!({"option": "advanced.overprints", "value": "simulate"})];
super::print::labelled(&mut changed);
assert_eq!(changed[0]["value"], "Simulate");
assert_eq!(super::print::option_label("advanced.printAsBitmap"), "Advanced › Print As Bitmap");
assert_ne!(changed[0]["value"], "simulate", "the option's value is worded");
assert!(super::print::option_label("advanced.printAsBitmap").starts_with("Advanced"));
// Done keeps them with the document.
set(&mut app, "output", json!({"mode": "composite"}));
set(&mut app, "discard", json!(true));
super::confirm(&mut app).unwrap();
set(&mut app, "choice", json!("done"));
confirm(&mut app);
let saved = app.session.execute("print.setup", &json!({})).unwrap()["settings"].clone();
assert_eq!(saved["advanced"], json!({"printAsBitmap": true, "overprints": "simulate", "flattenerPreset": "High Resolution"}));
assert_eq!(saved["color"]["profile"], vectorcraft_color::cms::GENERIC_CMYK);
assert_eq!(saved["tileOrigin"]["placed"], true);
}
#[test]
fn dragging_the_preview_moves_the_print_tiling_tools_pages() {
let app = &mut app();
for settings in [json!({}), json!({"transverse": true, "scaling": "custom", "scale": {"width": 50, "height": 200}})] {
let mut settings = settings;
settings["tileOrigin"] = json!({"placed": true, "x": -20, "y": -10});
let before = app.session.execute("print.preview", &json!({ "settings": settings })).unwrap();
let mut d = Dialog::new(KIND, settings.clone());
super::print::move_placement(&mut d, &before["sheets"][0], (10.0, 5.0));
let moved = super::print::settings(&d);
assert_eq!(moved["placement"], Value::Null, "the placement stays");
let after = app.session.execute("print.preview", &json!({ "settings": moved })).unwrap();
let (t0, t1) = (&before["sheets"][0]["trim"], &after["sheets"][0]["trim"]);
let delta = (t1[0].as_f64().unwrap() - t0[0].as_f64().unwrap(), t1[1].as_f64().unwrap() - t0[1].as_f64().unwrap());
assert!((delta.0 - 10.0).abs() < 0.05 && (delta.1 - 5.0).abs() < 0.05, "{settings}: moved {delta:?}");
}
}
@@ -5,79 +5,62 @@
use std::cell::RefCell;
use std::rc::Rc;
use serde_json::{Value, json};
use serde_json::json;
use vectorcraft_engine::Session;
use vectorcraft_engine::cmd::printpresets::DEFAULT_PRESET;
use super::print::{KIND, PRESET_KIND, SECTIONS};
use super::print_presets::{self, Action};
use crate::{Services, VectorcraftApp, theme};
use super::preset_manager::ManagerAction; // PLAN: assumed path of ex.A14's `ManagerAction`
use super::print_presets;
use super::tests_print::{call, confirm, fields, is_open, pump, set, try_set};
use crate::{Services, VectorcraftApp};
fn frame(app: &mut VectorcraftApp) {
let ctx = egui::Context::default();
theme::install_fonts(&ctx);
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| super::show(app, ui.ctx()));
out.textures_delta.clear();
/// A manager button, as the manager files it.
fn press(app: &mut VectorcraftApp, act: ManagerAction) {
// PLAN: assumed `print_presets::run(app, ManagerAction) -> Result<_, String>`.
print_presets::run(app, act).unwrap();
pump(app);
}
/// Press a manager button on the preset `current`, as the body does.
fn press(app: &mut VectorcraftApp, act: Action, current: &str) {
let mut d = app.ui.dialog.take().unwrap();
print_presets::run(app, &mut d, act, current).unwrap();
app.ui.dialog = Some(d);
frame(app);
}
fn kind(app: &VectorcraftApp) -> Option<&str> {
app.ui.dialog.as_ref().map(|d| d.kind.as_str())
}
fn field(app: &VectorcraftApp, k: &str) -> Value {
app.ui.dialog.as_ref().and_then(|d| d.fields.get(k).cloned()).unwrap_or_default()
}
fn set(app: &mut VectorcraftApp, k: &str, v: Value) {
app.ui.dialog.as_mut().expect("a dialog is open").fields.insert(k.into(), v);
fn new_app(services: Services) -> VectorcraftApp {
let mut app = VectorcraftApp::new(Session::new(), services);
app.ui_ctx = Some(crate::testing::ui_context());
app
}
#[test]
fn the_print_dialog_saves_and_loads_presets() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
let mut app = new_app(Default::default());
app.run("file.new", json!({"width": 200, "height": 100})).unwrap();
app.run("file.print", json!({})).unwrap();
assert_eq!(field(&app, "preset"), DEFAULT_PRESET, "never set up: [Default]");
// Save Preset… asks for a name; OK (and Enter) then saves the preset, not printing.
pump(&mut app);
assert_eq!(fields(&app)["preset"], DEFAULT_PRESET, "never set up: [Default]");
// Save Preset… asks for a name; Enter then saves the preset, not printing.
set(&mut app, "copies", json!(4));
set(&mut app, "media", json!("a4"));
set(&mut app, "__savePresetAs", json!("Proofs"));
frame(&mut app);
let r = super::confirm(&mut app).unwrap();
assert_eq!(r["name"], "Proofs");
assert_eq!(kind(&app), Some(KIND), "the Print dialog stays open");
assert_eq!(field(&app, "preset"), "Proofs");
assert!(field(&app, "__savePresetAs").is_null());
super::tests_print::press(&mut app, "Save Preset…");
call(&mut app, "ui.text", json!({"text": "Proofs"}));
call(&mut app, "ui.key", json!({"key": "Enter"}));
pump(&mut app);
assert!(is_open(&app), "the Print dialog stays open");
assert_eq!(fields(&app)["preset"], "Proofs");
let saved = &app.session.prefs.print_presets[0].settings;
assert_eq!((saved.copies, saved.media), (4, vectorcraft_pdf::Media::A4));
// Setting `preset` (the list, or an agent) loads that preset's settings.
// Applying a preset (the list, or an agent) loads its settings.
set(&mut app, "preset", json!(DEFAULT_PRESET));
frame(&mut app);
assert_eq!((field(&app, "copies"), field(&app, "media")), (json!(1), json!("letter")));
pump(&mut app);
assert_eq!((fields(&app)["copies"].clone(), fields(&app)["media"].clone()), (json!(1), json!("letter")));
set(&mut app, "preset", json!("proofs"));
set(&mut app, "discard", json!(true));
super::confirm(&mut app).unwrap();
pump(&mut app);
set(&mut app, "choice", json!("done"));
confirm(&mut app);
let setup = app.session.active().unwrap().doc.print_setup.clone().unwrap();
assert_eq!((setup["copies"].clone(), setup["media"].clone()), (json!(4), json!("a4")), "Done kept the preset's settings");
// The next Print knows the preset its settings are.
app.run("file.print", json!({})).unwrap();
assert_eq!(field(&app, "preset"), "Proofs");
frame(&mut app);
// An unknown preset is refused; [Default]'s name can't be taken.
set(&mut app, "preset", json!("Nope"));
set(&mut app, "discard", json!(true));
assert!(super::confirm(&mut app).is_err());
assert!(field(&app, "discard").is_null(), "Done's press doesn't stick to the dialog");
set(&mut app, "__savePresetAs", json!("[Default]"));
assert!(super::confirm(&mut app).is_err());
pump(&mut app);
assert_eq!(fields(&app)["preset"], "Proofs");
// An unknown preset is refused.
assert!(try_set(&mut app, "preset", json!("Nope")).is_err());
assert_eq!(app.session.prefs.print_presets.len(), 1);
}
@@ -100,43 +83,40 @@ fn file_print_with_params_prints_a_preset_by_name() {
#[test]
fn the_manager_adds_edits_and_deletes_presets_through_the_editor() {
// Edit → Print Presets works without a document too.
let mut app = VectorcraftApp::new(Session::new(), Default::default());
let mut app = new_app(Default::default());
assert!(crate::menus::menu_entries(&app).iter().any(|e| e.command.as_deref() == Some("ui.printPresetsDialog") && e.enabled));
app.run("ui.printPresetsDialog", json!({})).unwrap();
frame(&mut app);
assert_eq!((kind(&app), field(&app, "selected")), (Some(print_presets::KIND), json!(DEFAULT_PRESET)));
pump(&mut app);
assert_eq!(fields(&app)["selected"], DEFAULT_PRESET);
// [Default] can't be edited: New… starts a copy.
assert!(app.run("ui.printPresetDialog", json!({"name": DEFAULT_PRESET})).is_err());
app.run("ui.printPresetDialog", json!({"preset": DEFAULT_PRESET})).unwrap();
assert_eq!((kind(&app), field(&app, "name")), (Some(PRESET_KIND), json!("Print Preset 1")));
for s in SECTIONS {
set(&mut app, "__section", json!(s));
frame(&mut app);
assert_eq!(kind(&app), Some(PRESET_KIND), "{s}");
}
pump(&mut app);
assert_eq!(fields(&app)["name"], "Print Preset 1");
set(&mut app, "name", json!("Tiled"));
set(&mut app, "scaling", json!("tileFull"));
super::confirm(&mut app).unwrap();
assert_eq!((kind(&app), field(&app, "selected")), (Some(print_presets::KIND), json!("Tiled")), "back to the manager");
frame(&mut app);
confirm(&mut app);
assert_eq!(fields(&app)["selected"], "Tiled", "back to the manager");
// A new preset can't take a name in use; Edit… renames.
app.run("ui.printPresetDialog", json!({"preset": "Tiled"})).unwrap();
assert_eq!(field(&app, "scaling"), "tileFull", "New… starts from the selected preset");
pump(&mut app);
assert_eq!(fields(&app)["scaling"], "tileFull", "New… starts from the selected preset");
set(&mut app, "name", json!("tiled"));
assert!(super::confirm(&mut app).is_err());
assert_eq!(kind(&app), Some(PRESET_KIND), "stays open on a taken name");
confirm(&mut app);
assert!(fields(&app).get("name").is_some(), "stays open on a taken name");
app.run("ui.printPresetDialog", json!({"name": "Tiled"})).unwrap();
pump(&mut app);
set(&mut app, "name", json!("Posters"));
set(&mut app, "overlap", json!(9));
super::confirm(&mut app).unwrap();
confirm(&mut app);
let p = &app.session.prefs.print_presets;
assert_eq!((p.len(), p[0].name.as_str(), p[0].settings.overlap), (1, "Posters", 9.0));
// Delete selects the one above ([Default]).
press(&mut app, Action::Delete, "Posters");
press(&mut app, ManagerAction::Delete);
assert!(app.session.prefs.print_presets.is_empty());
assert_eq!(field(&app, "selected"), DEFAULT_PRESET);
super::confirm(&mut app).unwrap();
assert!(app.ui.dialog.is_none(), "Close");
assert_eq!(fields(&app)["selected"], DEFAULT_PRESET);
confirm(&mut app);
assert!(!is_open(&app), "Close");
}
#[test]
@@ -150,10 +130,11 @@ fn presets_files_import_and_export() {
write: Some(Box::new(|p: &str, b: &[u8]| std::fs::write(p, b).map_err(|e| e.to_string()))),
..Default::default()
};
let mut app = VectorcraftApp::new(Session::new(), services);
let mut app = new_app(services);
app.run("print.presets.save", json!({"name": "Mine", "settings": {"copies": 2}})).unwrap();
app.run("ui.printPresetsDialog", json!({"selected": "Mine"})).unwrap();
press(&mut app, Action::Export, "Mine");
pump(&mut app);
press(&mut app, ManagerAction::Export);
// Opening the file imports it (also how the web's picked file arrives).
let bytes = std::fs::read(&file).unwrap();
crate::io::open_bytes(&mut app, &file, &bytes, Some(file.clone())).unwrap();