Save and Export: the status bar's hover lists every note

A save or an export with several notes named only the first of them in
the status bar, with the count, and the others could not be seen. The
status bar now keeps every note of a save or an export for the status
message's hover, as it does for an open's notes since #6752: resting
the pointer on the message lists them in the order the reply gives them
(a save's notes start with what the format loses), and screen readers
receive the list after the message. The status text is unchanged.

This covers Save, Save As, Save a Copy, Save as Template, Save a
Timestamped Copy, Save as PDF, Export As, Export Selection, Export for
Screens, Asset Export, Save for Web, Preview in Browser, Save for Office
Documents, Text Export Options, a print to a file and the CSS Properties
panel's export. The open, the saves and the exports read a reply's notes
through one helper.

Docs: docs/mcp.md and the css.exportFile params text,
docs/control-protocol.md, docs/target-app-parity.md.
This commit is contained in:
dotCooCoo
2026-11-11 20:44:53 -08:00
parent fd6b8f6c97
commit 35be7952c8
14 changed files with 139 additions and 39 deletions
+3 -2
View File
@@ -248,8 +248,9 @@ pub(super) fn status_readouts(app: &VectorcraftApp, ui: &mut Ui, t: &Tokens) {
/// Most notes the status message's hover and access information list.
const MAX_LISTED_NOTES: usize = 30;
/// The notes behind the status message (the open's, [`crate::state::UiState::status_notes`]) when
/// there are several and the status bar still shows the message they came with, else none.
/// The notes behind the status message (an open's, a save's or an export's,
/// [`crate::state::UiState::status_notes`]) when there are several and the status bar still shows
/// the message they came with, else none.
fn status_notes(ui: &crate::state::UiState) -> &[String] {
let notes = ui.status_notes.as_ref().filter(|(status, notes)| *status == ui.status && notes.len() > 1);
notes.map(|(_, notes)| notes.as_slice()).unwrap_or_default()
+5 -5
View File
@@ -133,8 +133,8 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String> {
}
/// `file.saveForWeb` with settings: write the files (`path`, else a picked file: the page with HTML
/// output, else the image); the web downloads them. The status bar shows the export's first
/// warning.
/// output, else the image); the web downloads them. The status bar shows the export's warnings as
/// [`io::report_saved`] shows a save's notes.
pub(crate) fn save(app: &mut VectorcraftApp, mut p: Value) -> Result<Value, String> {
// Bad settings never open a save panel.
let s = app.session.web_settings(&p)?;
@@ -170,7 +170,7 @@ pub(crate) fn save(app: &mut VectorcraftApp, mut p: Value) -> Result<Value, Stri
}
/// Whether an export's reply `r` has warnings (an image that couldn't be decoded):
/// [`io::report_saved`] puts the first in the status bar as a save's note.
/// [`io::report_saved`] shows them in the status bar as a save's notes.
fn has_warnings(r: &Value) -> bool {
r["warnings"].as_array().is_some_and(|w| !w.is_empty())
}
@@ -183,8 +183,8 @@ pub(super) fn preview_name(stem: &str) -> &str {
}
/// `file.saveForWeb.browser`: the HTML page and its images in a new temporary folder, opened in the
/// default browser (desktop). When the export has warnings, the status bar shows the first in
/// place of "Opened …".
/// default browser (desktop). When the export has warnings, the status bar shows them as
/// [`io::report_saved`] shows a save's notes.
pub(crate) fn browser_preview(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
if io::is_web(app) {
return Err("Preview in Browser needs the desktop app (the web downloads files instead)".into());
@@ -508,6 +508,35 @@ fn the_status_bar_says_when_an_image_could_not_be_decoded() {
let _ = std::fs::remove_dir_all(dir);
}
/// An export into a folder with several notes, from Export for Screens and from the Asset Export
/// panel: the status bar names the first, counts them, and keeps every one of them for its hover.
#[test]
fn an_export_into_a_folder_keeps_every_note_for_the_hover() {
let mut png = Vec::new();
image::RgbaImage::from_pixel(64, 32, image::Rgba([200, 30, 30, 255]))
.write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png)
.unwrap();
let dir = temp_folder("notes");
let folder = dir.to_string_lossy().replace('\\', "/");
let rows = json!([{"format": "png", "scale": "1x", "suffix": ""}]);
let (mut app, _) = app(1, false);
vectorcraft_testkit::fixtures::place_cut_png(&mut app.session, &png, json!({"at": [10, 10]}));
app.run("text.create", json!({"x": 5, "y": 20, "text": "Ab", "font": "Nonexistent Sans Probe"})).unwrap();
let r = app.run("file.exportForScreens", json!({"folder": folder, "formats": rows})).unwrap();
let notes = crate::io::notes_of(&r);
assert_eq!(notes.len(), 2, "{r}");
assert!(app.ui.status.starts_with(&format!("Saved {folder} with 2 notes: {}", notes[0])), "{}", app.ui.status);
assert_eq!(app.ui.status_notes, Some((app.ui.status.clone(), notes)));
app.ui.status_notes = None;
app.run("select.all", json!({})).unwrap();
app.run("assets.add", json!({"multiple": false})).unwrap();
let r = crate::io::export_files(&mut app, "assets.export", json!({"folder": folder, "formats": rows})).unwrap();
let notes = crate::io::notes_of(&r);
assert_eq!(notes.len(), 2, "{r}");
assert_eq!(app.ui.status_notes, Some((app.ui.status.clone(), notes)), "assets.export");
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn a_preset_export_reopens_on_its_rows() {
let (mut app, _) = app(1, true);
+32 -2
View File
@@ -30,7 +30,7 @@ pub use open::{
#[cfg(test)]
pub(crate) use open::{open_file, opened_with_notes};
pub use save::{ask_format_options, ask_pdf_options, remember_active_artboard, remember_view, save, save_pdf};
pub(crate) use save::{export_path, is_web, report_saved, target_path, write_named, write_reporting, write_to};
pub(crate) use save::{export_path, is_web, notes_of, report_saved, show_with_notes, target_path, write_named, write_reporting, write_to};
#[cfg(test)]
pub(crate) use save::{report_write_error, saved_status};
@@ -90,7 +90,7 @@ mod tests {
use vectorcraft_testkit::ai;
let (mut app, _) = app();
let damaged = b"%AI12_CompressedData not zlib";
let notes = |r: &Value| -> Vec<String> { r["warnings"].as_array().unwrap().iter().filter_map(Value::as_str).map(str::to_string).collect() };
let notes = notes_of;
let pdf = ai::pdf(damaged, "0 g 150 20 100 60 re f");
let r = open_bytes(&mut app, "damaged.pdf", &pdf, None).unwrap();
let [page, layers] = &notes(&r)[..] else { panic!("two notes: {r}") };
@@ -125,6 +125,36 @@ mod tests {
assert_eq!((app.ui.status.clone(), app.ui.status_notes.clone()), shown);
}
/// A save and an export with several notes: the status bar names the first, counts them, and
/// keeps every one of them, in the reply's order, for its hover. A save without notes keeps
/// none.
#[test]
fn a_save_and_an_export_keep_every_note_for_the_hover() {
let (mut app, _) = app();
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
let r = app.run("file.save", json!({"path": "/out/a.svg", "compress": true})).unwrap();
let notes = notes_of(&r);
assert_eq!(notes.len(), 2, "{r}");
assert!(notes[0].starts_with("SVG keeps the artwork but not everything"), "{r}");
assert_eq!(app.ui.status, saved_status("/out/a.svg", &r));
assert!(app.ui.status.contains("with 2 notes"), "{}", app.ui.status);
assert_eq!(app.ui.status_notes, Some((app.ui.status.clone(), notes)));
app.run("file.save", json!({"path": "/out/b.vectorcraft"})).unwrap();
assert_eq!((app.ui.status.as_str(), &app.ui.status_notes), ("Saved /out/b.vectorcraft", &None));
// A PDF export of a knockout group and of type in a font that isn't installed.
app.run("text.create", json!({"x": 5, "y": 20, "text": "Ab", "font": "Nonexistent Sans Probe"})).unwrap();
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 20})).unwrap();
app.run("object.group", json!({})).unwrap();
app.run("transparency.set", json!({"knockout": "on"})).unwrap();
let r = export(&mut app, Some("pdf"), Some("/out/c.pdf".into()), &json!({})).unwrap();
let notes = notes_of(&r);
assert_eq!(notes.len(), 2, "{r}");
assert_eq!(app.ui.status, exported_with_notes("/out/c.pdf", notes.len(), &notes[0]));
assert_eq!(app.ui.status_notes, Some((app.ui.status.clone(), notes)));
}
/// #1685: a save or an export that can't write its file says so in a dialog that names the
/// file and the reason and stays until it is closed; the document stays modified and keeps
/// the file it had. An agent's request only gets the error, and a message that arrives while
+11 -9
View File
@@ -1,6 +1,6 @@
use super::save::{
ask_before_losing, export_path, is_web, remember_active_artboard, report_saved, report_write_error, saved_status, target_path,
target_path_keeping, view_file, write_encoded, write_named, write_reporting,
ask_before_losing, export_path, is_web, notes_of, remember_active_artboard, report_saved, report_write_error, saved_status, show_with_notes,
target_path, target_path_keeping, view_file, write_encoded, write_named, write_reporting,
};
use super::{EngineError, Progress, Value, VectorcraftApp, Writer, background, cancel, fileio, json, progress};
@@ -94,11 +94,12 @@ pub fn export(app: &mut VectorcraftApp, format: Option<&str>, path: Option<Strin
Some(files) => format!("{} files", files.len()),
None => r["path"].as_str().unwrap_or_default().to_string(),
};
let warnings: Vec<&str> = r["warnings"].as_array().map(|w| w.iter().filter_map(Value::as_str).collect()).unwrap_or_default();
app.status(match warnings.first() {
let warnings = notes_of(&r);
let status = match warnings.first() {
Some(first) => exported_with_notes(&what, warnings.len(), first),
None => format!("Exported {what}"),
});
};
show_with_notes(app, status, warnings);
Ok(r)
})?;
if r.get("path").is_none() {
@@ -115,7 +116,7 @@ pub(crate) fn exported_with_notes(what: &str, n: usize, first: &str) -> String {
/// Run an engine command that returns `{dataBase64}` and write the bytes to a picked path
/// (Export Selection, Save for Office Documents, Text Export Options and the presets dialogs'
/// Export…), reported with the first of the command's warnings ([`report_saved`]).
/// Export…), reported with the command's warnings ([`report_saved`]).
pub fn save_command_output(app: &mut VectorcraftApp, id: &str, ext: &str, params: Value) -> Result<String, String> {
let (path, v) = run_to_file(app, id, ext, params)?;
report_saved(app, &path, &v);
@@ -241,8 +242,9 @@ pub(crate) fn open_original(app: &mut VectorcraftApp, path: &str) -> Result<(),
/// File → Export for Screens with `document.exportForScreens` params: the files go into `folder`;
/// without one the web downloads them (the ZIP, or each file) and the other frontends get them
/// back as base64. With `openLocation`, the file manager shows the first file written. When an
/// export into a folder or a download has warnings, the status bar shows the first as
/// [`report_saved`] shows a save's notes: "Saved <folder, ZIP or first download> with n notes: …".
/// export into a folder or a download has warnings, the status bar shows them as [`report_saved`]
/// shows a save's notes: "Saved <folder, ZIP or first download> with n notes: …", and hovering the
/// message lists them all.
pub fn export_for_screens(app: &mut VectorcraftApp, params: Value) -> Result<Value, String> {
export_files(app, "document.exportForScreens", params)
}
@@ -312,7 +314,7 @@ fn report_exported(app: &mut VectorcraftApp, r: Value, folder: &str, open_locati
{
status = format!("{status} ({e})");
}
app.status(status);
show_with_notes(app, status, notes_of(&r));
} else if let Some(download) = app.services.download.as_mut() {
// A browser download has no folders: a file from a sub-folder (`2x/Logo@2x.png`) is named alone.
let returned: Vec<(&str, &str)> = returned.iter().map(|(name, data)| (name.rsplit('/').next().unwrap_or(name), *data)).collect();
+4 -4
View File
@@ -1,7 +1,7 @@
use vectorcraft_engine::cmd::plugin::InstallApproval;
use vectorcraft_plugins::permissions;
use super::save::suggested;
use super::save::{notes_of, show_with_notes, suggested};
use super::{Dialog, FilePick, Format, Value, VectorcraftApp, dialogs, fileio, json};
/// Template extensions New from Template's open dialog lists first.
@@ -144,8 +144,8 @@ pub(crate) fn opened(app: &mut VectorcraftApp, r: &Value) {
app.sync_views();
let notes = open_notes(app, r);
if let Some(first) = notes.first() {
app.status(opened_with_notes(notes.len(), first));
app.ui.status_notes = Some((app.ui.status.clone(), notes));
let status = opened_with_notes(notes.len(), first);
show_with_notes(app, status, notes);
}
crate::dialogs::missing_links::after_open(app, r);
}
@@ -153,7 +153,7 @@ pub(crate) fn opened(app: &mut VectorcraftApp, r: &Value) {
/// The notes of the open `r`, those of what reading the file left out (its document's
/// `import_losses`) first, each group in the order the import gave them.
fn open_notes(app: &VectorcraftApp, r: &Value) -> Vec<String> {
let notes: Vec<String> = r["warnings"].as_array().into_iter().flatten().filter_map(Value::as_str).map(str::to_string).collect();
let notes = notes_of(r);
let index = r["index"].as_u64().and_then(|i| usize::try_from(i).ok());
let losses = index.and_then(|i| app.session.documents().get(i)).map(|st| st.import_losses.as_slice()).unwrap_or_default();
let (mut first, rest): (Vec<String>, Vec<String>) = notes.into_iter().partition(|n| losses.contains(n));
+18 -4
View File
@@ -394,20 +394,34 @@ pub(super) fn view_file(app: &mut VectorcraftApp, path: &str) {
}
}
/// "Saved <path>", with the first of the result's warnings.
/// "Saved <path>", with the first of the result's warnings and how many there are; hovering the
/// message lists them all ([`show_with_notes`]).
pub(crate) fn report_saved(app: &mut VectorcraftApp, path: &str, r: &Value) {
app.status(saved_status(path, r));
show_with_notes(app, saved_status(path, r), notes_of(r));
}
/// The warnings of a reply `r`, in the reply's order (a save's notes start with what the format
/// loses).
pub(crate) fn notes_of(r: &Value) -> Vec<String> {
r["warnings"].as_array().into_iter().flatten().filter_map(Value::as_str).map(str::to_string).collect()
}
/// Show `status`, which names the first of `notes`, in the status bar and keep `notes` for its
/// hover ([`crate::state::UiState::status_notes`]). Without notes nothing is kept.
pub(crate) fn show_with_notes(app: &mut VectorcraftApp, status: String, notes: Vec<String>) {
app.status(status);
app.ui.status_notes = (!notes.is_empty()).then(|| (app.ui.status.clone(), notes));
}
/// [`report_saved`]'s message.
pub(crate) fn saved_status(path: &str, r: &Value) -> String {
let warnings: Vec<&str> = r["warnings"].as_array().map(|w| w.iter().filter_map(Value::as_str).collect()).unwrap_or_default();
let warnings = notes_of(r);
match warnings.first() {
Some(first) => crate::i18n::msg_n(
warnings.len() as u64,
"Saved {path} with {n} note: {first}",
"Saved {path} with {n} notes: {first}",
&[("path", path), ("first", first)],
&[("path", path), ("first", first.as_str())],
),
None => format!("Saved {path}"),
}
+1 -1
View File
@@ -1487,7 +1487,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"css.exportFile",
"Export CSS…",
"",
"{path?, scope?: selection|all (default selection), …css.selection options} css.export written to path, else a picked file (the web downloads it), with the pictures of rasterized art next to it (CSS Properties panel: Export Selected CSS…, Export All…) → {path, rules, images: [path…], warnings (css.export's; the status bar shows the first)}",
"{path?, scope?: selection|all (default selection), …css.selection options} css.export written to path, else a picked file (the web downloads it), with the pictures of rasterized art next to it (CSS Properties panel: Export Selected CSS…, Export All…) → {path, rules, images: [path…], warnings (css.export's; the status bar shows the first and how many there are, and hovering the message lists them all)}",
),
(
"file.print",
+6 -5
View File
@@ -86,7 +86,7 @@ fn shown(app: &mut VectorcraftApp, ui: &Ui, opts: &CssOptions, all: bool) -> Opt
let (id, scope) = if all { ("css.generate", "all") } else { ("css.selection", "selection") };
let out = app.session.execute(id, &params(opts, scope)).unwrap_or_default();
let rules: Vec<&str> = out["rules"].as_array().into_iter().flatten().filter_map(|r| r["css"].as_str()).collect();
let warnings = out["warnings"].as_array().into_iter().flatten().filter_map(Value::as_str).map(str::to_string).collect();
let warnings = io::notes_of(&out);
let job = (!rules.is_empty())
.then(|| Arc::new(highlight(rules.get(..MAX_SHOWN).unwrap_or(&rules), &t, egui::TextStyle::Monospace.resolve(ui.style()))));
let skipped = out["skipped"].as_u64().unwrap_or(0);
@@ -204,13 +204,14 @@ pub(crate) fn export_file(app: &mut VectorcraftApp, p: &Value) -> Result<Value,
io::write_to(&mut app.services, &at, &bytes)?;
images.push(at);
}
// The status bar shows the first warning in Export As's message.
let warnings: Vec<&str> = r["warnings"].as_array().map(|w| w.iter().filter_map(Value::as_str).collect()).unwrap_or_default();
// The status bar shows the warnings as Export As shows them.
let warnings = io::notes_of(&r);
let what = &path;
app.status(match warnings.first() {
let status = match warnings.first() {
Some(first) => io::exported_with_notes(what, warnings.len(), first),
None => format!("Exported {path}"),
});
};
io::show_with_notes(app, status, warnings);
Ok(json!({ "path": path, "rules": r["rules"], "images": images, "warnings": r["warnings"] }))
}
@@ -146,3 +146,23 @@ fn export_says_in_the_status_bar_when_an_image_could_not_be_decoded() {
assert_eq!(app.ui.status, format!("Exported /tmp/site/site.css with 1 note: {WARNING}"));
assert_eq!(log.borrow().len(), 3, "the sheet and the image's picture are still written");
}
/// A CSS export with several notes: the status bar names the first, counts them, and keeps every
/// one of them for its hover.
#[test]
fn export_keeps_every_note_for_the_hover() {
let (mut app, _) = app();
let mut png = Vec::new();
image::RgbaImage::from_pixel(64, 32, image::Rgba([200, 30, 30, 255]))
.write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png)
.unwrap();
vectorcraft_testkit::fixtures::place_cut_png(&mut app.session, &png, json!({}));
// Type painted with a gradient is rasterized, and its picture is drawn in the fallback font.
app.run("text.create", json!({"x": 5, "y": 20, "text": "Ab", "font": "Nonexistent Sans Probe"})).unwrap();
app.run("paint.setFill", json!({"gradient": {"stops": [{"offset": 0, "color": "#ff0000"}, {"offset": 1, "color": "#0000ff"}]}})).unwrap();
let r = app.run("css.exportFile", json!({"path": "/tmp/site/site.css", "scope": "all", "rasterize": true})).unwrap();
let notes = crate::io::notes_of(&r);
assert_eq!(notes.len(), 2, "{r}");
assert_eq!(app.ui.status, format!("Exported /tmp/site/site.css with 2 notes: {}", notes[0]));
assert_eq!(app.ui.status_notes, Some((app.ui.status.clone(), notes)));
}
+3 -2
View File
@@ -537,8 +537,9 @@ pub struct UiState {
/// The Replace Font request behind the status bar's warning ([`ReplaceFontWarning`]). Not saved.
#[serde(skip)]
pub replace_font_warning: Option<ReplaceFontWarning>,
/// The notes of the last open that gave any, with the status text that names the first of
/// them: hovering that text lists them when there are several. Not saved.
/// The notes of the last open that gave any, or of the last save or export, with the status
/// text that names the first of them: hovering that text lists them when there are several.
/// Not saved.
#[serde(skip)]
pub status_notes: Option<(String, Vec<String>)>,
pub palette_open: bool,