Retire Export for Screens approvals after Revert

This commit is contained in:
dotCooCoo committed 2026-11-26 17:33:58 -08:00
1 parent 23c05774b7
commit 906a5446ff
2 files changed
+96 -13

No files matched your search

@@ -506,7 +506,7 @@ pub(super) fn artboard_thumb(app: &mut VectorcraftApp, ctx: &Context, i: usize)
/// thumbnails.
fn document_view(app: &mut VectorcraftApp, ctx: &Context) -> (Option<Shown>, Vec<Option<TextureHandle>>) {
let Some(st) = app.session.active() else { return (None, Vec::new()) };
let shown = Shown { key: (st.uid, st.revision), doc: Arc::clone(&st.doc) };
let shown = Shown { key: (st.uid, st.revision), reverts: st.reverts, doc: Arc::clone(&st.doc) };
let thumbs = (0..shown.doc.artboards.len()).map(|i| artboard_thumb(app, ctx, i)).collect();
(Some(shown), thumbs)
}
@@ -515,6 +515,8 @@ fn document_view(app: &mut VectorcraftApp, ctx: &Context) -> (Option<Shown>, Vec
struct Shown {
/// The document's uid and revision.
key: (u64, u64),
/// Which contents of this tab were shown; File Revert preserves its uid.
reverts: u64,
doc: Arc<Document>,
}
@@ -535,9 +537,9 @@ pub(crate) struct ExportForScreensDialog {
/// What the format presets menu asked for, for the pump to run.
pending: Option<PresetPick>,
/// The document an artboard rename began in, while it runs.
renaming_in: Option<u64>,
/// A committed artboard name: (document uid, artboard id, name), for the pump to run.
rename: Option<(u64, u32, String)>,
renaming_in: Option<(u64, u64)>,
/// A committed artboard name: ((document uid, reverts), artboard id, name), for the pump to run.
rename: Option<((u64, u64), u32, String)>,
held: HeldAnswer<Map<String, Value>>,
}
@@ -620,13 +622,13 @@ impl ExportForScreensDialog {
}
}
if picks.rename_began {
self.renaming_in = Some(shown.key.0);
self.renaming_in = Some((shown.key.0, shown.reverts));
}
// The name goes to the document the rename began in.
if let Some((key, name)) = picks.renamed
&& let Ok(board) = u32::try_from(key)
{
self.rename = Some((self.renaming_in.take().unwrap_or(shown.key.0), board, name));
self.rename = Some((self.renaming_in.take().unwrap_or((shown.key.0, shown.reverts)), board, name));
}
if on != boards(doc.artboards.len(), fields) {
set_select(fields, if on.iter().all(|b| *b) { "all" } else { "range" });
@@ -994,15 +996,16 @@ pub(crate) fn pump(app: &mut VectorcraftApp, ctx: &Context) {
// The export ran when OK was filed: the closed dialog's answer is not read.
let _ = dialogs.with(|host| host.take_by_id::<ExportForScreensDialog>(id));
let key = app.session.active().map(|st| (st.uid, st.revision));
let contents = app.session.active().map(|st| (st.uid, st.reverts));
let pdf_presets = pdf::presets(&app.session);
let saved = &app.session.prefs.screen_export_presets;
let Some((shown, pending, rename, filed)) = dialogs.with(|host| {
let Some((shown, shown_contents, pending, rename, filed)) = dialogs.with(|host| {
let d = host.get_mut_by_id::<ExportForScreensDialog>(id)?;
screen_formats::preset_list(&mut d.presets, saved);
if d.pdf_presets != pdf_presets {
d.pdf_presets = pdf_presets;
}
Some((d.doc.as_ref().map(|s| s.key), d.pending.take(), d.rename.take(), d.held.take()))
Some((d.doc.as_ref().map(|s| s.key), d.doc.as_ref().map(|s| (s.key.0, s.reverts)), d.pending.take(), d.rename.take(), d.held.take()))
}) else {
return;
};
@@ -1024,15 +1027,15 @@ pub(crate) fn pump(app: &mut VectorcraftApp, ctx: &Context) {
}
});
}
// A name typed in another document than the active one is dropped.
if let Some((uid, board, name)) = rename
&& key.is_some_and(|(active, _)| active == uid)
// A name typed in another drawing or in content discarded by File Revert is dropped.
if let Some((origin, board, name)) = rename
&& contents == Some(origin)
{
rename_artboard(app, board, &name);
}
if let Some(fields) = filed {
// OK validated its selection against the document the dialog showed before refreshing.
let answer = if shown.map(|(uid, _)| uid) == app.session.active().map(|st| st.uid) {
// OK validated its selection against the loaded contents shown before refreshing.
let answer = if shown_contents == contents {
params(app, &fields).and_then(|p| io::export_for_screens(app, p)).map(drop).map_err(Label::from)
} else {
Err(Label::from(tl!("The active document changed. Review the export selection and try again.")))
@@ -67,6 +67,62 @@ fn stays_open(app: &mut VectorcraftApp) {
assert_eq!(kind(app).as_deref(), Some(export_for_screens::KIND));
}
#[test]
fn a_queued_download_requires_fresh_confirmation_after_file_revert() {
use craft::ui::dialog::{HeldOk, dialog_id};
for artboards in [1, 2] {
let dir = vectorcraft_testkit::TempDir::new("screens-held-revert");
let path = dir.join("saved.vectorcraft").to_string_lossy().into_owned();
let (mut app, log) = app(artboards, true);
app.run("artboard.rename", json!({"indices": [0], "name": "Saved"})).unwrap();
app.session.execute("document.save", &json!({"path": path})).unwrap();
app.run("artboard.rename", json!({"indices": [0], "name": "Edited"})).unwrap();
let uid = app.session.active().unwrap().uid;
let reverts = app.session.active().unwrap().reverts;
open(&mut app);
let ctx = app.ui_ctx.clone().unwrap();
let dialogs = app.dialogs().unwrap();
let id = dialog_id(export_for_screens::KIND);
assert!(!dialogs.with(|host| host.confirm_by_id(&ctx, id)));
assert_eq!(dialogs.with(|host| host.held_state(id)), Some(HeldOk::Waiting));
app.run("file.revert", json!({"confirmed": true})).unwrap();
assert_eq!(app.session.active().unwrap().uid, uid);
assert!(app.session.active().unwrap().reverts > reverts, "the actual file was loaded back into its tab");
let settings = app.session.active().unwrap().doc.export_settings.clone();
export_for_screens::pump(&mut app, &ctx);
assert!(log.borrow().is_empty(), "the retired drawing's approval exports no restored content");
assert_eq!(app.session.active().unwrap().doc.export_settings, settings);
assert!(matches!(dialogs.with(|host| host.held_state(id)), Some(HeldOk::Refused(_))));
try_confirm(&mut app).unwrap();
let log = log.borrow();
let [(name, bytes)] = log.as_slice() else { panic!("one download") };
if artboards == 1 {
assert_eq!(name, "Saved.png");
} else {
let names = zip_names(bytes);
assert!(names.iter().any(|name| name.ends_with("Saved.png")));
assert!(!names.iter().any(|name| name.contains("Edited")));
}
}
}
#[test]
fn a_queued_download_still_uses_ordinary_edits_in_the_same_loaded_drawing() {
use craft::ui::dialog::dialog_id;
let (mut app, log) = app(1, true);
open(&mut app);
let ctx = app.ui_ctx.clone().unwrap();
let dialogs = app.dialogs().unwrap();
let id = dialog_id(export_for_screens::KIND);
assert!(!dialogs.with(|host| host.confirm_by_id(&ctx, id)));
app.run("artboard.rename", json!({"indices": [0], "name": "Current"})).unwrap();
export_for_screens::pump(&mut app, &ctx);
assert_eq!(log.borrow().iter().map(|(name, _)| name.as_str()).collect::<Vec<_>>(), ["Current.png"]);
}
#[test]
fn a_queued_export_requires_fresh_confirmation_after_switching_documents() {
use craft::ui::dialog::{HeldOk, dialog_id};
@@ -1448,6 +1504,30 @@ fn renaming_an_artboard_in_export_for_screens_renames_it() {
}
}
/// A rename begun before File Revert cannot rename an artboard restored from the saved file.
#[test]
fn an_artboard_name_cannot_reach_the_contents_loaded_by_file_revert() {
for view in ["grid", "list"] {
let dir = vectorcraft_testkit::TempDir::new("screens-rename-revert");
let path = dir.join("saved.vectorcraft").to_string_lossy().into_owned();
let (mut app, log) = app(2, true);
app.session.execute("document.save", &json!({"path": path})).unwrap();
app.run("shape.rectangle", json!({"x": 1, "y": 1, "width": 5, "height": 5})).unwrap();
let reverts = app.session.active().unwrap().reverts;
let mut w = Window::default();
w.names(&mut app);
open(&mut app);
set(&mut app, "view", json!(view));
type_artboard_name(&mut w, &mut app, "2 Artboard 2", "Retired Name");
app.run("file.revert", json!({"confirmed": true})).unwrap();
assert!(app.session.active().unwrap().reverts > reverts);
w.key(&mut app, egui::Key::Enter);
assert_eq!(app.session.active().unwrap().doc.artboards[1].name, "Artboard 2");
assert!(app.session.active().unwrap().history.undo.is_empty());
assert!(log.borrow().is_empty(), "the stale name does not export either");
}
}
/// A name typed while another document becomes active (a command from the control channel or MCP)
/// renames no artboard of the active document.
#[test]