mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Keep Print presets while the drawing preview is paused
This commit is contained in:
1 parent
b801e1b9d3
commit
e206b0a7af
2 files changed
+30
-13
No files matched your search
@@ -369,6 +369,19 @@ fn serve(app: &mut VectorcraftApp, ctx: &egui::Context, dialogs: &WindowDialogs,
|
||||
let _ = dialogs.with(|h| h.take_by_id::<HostedPrint>(open.id));
|
||||
return false;
|
||||
};
|
||||
for event in std::mem::take(&mut d.events) {
|
||||
apply_preset_event(app, dialogs, open, &mut d.settings, event);
|
||||
}
|
||||
if open.mode == PrintMode::Print {
|
||||
let same = serde_json::from_value::<PrintSettings>(d.settings.clone())
|
||||
.ok()
|
||||
.is_some_and(|s| app.session.print_preset_settings(&open.preset) == Some(s));
|
||||
let held = same.then(|| open.preset.clone());
|
||||
let rows: Vec<PresetRow<String>> = std::iter::once(PresetRow::item(DEFAULT_PRESET.to_string(), tl!(DEFAULT_PRESET), 0))
|
||||
.chain(app.session.prefs.print_presets.iter().map(|p| PresetRow::item(p.name.clone(), p.name.clone(), 0)))
|
||||
.collect();
|
||||
on(dialogs, |p| p.set_presets(rows, held, vec![DEFAULT_PRESET.to_string()]));
|
||||
}
|
||||
if open.document.is_some_and(|document| app.session.active().is_none_or(|st| st.uid != document)) {
|
||||
let message = tl!("Return to the original drawing to print it");
|
||||
on(dialogs, |p| {
|
||||
@@ -397,9 +410,6 @@ fn serve(app: &mut VectorcraftApp, ctx: &egui::Context, dialogs: &WindowDialogs,
|
||||
{
|
||||
app.status(e);
|
||||
}
|
||||
for event in std::mem::take(&mut d.events) {
|
||||
apply_preset_event(app, dialogs, open, &mut d.settings, event);
|
||||
}
|
||||
let doc = app.session.active().map_or((0, 0), |s| (s.uid, s.revision));
|
||||
let stamp = (d.settings.to_string(), doc);
|
||||
let changed = open.preview.as_ref().is_none_or(|(s, _)| *s != stamp);
|
||||
@@ -439,16 +449,6 @@ fn serve(app: &mut VectorcraftApp, ctx: &egui::Context, dialogs: &WindowDialogs,
|
||||
p.set_field("__inks", FieldValue::Json(inks));
|
||||
});
|
||||
}
|
||||
if open.mode == PrintMode::Print {
|
||||
let same = serde_json::from_value::<PrintSettings>(d.settings.clone())
|
||||
.ok()
|
||||
.is_some_and(|s| app.session.print_preset_settings(&open.preset) == Some(s));
|
||||
let held = same.then(|| open.preset.clone());
|
||||
let rows: Vec<PresetRow<String>> = std::iter::once(PresetRow::item(DEFAULT_PRESET.to_string(), tl!(DEFAULT_PRESET), 0))
|
||||
.chain(app.session.prefs.print_presets.iter().map(|p| PresetRow::item(p.name.clone(), p.name.clone(), 0)))
|
||||
.collect();
|
||||
on(dialogs, |p| p.set_presets(rows, held, vec![DEFAULT_PRESET.to_string()]));
|
||||
}
|
||||
if let Some(answer) = d.ok {
|
||||
let result = accept(app, open, &answer, &d.name);
|
||||
on(dialogs, |p| p.answer_ok(result.map_err(Into::into)));
|
||||
|
||||
@@ -510,6 +510,23 @@ fn a_print_preset_keeps_the_scale_link() {
|
||||
assert_eq!(fields(&app)["scale"], json!({"width": 30, "height": 70, "linked": false}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn print_preset_changes_survive_a_paused_preview() {
|
||||
let (mut app, jobs) = app();
|
||||
app.run("print.presets.save", json!({"name": "Apart", "settings": {"scaling": "custom", "scale": {"width": 30, "height": 90}}})).unwrap();
|
||||
app.run("file.print", json!({})).unwrap();
|
||||
pump(&mut app);
|
||||
app.run("file.new", json!({"width": 90, "height": 90})).unwrap();
|
||||
set(&mut app, "preset", json!("Apart"));
|
||||
let ctx = ctx(&app);
|
||||
super::print::pump(&mut app, &ctx);
|
||||
assert_eq!(scale(&app), (30.0, 90.0, false));
|
||||
assert!(jobs.borrow().is_empty());
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
super::print::pump(&mut app, &ctx);
|
||||
assert_eq!(scale(&app), (30.0, 90.0, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_scale_set_through_the_dialog_keeps_the_percentage_it_changes() {
|
||||
let (mut app, _) = app();
|
||||
|
||||
Reference in new issue
Block a user