mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Require fresh Package approval after File Revert (#9641)
This commit is contained in:
1 parent
f3100589b0
commit
315c07fe9d
3 files changed
+37
-6
No files matched your search
@@ -55,7 +55,7 @@ pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
);
|
||||
return Ok(Value::Null);
|
||||
};
|
||||
let document = st.uid;
|
||||
let document = (st.uid, st.reverts);
|
||||
let p = std::path::Path::new(&path);
|
||||
let stem = p.file_stem().map_or_else(|| "Untitled".into(), |s| s.to_string_lossy().into_owned());
|
||||
let folder = p.parent().map(|f| f.to_string_lossy().into_owned()).unwrap_or_default();
|
||||
@@ -107,9 +107,12 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
|
||||
fn require_package_document(app: &VectorcraftApp, document: u64) -> Result<(), String> {
|
||||
if app.session.active().is_none_or(|st| st.uid != document) {
|
||||
fn require_package_document(app: &VectorcraftApp, (document, reverts): (u64, u64)) -> Result<(), String> {
|
||||
let Some(active) = app.session.active().filter(|st| st.uid == document) else {
|
||||
return Err(tl!("Package can only save and collect the document where it was opened.").to_owned());
|
||||
};
|
||||
if active.reverts != reverts {
|
||||
return Err(tl!("The document was reverted. Reopen this dialog to continue.").to_owned());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -160,7 +163,7 @@ pub(super) fn confirm(app: &mut VectorcraftApp, fields: &DialogFields) -> Result
|
||||
return r;
|
||||
}
|
||||
}
|
||||
// A completed background job may have changed the active document while Package waited.
|
||||
// A completed background job may have changed the active document or its loaded contents while Package waited.
|
||||
require_package_document(app, document)?;
|
||||
let package = app.session.prepare_package(¶ms).map_err(|e| e.to_string()).inspect_err(|e| app.ui.status = e.clone())?;
|
||||
let label = format!("Packaging {}", text("name"));
|
||||
|
||||
@@ -665,3 +665,31 @@ fn package_save_first_does_not_save_a_different_drawing() {
|
||||
crate::tests::picks::poll(&mut app, &ctx);
|
||||
assert_eq!(picker.requests().len(), 1, "approval in the opening drawing starts Save As");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn held_package_approval_does_not_write_output_after_revert() {
|
||||
let dir = Folder::new("package-revert");
|
||||
let mut app = saved(&dir);
|
||||
app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|e| e.to_string())));
|
||||
app.session.execute("prefs.set", &json!({"values": {"backgroundExport": false, "backgroundSave": false}})).unwrap();
|
||||
let before = std::fs::read(dir.path("card.vectorcraft")).unwrap();
|
||||
let out = dir.path("out");
|
||||
let output = std::path::Path::new(&out).join("card Folder");
|
||||
app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 30, "height": 30})).unwrap();
|
||||
package_dialog(&mut app, &out);
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
let host = app.dialogs().unwrap();
|
||||
assert!(!host.with(|h| h.confirm_by_id(&ctx, package_id())));
|
||||
assert_eq!(held_state(&app), Some(HeldOk::Waiting));
|
||||
|
||||
app.run("file.revert", json!({"confirmed": true})).unwrap();
|
||||
crate::dialogs::host::pump(&mut app, &ctx);
|
||||
assert!(!output.exists(), "the old approval writes no output");
|
||||
assert_eq!(std::fs::read(dir.path("card.vectorcraft")).unwrap(), before);
|
||||
assert!(matches!(held_state(&app), Some(HeldOk::Refused(_))));
|
||||
|
||||
close_all(&app);
|
||||
package_dialog(&mut app, &out);
|
||||
assert!(press_ok(&mut app));
|
||||
assert!(output.join("card.vectorcraft").exists());
|
||||
}
|
||||
@@ -288,8 +288,8 @@ pub struct VectorcraftApp {
|
||||
pub(crate) three_d: panels::three_d::Model,
|
||||
/// The open export option dialogs and what runs after each.
|
||||
pub(crate) export_dialogs: dialogs::export_host::ExportDialogs,
|
||||
/// The drawing the open Package dialog saves and collects.
|
||||
pub(crate) package_document: Option<u64>,
|
||||
/// The drawing and loaded contents the open Package dialog saves and collects.
|
||||
pub(crate) package_document: Option<(u64, u64)>,
|
||||
/// Save for Web's renders and colour table.
|
||||
pub(crate) web_export: dialogs::save_for_web::WebExport,
|
||||
/// The Flattener Preview panel's model.
|
||||
|
||||
Reference in new issue
Block a user