Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

M6: side panels have fixed automation ids, and the parity note says where Print works

Eric Kaden9366af3badb6
diff --git a/crates/automation/src/a11y.rs b/crates/automation/src/a11y.rs
index 3a1422ec7..a9e13cbc3 100644
--- a/crates/automation/src/a11y.rs
+++ b/crates/automation/src/a11y.rs
@@ -657,7 +657,7 @@ fn request_json(r: &pdfcraft_engine::js::Request) -> Value {
R::Focus(f) => json!({ "focus": f }),
R::Beep => json!({ "beep": true }),
R::SaveAs => json!({ "save_as": true }),
- R::ShowPanel(p) => json!({ "panel": format!("{p:?}").to_lowercase() }),
+ R::ShowPanel(p) => json!({ "panel": p.id() }),
}
}
diff --git a/crates/js/src/lib.rs b/crates/js/src/lib.rs
index 987d28da4..281898c4a 100644
--- a/crates/js/src/lib.rs
+++ b/crates/js/src/lib.rs
@@ -174,6 +174,19 @@ pub enum Panel {
Layers,
}
+impl Panel {
+ /// The panel's name in automation output, fixed whatever the variant is called.
+ pub fn id(self) -> &'static str {
+ match self {
+ Panel::Bookmarks => "bookmarks",
+ Panel::Pages => "pages",
+ Panel::Attachments => "attachments",
+ Panel::Signatures => "signatures",
+ Panel::Layers => "layers",
+ }
+ }
+}
+
/// What running a script did.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Outcome {
diff --git a/crates/js/src/tests.rs b/crates/js/src/tests.rs
index bfb53996f..ec4cfcc5e 100644
--- a/crates/js/src/tests.rs
+++ b/crates/js/src/tests.rs
@@ -1137,6 +1137,12 @@ mod menu_items {
use super::*;
use crate::xfa::{XfaDoc, XfaEffect, XfaEvent, run_xfa};
+ #[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"]);
+ }
+
#[test]
fn exec_menu_item_shows_side_panels_prints_and_saves() {
let o = go(
diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml
index f47140442..12e11d82c 100644
--- a/parity/acrobat-features.toml
+++ b/parity/acrobat-features.toml
@@ -5137,7 +5137,7 @@ status = "partial"
commands = ["tools.js_console"]
tools = ["js_run"]
evidence = ["crates/js/src/tests.rs::calculate_scripts_read_fields_and_set_the_value", "crates/engine/src/tests.rs::form_javascript_validates_calculates_and_formats", "crates/automation/tests/automation.rs::javascript_through_tools"]
-notes = "boa (pure Rust) with the forms object model: event, getField/Field (value, readonly, display, colours, items, check boxes), app (with execMenuItem for the side panels, Print and Save As, from a button only), util.printf/printd/printx, console, display, color; no annotations, layers or dialogs (app.response returns null) yet."
+notes = "boa (pure Rust) with the forms object model: event, getField/Field (value, readonly, display, colours, items, check boxes), app (with execMenuItem for the side panels and Save As, from a button only, and Print where this.print() works), util.printf/printd/printx, console, display, color; no annotations, layers or dialogs (app.response returns null) yet."
[[feature]]
id = "form.js-console"