PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
M6: doc comments for the functions this change touches
Eric Kadena0ae8a39961d
diff --git a/crates/automation/src/a11y.rs b/crates/automation/src/a11y.rsindex a9e13cbc3..19afb16a4 100644--- a/crates/automation/src/a11y.rs+++ b/crates/automation/src/a11y.rs@@ -646,6 +646,8 @@ impl Automation {}}+/// A script's request to the viewer as the JSON that running a script reports; a side panel+/// goes by its fixed id.fn request_json(r: &pdfcraft_engine::js::Request) -> Value {use pdfcraft_engine::js::Request as R;match r {diff --git a/crates/engine/src/js.rs b/crates/engine/src/js.rsindex 73be05660..9b057900f 100644--- a/crates/engine/src/js.rs+++ b/crates/engine/src/js.rs@@ -26,6 +26,9 @@ impl JsOutput {self.alerts.is_empty() && self.console.is_empty() && self.requests.is_empty() && self.errors.is_empty()}+ /// Adds what a field's own script produced: its alerts, console lines, errors and requests,+ /// except a request to show a side panel or open Save As, which is noted on the console+ /// and dropped.fn absorb(&mut self, o: &Outcome) {self.alerts.extend(o.alerts.iter().cloned());self.console.extend(o.console.iter().cloned());diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rsindex 4c19b8011..6b0a97e98 100644--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@ -6107,6 +6107,8 @@ fn undo_never_makes_an_unsaved_document_clean() {assert!(!s.get(new).unwrap().dirty, "once saved, undo back to the saved state is clean");}+/// An XFA button's click script may show the attachments panel; a text field's exit script+/// asking the same is noted on the console and ignored.#[test]fn an_xfa_button_may_show_a_side_panel_and_other_events_may_not() {let xdp = r##"<?xml version="1.0" encoding="UTF-8"?>@@ -6134,6 +6136,8 @@ fn an_xfa_button_may_show_a_side_panel_and_other_events_may_not() {assert!(out.console.iter().any(|c| c.contains("show a side panel")), "{:?}", out.console);}+/// A validate script that asks for Save As and a side panel gets neither, with a console note+/// for each; a button's script may still open Save As.#[test]fn a_fields_own_script_may_not_save_as_or_show_a_panel() {let mut s = Session::new().with_clock(|| 1_700_000_000);diff --git a/crates/js/src/lib.rs b/crates/js/src/lib.rsindex aff27f951..1eb3d60e8 100644--- a/crates/js/src/lib.rs+++ b/crates/js/src/lib.rs@@ -608,6 +608,8 @@ pub(crate) fn menu_item(name: &str) -> Option<Request> {})}+/// `app.execMenuItem(name)`: queues the request [`menu_item`] gives for the name (Save opens+/// Save As too); an unknown name does nothing.fn exec_menu_item(_: &JsValue, args: &[JsValue], ctx: &mut Context) -> JsResult<JsValue> {let item = text(&arg(args, 0), ctx)?;if let Some(r) = menu_item(&item) {@@ -941,6 +943,9 @@ fn color_object(ctx: &mut Context) -> JsObject {o.build()}+/// Installs the form object model's globals: the document's functions and properties+/// (`getField`, `numFields`, `pageNum`, `info`, …), `app`, `util`, `console`, `display` and+/// `color`.fn install(ctx: &mut Context) -> JsResult<()> {let globals: [(&str, usize, NativeFunction); 9] = [("getField", 1, NativeFunction::from_fn_ptr(get_field)),diff --git a/crates/js/src/tests.rs b/crates/js/src/tests.rsindex ec4cfcc5e..a78ce67de 100644--- a/crates/js/src/tests.rs+++ b/crates/js/src/tests.rs@@ -1137,12 +1137,15 @@ mod menu_items {use super::*;use crate::xfa::{XfaDoc, XfaEffect, XfaEvent, run_xfa};+ /// Every side panel has a fixed id in automation output.#[test]fn each_panel_has_a_fixed_id_for_automation() {let ids = [Panel::Bookmarks, Panel::Pages, Panel::Attachments, Panel::Signatures, Panel::Layers].map(Panel::id);assert_eq!(ids, ["bookmarks", "pages", "attachments", "signatures", "layers"]);}+ /// Each side panel item, Print and SaveAs make their request, in order; an unknown item+ /// makes none and is not an error.#[test]fn exec_menu_item_shows_side_panels_prints_and_saves() {let o = go(@@ -1166,6 +1169,7 @@ mod menu_items {);}+ /// `app.execMenuItem` works in XFA scripts too: a click shows the attachments panel.#[test]fn xfa_scripts_show_the_attachments_panel() {let event = XfaEvent { activity: "click".into(), target: "form1[0].page1[0].go[0]".into(), ..Default::default() };diff --git a/crates/js/src/xfa.rs b/crates/js/src/xfa.rsindex 8f64f9049..093ba633b 100644--- a/crates/js/src/xfa.rs+++ b/crates/js/src/xfa.rs@@ -1049,6 +1049,8 @@ fn set_focus(_: &JsValue, args: &[JsValue], ctx: &mut Context) -> JsResult<JsValOk(JsValue::undefined())}+/// `app.execMenuItem(name)`: the effect for the request the shared menu table gives the name+/// (Save opens Save As too); an unknown name does nothing.fn exec_menu_item(_: &JsValue, args: &[JsValue], ctx: &mut Context) -> JsResult<JsValue> {let item = text(&arg(args, 0), ctx)?;match crate::menu_item(&item) {diff --git a/crates/ui-egui/tests/forms.rs b/crates/ui-egui/tests/forms.rsindex 6b2add486..47a5c8b52 100644--- a/crates/ui-egui/tests/forms.rs+++ b/crates/ui-egui/tests/forms.rs@@ -1073,6 +1073,8 @@ fn auto_size_fields_shrink_and_wrap_typed_text_to_fit_their_box() {assert_eq!(on_screen_fit(&h, "fixed", long).0, 10.0);}+/// A button script's `ShowHideFileAttachment` opens the attachments panel, and running it again+/// closes it.#[test]fn a_form_button_shows_and_hides_the_attachments_panel() {let mut h = harness();