mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 18:25:34 +01:00
Merge pull request #9627 from dotCooCoo/fix/new-brush-approval-after-revert
Require a fresh New Brush opening after Revert
This commit is contained in:
2 files changed
+40
-5
No files matched your search
@@ -164,7 +164,7 @@ pub fn open(app: &mut VectorcraftApp, name: Option<&str>) -> Result<Value, Strin
|
||||
/// with the values it opened with. OK reaches [`ok`] once the dialog's own rows accept it.
|
||||
fn open_dialog(app: &mut VectorcraftApp, f: &Map<String, Value>, object_keys: Option<&[&str]>) -> Result<Value, String> {
|
||||
let source = app.session.active().ok_or("no document open")?;
|
||||
let document = source.uid;
|
||||
let (document, reverts) = (source.uid, source.reverts);
|
||||
let ty = f.get("__type").and_then(Value::as_str).unwrap_or_default();
|
||||
let object = object_keys.is_some();
|
||||
let ctx = app.ui_ctx.clone().ok_or("no window")?;
|
||||
@@ -195,8 +195,12 @@ fn open_dialog(app: &mut VectorcraftApp, f: &Map<String, Value>, object_keys: Op
|
||||
.held_ok();
|
||||
app.ui.brush_options = Some(
|
||||
host::open_held(app, dialog, move |app, result: &ParamResult| {
|
||||
if !object && app.session.active().is_none_or(|st| st.uid != document) {
|
||||
return Err(tl!("Return to the original drawing to edit its brush").into());
|
||||
match app.session.active().filter(|st| st.uid == document) {
|
||||
Some(source) if source.reverts != reverts => {
|
||||
return Err(tl!("The document was reverted. Reopen this dialog to continue.").into());
|
||||
}
|
||||
None if !object => return Err(tl!("Return to the original drawing to edit its brush").into()),
|
||||
_ => {}
|
||||
}
|
||||
ok(app, result)
|
||||
})
|
||||
|
||||
@@ -25,7 +25,7 @@ const TYPES: [&str; 5] = ["calligraphic", "scatter", "art", "bristle", "pattern"
|
||||
/// It starts on Art when there is art, and it starts on Calligraphic otherwise.
|
||||
pub fn open(app: &mut VectorcraftApp, ids: Option<Value>) -> Result<Value, String> {
|
||||
let st = app.session.active().ok_or("no document open")?;
|
||||
let document = st.uid;
|
||||
let (document, reverts) = (st.uid, st.reverts);
|
||||
let art = match &ids {
|
||||
Some(ids) => ids.as_array().is_some_and(|a| !a.is_empty()),
|
||||
None => !st.selection.is_empty(),
|
||||
@@ -38,8 +38,11 @@ pub fn open(app: &mut VectorcraftApp, ids: Option<Value>) -> Result<Value, Strin
|
||||
let dialog =
|
||||
HostedParamDialog::new(&ctx, KIND, fields, move |f| ParamDialog::new(KIND, title.clone(), rows.clone()).values(Bind::bound(f))).held_ok();
|
||||
host::open_held(app, dialog, move |app, answer| {
|
||||
if app.session.active().is_none_or(|st| st.uid != document) {
|
||||
let Some(source) = app.session.active().filter(|st| st.uid == document) else {
|
||||
return Err(tl!("Return to the original drawing to make the brush").into());
|
||||
};
|
||||
if source.reverts != reverts {
|
||||
return Err(tl!("The document was reverted. Reopen this dialog to continue.").into());
|
||||
}
|
||||
confirm(app, &answer.fields, ids.clone())
|
||||
})
|
||||
@@ -182,6 +185,34 @@ mod tests {
|
||||
assert_eq!(open_fields(&app).text("__type"), Some("scatter"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_type_chooser_and_brush_options_require_a_new_opening_after_revert() {
|
||||
for in_options in [false, true] {
|
||||
let dir = vectorcraft_testkit::TempDir::new("new-brush-revert");
|
||||
let mut app = app();
|
||||
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())));
|
||||
let saved = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 20})).unwrap()["id"].clone();
|
||||
app.run("file.saveAs", json!({"path": dir.join("Saved.vectorcraft")})).unwrap();
|
||||
app.run("shape.ellipse", json!({"x": 10, "y": 60, "width": 60, "height": 40})).unwrap();
|
||||
app.run("ui.newBrush", json!({})).unwrap();
|
||||
if in_options {
|
||||
press_ok(&mut app, json!({"type": "art"}));
|
||||
assert_eq!(open_fields(&app).text("__type"), Some("art"));
|
||||
}
|
||||
let source = app.session.active().unwrap();
|
||||
let (uid, reverts) = (source.uid, source.reverts);
|
||||
app.run("file.revert", json!({"confirmed": true})).unwrap();
|
||||
app.run("select.set", json!({"ids": [saved]})).unwrap();
|
||||
let restored = app.session.active().unwrap();
|
||||
assert_eq!((restored.uid, restored.reverts), (uid, reverts + 1));
|
||||
let before = (library(&mut app), undo_steps(&app));
|
||||
let error = super::super::tests_export::try_confirm(&mut app).expect_err("an old brush approval is refused");
|
||||
assert_eq!(error, "The document was reverted. Reopen this dialog to continue.");
|
||||
assert_eq!((library(&mut app), undo_steps(&app)), before);
|
||||
}
|
||||
}
|
||||
|
||||
/// The new brush takes the art its Brush Options opened with: changing or clearing the
|
||||
/// selection while the dialog is open does not change the art, and OK still makes the brush.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user