diff --git a/crates/ui-egui/src/app/files.rs b/crates/ui-egui/src/app/files.rs index 962bbe61da..4df6296f96 100644 --- a/crates/ui-egui/src/app/files.rs +++ b/crates/ui-egui/src/app/files.rs @@ -633,7 +633,7 @@ impl WordApp { for item in intake.take() { match item { Intake::Dropped { files, target } => self.open_dropped(&files, target), - Intake::Open(paths) => { + Intake::Open(paths) | Intake::OpenFor { paths, .. } => { for p in paths { // A path that is not Unicode cannot be passed on as text: skipped. if let Some(path) = p.to_str() @@ -649,10 +649,13 @@ impl WordApp { Intake::Quit => { self.quit(); } - // WordCraft has no app-specific open actions. - Intake::OpenFor { .. } => {} + // An OS open request that arrived as bytes, with no path. Intake::Bytes { name, bytes } => { - self.open_dropped(&[DroppedFile { path: None, name, bytes: Some(bytes) }], DropTarget::Elsewhere); + let data = wordcraft_engine::cmd::insert::base64_encode(bytes.as_ref()); + if let Err(e) = self.run("file.open", json!({"path": name, "data": data})) { + self.report_open_failure(&name, &e); + } + self.ui.backstage = false; } } } diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index ba1e71f794..81e0cdbe53 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -9,7 +9,7 @@ //! control library //! - `ui.clickText {page, x, y}`: click at a page position (points from the page's top-left) //! - `ui.dialog.set`, `ui.dialog.confirm`, `ui.dialog.cancel`: the open dialogs' fields and answers -//! - `ui.screenshot {path?}`: PNG of the window; `ui.render {path?, page?, scale?}`: page PNG +//! - `ui.screenshot {path?, region?}`: PNG of the window (or of `region` `[x0, y0, x1, y1]` in points); `ui.render {path?, page?, scale?}`: page PNG //! (without `path`, both reply with the PNG as base64 `png`) //! - `ui.resize`, `ui.focus`, `ui.closeWindow`, `ui.clipboard`, `ui.replayAt`, `ui.accessTree` //! - `ui.parity`: feature catalog parity diff --git a/crates/ui-egui/src/options.rs b/crates/ui-egui/src/options.rs index 24b6ebc26d..51d6489d33 100644 --- a/crates/ui-egui/src/options.rs +++ b/crates/ui-egui/src/options.rs @@ -708,30 +708,26 @@ impl PreferencesModel for OptionsModel<'_> { fn custom_row(&mut self, ui: &mut Ui, key: &str) -> bool { match key { "general.defaultApp" => default_app_row(self.app, ui), - "proofing.autoCorrect" => { - if Button::new(tl!("AutoCorrect Options")).show(ui).clicked() { - self.run("tools.autocorrect", json!({})); - } - } + "proofing.autoCorrect" => self.command_button(ui, tl!("AutoCorrect Options"), "tools.autocorrect"), "proofing.customDictionaryFile" => self.custom_dictionary_file(ui), "proofing.customDictionary" => self.custom_dictionary(ui), "language.proofingLanguage" => { Text::new(self.strings.proofing_language.clone()).role(TypeRole::Caption).shade(Shade::Faint).show(ui); + false } // PLAN: assumed `your_languages(app: &mut WordApp, ui: &mut Ui)` (chrome-w12) - "language.yourLanguages" => crate::language_packs::your_languages(self.app, ui), - "language.dictionaryFiles" => dictionary_files(ui), - "advanced.customizeKeyboard" => { - if Button::new(tl!("Customize…")).show(ui).clicked() { - self.run("tools.customizeKeyboard", json!({})); - } + "language.yourLanguages" => { + crate::language_packs::your_languages(self.app, ui); + false } - "advanced.customizeRibbon" if Button::new(tl!("Customize…")).show(ui).clicked() => { - self.run("tools.customizeRibbon", json!({})); + "language.dictionaryFiles" => { + dictionary_files(ui); + false } - _ => {} - }; - false + "advanced.customizeKeyboard" => self.command_button(ui, tl!("Customize…"), "tools.customizeKeyboard"), + "advanced.customizeRibbon" => self.command_button(ui, tl!("Customize…"), "tools.customizeRibbon"), + _ => false, + } } fn custom_page(&mut self, ui: &mut Ui, page: &str) -> bool { @@ -764,21 +760,32 @@ impl OptionsModel<'_> { /// Enter or focus loss. The field is given the saved path and never writes it: the framework /// holds the draft while an edit is open and drops it when the saved path changes (an agent's /// `file.options`) or the page is left, so no edit open always shows the saved path. - fn custom_dictionary_file(&mut self, ui: &mut Ui) { + /// A button that runs `command` when clicked; whether it did. + fn command_button(&mut self, ui: &mut Ui, label: impl Into, command: &str) -> bool { + let clicked = Button::new(label).show(ui).clicked(); + if clicked { + self.run(command, json!({})); + } + clicked + } + + fn custom_dictionary_file(&mut self, ui: &mut Ui) -> bool { let saved = self.app.session.prefs.custom_dictionary.clone().unwrap_or_default(); let out = TextField::new(tl!("Dictionary file:"), Bind::given(saved)).limit(None).show(ui); let committed = out.events.into_iter().find_map(|event| match event { EditEvent::Commit { after, .. } => Some(after), _ => None, }); + let changed = committed.is_some(); if let Some(path) = committed { self.set("proofing.customDictionaryFile", PrefValue::Text(path)); } + changed } /// The custom dictionary: the words Add to Dictionary kept, each with a Remove button, and a /// field to add one. - fn custom_dictionary(&mut self, ui: &mut Ui) { + fn custom_dictionary(&mut self, ui: &mut Ui) -> bool { let words = wordcraft_engine::proof::user_dictionary(); if words.is_empty() { Text::new(tl!("No words yet. Add to Dictionary on a misspelled word puts it here.")).role(TypeRole::Caption).shade(Shade::Faint).show(ui); @@ -795,8 +802,10 @@ impl OptionsModel<'_> { } }) }); + let mut changed = false; if let Some(w) = removed.take() { self.options(json!({"removeWords": [w]})); + changed = true; } // Enter or Add files the draft and clears it. Row::new().show(ui, |ui, cx| { @@ -808,8 +817,10 @@ impl OptionsModel<'_> { if ok && (add || out.submitted) { self.options(json!({"addWords": [word]})); draft.clear(); + changed = true; } }); + changed } } @@ -863,7 +874,7 @@ fn language_name(lang: wordcraft_engine::proof::ProofLang) -> &'static str { /// the host can (`Services::make_default_app`: Windows opens Default apps, Linux and BSD use /// `xdg-mime`); macOS shows how to do it in Finder, the web shows nothing. #[cfg(not(target_arch = "wasm32"))] -fn default_app_row(app: &mut WordApp, ui: &mut Ui) { +fn default_app_row(app: &mut WordApp, ui: &mut Ui) -> bool { if app.services.make_default_app.is_some() { let hint = if cfg!(target_os = "windows") { tl!("Opens Settings › Default apps, where you choose WordCraft for .docx and the other document types.") @@ -874,6 +885,7 @@ fn default_app_row(app: &mut WordApp, ui: &mut Ui) { // Only a person's click changes system defaults: an automation client's pass does not. if clicked && !WindowHost::of(ui.ctx()).injected_pass() { let _ = app.make_default_app(); + return true; } } else if cfg!(target_os = "macos") { Text::new(tl!("To open Word documents with WordCraft by default: select one in Finder, choose File › Get Info, pick WordCraft under Open with, then click Change All.")) @@ -881,11 +893,14 @@ fn default_app_row(app: &mut WordApp, ui: &mut Ui) { .shade(Shade::Faint) .show(ui); } + false } /// The web has no system default apps to change: nothing to show. #[cfg(target_arch = "wasm32")] -fn default_app_row(_app: &mut WordApp, _ui: &mut Ui) {} +fn default_app_row(_app: &mut WordApp, _ui: &mut Ui) -> bool { + false +} /// The Options page. pub fn page(app: &mut WordApp, ui: &mut Ui) { diff --git a/crates/ui-egui/src/printing.rs b/crates/ui-egui/src/printing.rs index 3c0cab0a4d..d2ebdeca7b 100644 --- a/crates/ui-egui/src/printing.rs +++ b/crates/ui-egui/src/printing.rs @@ -262,6 +262,11 @@ pub fn submit(app: &mut crate::WordApp, params: &Value) -> Result let Some(spool) = app.services.print.clone() else { return Err("printing to the system print dialog isn't available here; export a PDF instead".into()); }; + // Save as PDF is WordCraft's own route, not the spooler's. + if app.printing.settings.destination == Destination::File { + app.print_pdf_dialog(); + return Ok(json!({"saveAsPdf": true})); + } let chooses = spool.chooses_printer(); if chooses && !app.printing.ready() { return Err("Select an available printer in File > Print before submitting.".into()); diff --git a/docs/control-protocol.md b/docs/control-protocol.md index eaba10ef85..fbcba77dcb 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -103,7 +103,7 @@ let apps move windows, so there Arrange All and Side by Side only resize. | `ui.wheel` | `x`, `y`, `dy`, `dx?`, `unit?` (`point`/`line`/`page`), `phase?` (`start`/`move`/`end`), modifiers | mouse-wheel or trackpad scroll at window coordinates (`dy` < 0 scrolls down) | | `ui.key` | `key` (`B`, `Enter`, `Left`…), `shift?`, `alt?`, `cmd?` | key press through egui (shortcuts apply) | | `ui.text` | `text` | typed text through egui | -| `ui.screenshot` | `path?` | PNG of the window in the root viewport: written to `path`, or without one returned as base64 `png` in the reply. Capturing a secondary document window is not supported by the viewport renderer; select the root window with `view.switchWindows {"window": root}` first | +| `ui.screenshot` | `path?`, `region?` (`[x0, y0, x1, y1]` in points) | PNG of the window (or of `region`) in the root viewport: written to `path`, or without one returned as base64 `png` in the reply. Capturing a secondary document window is not supported by the viewport renderer; select the root window with `view.switchWindows {"window": root}` first | | `ui.render` | `path?`, `page?` (1-based), `scale?`, `doc?` | PNG of a page, rendered by the engine: written to `path`, or without one returned as base64 `png` in the reply (never a fixed name in the shared temporary folder) | | `ui.parity` | — | feature-catalog parity | | `ui.resize` | `width`, `height` | asks for that window content size in points; sizes that aren't positive and finite are refused, the rest are clamped to the app's minimum (600 × 480, #5886) and to the largest surface the GPU can draw (at most 16384; that limit wins over the minimum), and the reply's `width` and `height` are the size asked for |