mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Merge main into feat/scripts-xmp-objects
This commit is contained in:
5 files changed
+73
-9
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"));
|
||||
|
||||
@@ -86,7 +86,7 @@ pub(crate) struct Strip {
|
||||
/// Which command the strip previews.
|
||||
pub kind: StripKind,
|
||||
/// The drawing whose selection and preview the strip uses.
|
||||
document: Option<u64>,
|
||||
document: Option<(u64, u64)>,
|
||||
/// The slider's value, 0 to 100.
|
||||
pub level: f64,
|
||||
/// The selection's document bounds when the strip opened, so the strip stays put while the
|
||||
@@ -102,7 +102,7 @@ pub(crate) struct Strip {
|
||||
|
||||
impl Strip {
|
||||
fn in_source(&self, app: &VectorcraftApp) -> bool {
|
||||
self.document == app.session.active().map(|doc| doc.uid)
|
||||
self.document == app.session.active().map(|doc| (doc.uid, doc.reverts))
|
||||
}
|
||||
|
||||
fn cancel(self, app: &mut VectorcraftApp) {
|
||||
@@ -142,7 +142,7 @@ pub(crate) fn open(app: &mut VectorcraftApp, kind: StripKind) {
|
||||
}
|
||||
let strip = Strip {
|
||||
kind,
|
||||
document: app.session.active().map(|doc| doc.uid),
|
||||
document: app.session.active().map(|doc| (doc.uid, doc.reverts)),
|
||||
level: opening_level(app, kind),
|
||||
bounds: app.selection_bounds(),
|
||||
open: true,
|
||||
|
||||
@@ -293,3 +293,36 @@ fn simplify_slider_and_dialog_simplify_only_the_direct_selected_part_of_a_path()
|
||||
assert_eq!(app.session.doc().unwrap().history.undo.len(), undo_len + 1);
|
||||
kept(&app, "the dialog");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn path_sliders_close_when_file_revert_restores_the_artwork() {
|
||||
for (kind, command) in
|
||||
[(simplify_slider::StripKind::Simplify, "object.path.simplify"), (simplify_slider::StripKind::Smooth, "object.path.smooth")]
|
||||
{
|
||||
let mut app = app_with_dense_path();
|
||||
let id = app.session.active().unwrap().selection.objects[0];
|
||||
let dir = vectorcraft_testkit::TempDir::new("path-slider-revert");
|
||||
app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|e| e.to_string())));
|
||||
app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|e| e.to_string())));
|
||||
app.run("file.saveAs", json!({"path": dir.join("Art.vectorcraft")})).unwrap();
|
||||
app.run("object.move", json!({"dx": 10, "dy": 0})).unwrap();
|
||||
app.run("select.anchors", json!({"id": id.0, "anchors": [[0, 19]]})).unwrap();
|
||||
crate::menus::invoke(&mut app, command, json!({}));
|
||||
settle(&mut app);
|
||||
assert!(simplify_slider::showing_of(&app, kind));
|
||||
assert!(app.session.in_interaction());
|
||||
|
||||
app.run("file.revert", json!({"confirmed": true})).unwrap();
|
||||
app.run("select.anchors", json!({"id": id.0, "anchors": [[0, 19]]})).unwrap();
|
||||
let restored = app.session.active().unwrap().doc.clone();
|
||||
frame(&mut app, vec![]);
|
||||
assert!(!simplify_slider::showing_of(&app, kind), "{command}");
|
||||
assert!(!app.session.in_interaction());
|
||||
assert_eq!(app.session.active().unwrap().doc, restored);
|
||||
|
||||
crate::menus::invoke(&mut app, command, json!({}));
|
||||
settle(&mut app);
|
||||
assert!(simplify_slider::showing_of(&app, kind));
|
||||
assert!(app.session.in_interaction());
|
||||
}
|
||||
}
|
||||
@@ -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