mirror of
https://github.com/storytold/gridcraft.git
synced 2026-12-03 22:41:38 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bcc39e0ba |
@@ -227,11 +227,7 @@ fn services(inbox: Inbox, ctx: egui::Context) -> Services {
|
||||
log::error!("download of {name} failed: {e}");
|
||||
}
|
||||
})),
|
||||
print: Some(Box::new(|bytes: &[u8]| {
|
||||
if let Err(e) = craft_print::browser::print_pdf(bytes) {
|
||||
log::error!("print failed: {e}");
|
||||
}
|
||||
})),
|
||||
print: Some(Box::new(craft_print::browser::print_pdf)),
|
||||
open_url: Some(Box::new(|url: &str| {
|
||||
if let Some(w) = web_sys::window()
|
||||
&& let gridcraft_engine::links::LinkKind::External(url) = gridcraft_engine::links::classify(url)
|
||||
|
||||
@@ -58,7 +58,7 @@ impl SheetApp {
|
||||
self.printing.begin(submit(bytes, self.printing.settings.clone())).map_err(|_| "A print job is already being submitted.".to_owned())?;
|
||||
self.print_feedback_seen = None;
|
||||
} else if let Some(print) = &self.services.print {
|
||||
print(&bytes);
|
||||
print(&bytes)?;
|
||||
} else {
|
||||
return Err("Printing is unavailable here; export a PDF instead.".into());
|
||||
}
|
||||
|
||||
@@ -39,8 +39,10 @@ pub(super) fn print(app: &mut SheetApp, ui: &mut Ui, bs: &mut Backstage, out: &m
|
||||
if ui.add_enabled_ui(can_print, |ui| square_button(ui, Icon::Print, lang.tr("Print"))).inner.clicked()
|
||||
&& app.commit_edit(0, 0, false, false)
|
||||
{
|
||||
app.print_now(params.clone());
|
||||
out.close = app.services.print_native.is_none();
|
||||
match app.run("ui.printSubmit", params.clone()) {
|
||||
Ok(_) => out.close = app.services.print_native.is_none(),
|
||||
Err(error) => app.alert(error),
|
||||
}
|
||||
}
|
||||
ui.add_space(16.0);
|
||||
egui::ComboBox::from_id_salt("backstage_print_scope")
|
||||
|
||||
@@ -4,7 +4,7 @@ type PickSave = Box<dyn Fn(&str) -> Option<String>>;
|
||||
type OpenUrl = Box<dyn Fn(&str)>;
|
||||
type CopyHtml = Box<dyn FnMut(&str, &str) -> Result<(), String>>;
|
||||
type Download = Box<dyn Fn(&str, &[u8])>;
|
||||
type PrintPdf = Box<dyn Fn(&[u8])>;
|
||||
type PrintPdf = Box<dyn Fn(&[u8]) -> Result<(), String>>;
|
||||
|
||||
/// Host services the platform shell provides (file pickers, opening URLs).
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -21,7 +21,10 @@ fn harness(jobs: Rc<RefCell<Vec<Vec<u8>>>>) -> egui_kittest::Harness<'static, Sh
|
||||
app.run("cell.set", json!({"cell": "H20", "input": "Outside"})).unwrap();
|
||||
app.run("pageLayout.pageSetup", json!({"printArea": "F10:H20"})).unwrap();
|
||||
app.run("selection.set", json!({"range": "A1:B2"})).unwrap();
|
||||
app.services.print = Some(Box::new(move |bytes| jobs.borrow_mut().push(bytes.to_vec())));
|
||||
app.services.print = Some(Box::new(move |bytes| {
|
||||
jobs.borrow_mut().push(bytes.to_vec());
|
||||
Ok(())
|
||||
}));
|
||||
app.run("ui.backstage", json!({"page": "print"})).unwrap();
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1000.0, 800.0)).build_ui_state(
|
||||
|ui, app: &mut SheetApp| {
|
||||
@@ -76,3 +79,30 @@ fn the_preview_follows_the_selection_and_each_area_gets_its_own_page() {
|
||||
h.run_steps(4);
|
||||
assert!(h.query_by_label("Page 1 of 2").is_some(), "two areas, two pages");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refused_browser_handoff_keeps_the_print_selection_available_for_retry() {
|
||||
let jobs = Rc::new(RefCell::new(Vec::new()));
|
||||
let mut h = harness(jobs.clone());
|
||||
choose_selection(&mut h);
|
||||
let accepted = h.state_mut().services.print.take();
|
||||
h.state_mut().services.print = Some(Box::new(|_| Err("The browser blocked the print window".into())));
|
||||
let error = h.state_mut().run("ui.printSubmit", json!({})).unwrap_err();
|
||||
assert!(error.contains("blocked the print window"));
|
||||
h.get_all_by_role_and_label(egui::accesskit::Role::Button, "Print").last().expect("Print button").click();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().backstage.is_some());
|
||||
assert!(h.state().message.as_ref().unwrap().1.contains("blocked the print window"));
|
||||
assert!(jobs.borrow().is_empty());
|
||||
|
||||
h.state_mut().message = None;
|
||||
h.state_mut().services.print = accepted;
|
||||
h.run_steps(3);
|
||||
h.get_all_by_role_and_label(egui::accesskit::Role::Button, "Print").last().expect("Print button").click();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().backstage.is_none());
|
||||
let jobs = jobs.borrow();
|
||||
assert_eq!(jobs.len(), 1);
|
||||
assert!(contains(&jobs[0], "(Inside) Tj"));
|
||||
assert!(!contains(&jobs[0], "(Outside) Tj"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user