From 6c314c4cd68ee5208689f2d4ef443612f5f3b16a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 12:57:51 -0800 Subject: [PATCH] Docs: the control protocol gives Don't Save in one ui.dialog.set request ui.dialog.set with fields and action "confirm" sets choice (and applyToAll) and confirms the same Save Changes question in one request, so no other dialog is answered between the two. The control-protocol row now gives that form beside the two-request one, and the Save Changes test checks the line and sends both one-request forms through the control handler. --- crates/ui-egui/src/unsaved.rs | 22 ++++++++++++++++++++-- docs/control-protocol.md | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/unsaved.rs b/crates/ui-egui/src/unsaved.rs index 252f3cc8a5..5259c30efb 100644 --- a/crates/ui-egui/src/unsaved.rs +++ b/crates/ui-egui/src/unsaved.rs @@ -401,6 +401,7 @@ mod tests { const CONTROL_DONT_SAVE: &str = r#"`ui.dialog.set {field: "choice", value: "dontSave"}` then confirm"#; const CONTROL_APPLY_TO_ALL: &str = r#"`ui.dialog.set {field: "applyToAll", value: true}` before confirm"#; + const CONTROL_ONE_REQUEST: &str = r#"`ui.dialog.set {fields: [{field: "choice", value: "dontSave"}], action: "confirm"}`"#; const MCP_DONT_SAVE: &str = r#"`{set: [{field: "choice", value: "dontSave"}]}` followed by a second call with `{action: "confirm"}`"#; const MCP_APPLY_TO_ALL: &str = r#"adding `{field: "applyToAll", value: true}` to `set`"#; @@ -410,8 +411,12 @@ mod tests { #[test] fn the_documented_dont_save_answer_closes_without_saving() { for (name, text, snippets) in [ - ("docs/control-protocol.md", include_str!("../../../docs/control-protocol.md"), [CONTROL_DONT_SAVE, CONTROL_APPLY_TO_ALL]), - ("docs/mcp.md", include_str!("../../../docs/mcp.md"), [MCP_DONT_SAVE, MCP_APPLY_TO_ALL]), + ( + "docs/control-protocol.md", + include_str!("../../../docs/control-protocol.md"), + &[CONTROL_DONT_SAVE, CONTROL_APPLY_TO_ALL, CONTROL_ONE_REQUEST][..], + ), + ("docs/mcp.md", include_str!("../../../docs/mcp.md"), &[MCP_DONT_SAVE, MCP_APPLY_TO_ALL][..]), ] { // Check the requests on every line describing the pending Save Changes reply. let lines: Vec<_> = text.lines().filter(|line| line.contains(r#"{"pending": "saveChanges"}"#)).collect(); @@ -444,6 +449,19 @@ mod tests { ("ui.dialog.confirm", json!({})), ], ), + ( + "control protocol one request", + false, + vec![("ui.dialog.set", json!({ "fields": [{ "field": "choice", "value": "dontSave" }], "action": "confirm" }))], + ), + ( + "control protocol one request applyToAll", + true, + vec![( + "ui.dialog.set", + json!({ "fields": [{ "field": "choice", "value": "dontSave" }, { "field": "applyToAll", "value": true }], "action": "confirm" }), + )], + ), ( "MCP Don't Save", false, diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 783c686f45..5b280ec8f8 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -107,7 +107,7 @@ the two can still win that race. | `ui.render` | `{path?, scale?, artboard?, data?, traceViews?}` | render an artboard headlessly (PNG with the pixels of `app.export {format: "png", background: "white"}` at the same scale; `artboard`: its 0-based index, default the first; `traceViews: true`: Image Trace objects draw in their View, as on the canvas, instead of their tracing result): written to `path`, else (or with `data: true` as well) sent back as `pngBase64` | | `ui.resize` | `{width?, height?}` | request the window's inner size; omitted or null `width` and `height` default to 1440 and 900. Returns `null` | | `ui.focus` | `{}` | request keyboard focus for the window. Returns `null` | -| `app.open` / `app.save` / `app.export` / `app.quit` | `{path, importer?, params?}` / `{path?}` / `{path?, format?, artboard?, range?, scale?, …}` | `app.open` reads every format `document.open` reads (see `document.formats`) and returns its result (`{index, title, format, warnings, …}`; `warnings` say what didn't come in as it was, such as an EPS shown as its preview image and why its PostScript couldn't be read), or null when a dialog asks first or a library loads. The status bar (`ui.inspect` → `ui.status`), after a line about the document's linked files when there is one (Missing linked files below), counts the `warnings` and names the first that says reading the file left something out (the notes that make Save ask before writing over it), else the first; with several, hovering it lists them in that order, as many as fit in the window (at most 30), then how many more. After `app.save`, and `app.export` with a `path`, the status bar counts the reply's `warnings` and names the first, and with several, hovering it lists them in the reply's order (a save's notes start with what the format loses). With `importer` (an importer plug-in's format id, `plugin.`) it runs `file.openWith`: the file opens with that importer, also when a built-in format reads its extension, with the importer's parameters `params` (their defaults when omitted; no dialog asks for them). Without `importer`, `params` go to the importer that opens the file, and a built-in format does not read them. `app.export` encodes through the engine's `document.export` (same options; the document keeps its path) and writes `path` through the host; without `path` it returns `{dataBase64, format, bytes}`, as headless mode does. It refuses a key that no format takes, and an unknown key inside a PDF or EPS option object, before it writes anything (`docs/mcp.md`, Parameter keys). It accepts a key that only another format takes and does not use it: the reply's `warnings` and the status bar name the key ("`quality` was not used: PDF files don't read it"). `app.save` refuses a key that no save format takes, beside the path or in `options`, the same way. `app.quit`, `file.close` and `file.closeAll` first open a `saveChanges` dialog for each modified document (they return `{"pending": "saveChanges"}`): `ui.dialog.confirm` saves, `ui.dialog.set {field: "choice", value: "dontSave"}` then confirm closes the document without saving, `ui.dialog.cancel` cancels the whole close or quit. `choice` takes `save`, `dontSave` or `cancel`, and any other field or value is an error. While more modified documents wait to be asked about, the dialog also has `applyToAll`: `ui.dialog.set {field: "applyToAll", value: true}` before confirm gives the same answer for each of them | +| `app.open` / `app.save` / `app.export` / `app.quit` | `{path, importer?, params?}` / `{path?}` / `{path?, format?, artboard?, range?, scale?, …}` | `app.open` reads every format `document.open` reads (see `document.formats`) and returns its result (`{index, title, format, warnings, …}`; `warnings` say what didn't come in as it was, such as an EPS shown as its preview image and why its PostScript couldn't be read), or null when a dialog asks first or a library loads. The status bar (`ui.inspect` → `ui.status`), after a line about the document's linked files when there is one (Missing linked files below), counts the `warnings` and names the first that says reading the file left something out (the notes that make Save ask before writing over it), else the first; with several, hovering it lists them in that order, as many as fit in the window (at most 30), then how many more. After `app.save`, and `app.export` with a `path`, the status bar counts the reply's `warnings` and names the first, and with several, hovering it lists them in the reply's order (a save's notes start with what the format loses). With `importer` (an importer plug-in's format id, `plugin.`) it runs `file.openWith`: the file opens with that importer, also when a built-in format reads its extension, with the importer's parameters `params` (their defaults when omitted; no dialog asks for them). Without `importer`, `params` go to the importer that opens the file, and a built-in format does not read them. `app.export` encodes through the engine's `document.export` (same options; the document keeps its path) and writes `path` through the host; without `path` it returns `{dataBase64, format, bytes}`, as headless mode does. It refuses a key that no format takes, and an unknown key inside a PDF or EPS option object, before it writes anything (`docs/mcp.md`, Parameter keys). It accepts a key that only another format takes and does not use it: the reply's `warnings` and the status bar name the key ("`quality` was not used: PDF files don't read it"). `app.save` refuses a key that no save format takes, beside the path or in `options`, the same way. `app.quit`, `file.close` and `file.closeAll` first open a `saveChanges` dialog for each modified document (they return `{"pending": "saveChanges"}`): `ui.dialog.confirm` saves, `ui.dialog.set {field: "choice", value: "dontSave"}` then confirm closes the document without saving, `ui.dialog.cancel` cancels the whole close or quit. `choice` takes `save`, `dontSave` or `cancel`, and any other field or value is an error. While more modified documents wait to be asked about, the dialog also has `applyToAll`: `ui.dialog.set {field: "applyToAll", value: true}` before confirm gives the same answer for each of them. `ui.dialog.set {fields: [{field: "choice", value: "dontSave"}], action: "confirm"}` answers the same question in one request, so no other dialog can be answered between the set and the confirm, and `{field: "applyToAll", value: true}` can go in the same `fields` | | `app.export` with `useArtboards` | `{path, useArtboards: true, range? \| artboards?, …}` | Export As: PNG, JPEG and WebP write one file per chosen artboard (default all; SVG does so for a `range`), `-.`, and return `{path, files: [path…]}`; a PDF keeps them as pages of `path`. `useArtboards: false` covers the bounds of the visible art. The menu's Export As… is `file.exportAs`: the `exportAs` dialog (`format`, `useArtboards`, `all`, `range`), then a save dialog and the format's options: `pngOptions` / `jpgOptions` / `webpOptions`, `svgOptions`, or `savePdf` for a PDF | | `ui.dialog.*` on `gradientStop` | `{field: "color" \| "opacity" \| "location", value}` | double-clicking a stop on the Gradient tool's annotator opens its popover (fields `index`, `x`, `y`, `tab`); set `color` (hex), `opacity` or `location` (percentages) and `ui.dialog.confirm` to apply them to the selected stop. `gradient.selectStop {index}` picks the stop the annotator, the panels and Delete/←/→ (`ui.key`) act on | | `engine.execute` `ui.savePdfDialog` | `{path?, preset?, range?, …document.exportPdf options}` | opens the Save PDF dialog (`file.export.pdf` with no params opens it too). Its fields are the `document.exportPdf` options: set `compatibility` with `ui.dialog.set {field: "compatibility", value: "1.5"}`, a section with `{field: "compression", value: {…}}` (the options it leaves out keep the dialog's values, in Save PDF and in the preset editor, and in an object inside a section such as `compression.color`; a value that isn't an object, null included, is an error), the artboards with `__allArtboards: false` and `range`, the visible section with `__section` (General, Compression, Marks and Bleeds, Output, Advanced, Security, Summary), and the bleed link with `__bleedLinked` (true gives every side the top value; any value other than true or false is an error; setting `bleed` turns the link on when its four sides are equal and off when they differ). In Advanced, Custom… beside Flattener preset (enabled when the file is flattened: PDF 1.3, PDF/X-1a, PDF/X-3) opens the `pdfFlattenerOptions` dialog over Save PDF on the flattener options the save would use; its fields are those options, with `clipComplexRegions`, `preserveAlpha` and `preserveOverprints` set by the writer and Overprint. Its `ui.dialog.confirm` sets `flattener` (the preset then shows [Custom]; options equal to the preset's leave it unset) and goes back to Save PDF, and `ui.dialog.cancel` goes back unchanged. Setting `flattenerPreset` drops `flattener`. `useArtboards: false` opens it for one page of the visible art's bounds, as Export As with Use Artboards off does: the dialog has no Artboards section and its `__artBounds` field is true. `ui.dialog.confirm` writes `path` (else asks for one), returns `{path, bytes, warnings}` and opens the file when `viewAfterSaving` is set. With `useArtboards: false` it writes the page as `app.export` does and returns `{path, warnings}`, or `{background: true, status}` while Background Export writes it |