Merge branch 'red7/g4' into area/app-1

This commit is contained in:
Dylan M. Taylor
2026-11-19 12:26:19 -05:00
13 changed files with 87 additions and 90 deletions
+7 -1
View File
@@ -495,7 +495,13 @@ impl PdfCraftApp {
let mut root =
RootEnv::new().mode(self.theme_preference).direction(direction).scale(Scale::new(crate::ui_scale::zoom(self.ui_scale, system, native)));
root.motion = self.animation_effects;
root
// Today is the session's day, the one its date formats and Fill & Sign's Date tool use: the calendars ring it
// and pick it.
let (year, month, day) = self.session.today();
match craft_i18n::CalendarDate::new(year, u8::try_from(month).unwrap_or(0), u8::try_from(day).unwrap_or(0)) {
Some(today) => root.today(today),
None => root,
}
}
/// Read mode and full screen hide the hotbar (the quick tools), and its tools window with it.
+3 -1
View File
@@ -668,7 +668,9 @@ impl PdfCraftApp {
if let Some(error) = error {
dialog = dialog.error(craft::ui::runtime::env::Label::from(error));
}
let output = dialog.show(ui);
// Open while a prompt waits: a wrong password sets the prompt again, which opens the dialog again.
let mut open = true;
let output = dialog.opened(craft::ui::contract::Bind::bound(&mut open)).show(ui);
let password = match (output.answer, output.closed) {
(Some(answer), _) => Some(answer.secret.expose().to_string()),
(None, Some(_)) => None,
+1 -2
View File
@@ -130,8 +130,7 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
let _ = Text::new(tl!("Join the ArtCraft community").to_string()).show(ui);
let _ = Text::new(tl!("Get help, share feedback and follow development on Discord.").to_string()).show(ui);
// Closed for this run only: the card is back on the next launch.
// PLAN: the Close control is a Button: IconButton's label builder is not in the bundle.
if Button::new(tl!("Close").to_string()).id_salt("community-close").show(ui).clicks > 0 {
if IconButton::new(IconId::new("x")).id_salt("community-close").label(tl!("Close")).show(ui).clicked() {
asked.borrow_mut().push(Asked::CloseCommunityCard);
}
}
+13 -1
View File
@@ -104,6 +104,18 @@ fn current_tool(app: &PdfCraftApp) -> String {
}
}
/// The tool each slot shows while its tools aren't current. The comment groups and Fill & Sign show the app's own last
/// tool of theirs, which every pick sets (a command, a menu, the control channel), with the toolbar shown or not; the
/// other slots show the rail's own memory.
fn last_used(app: &PdfCraftApp) -> LastUsed<String> {
let mut last = app.hotbar.last_used.clone();
for (g, tool) in app.comment_prefs.group_tool.iter().enumerate() {
last.set(SLOT_COMMENT + g as SlotId, tool.command().to_owned());
}
last.set(SLOT_FILL, app.fill_tool.command().to_owned());
last
}
/// The built-in slots, then one slot for each of `user` commands.
fn slots_with(app: &PdfCraftApp, user: &[String]) -> Vec<ToolSlot<String>> {
let mut slots = vec![
@@ -187,7 +199,7 @@ pub(crate) fn show_rail(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
app.hotbar.normalize();
let toolbar = slots(app);
let current = current_tool(app);
let last_used = app.hotbar.last_used.clone();
let last_used = last_used(app);
let editing = app.hotbar.drawer_open;
let mut rail = ToolRail::new(tl!("Toolbar").to_string(), &toolbar, &current, &last_used).edit_toolbar(tl!("Edit toolbar").to_string());
if editing {
+5 -7
View File
@@ -198,13 +198,11 @@ pub(crate) fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) -> PanelResult {
let current = rows.rows.iter().filter(|r| is_selected(r)).map(|r| r.key.clone()).collect();
let keys: Vec<(String, usize)> =
changed(current, change).iter().filter_map(|k| rows.get(k).and_then(|r| r.select.clone())).collect();
if let Some((last, rest)) = keys.split_last() {
selection.selected = Some(last.clone());
selection.also = rest.to_vec();
} else {
selection.selected = None;
selection.also.clear();
}
// The anchor of Align and Match Size stays the field selected first while it stays selected, as
// `PrepareView::select` keeps it for clicks on the page.
let lead = selection.selected.clone().filter(|lead| keys.contains(lead)).or_else(|| keys.last().cloned());
selection.also = keys.into_iter().filter(|key| Some(key) != lead.as_ref()).collect();
selection.selected = lead;
}
if let SelectionChange::Set(keys) = change
&& let Some(key) = keys.last()
@@ -168,6 +168,12 @@ impl Rig {
crate::export_ui::open_kind(self.h.state()).is_some()
}
/// Whether a notice on screen says `text`.
fn notice_says(&self, text: &str) -> bool {
use egui_kittest::kittest::NodeT as _;
self.h.query_all_by_label_contains(text).any(|node| node.accesskit_node().role() == egui::accesskit::Role::Status)
}
fn password_dialog(&self) -> bool {
self.h.query_all_by_label("Password").next().is_some()
}
@@ -323,7 +329,7 @@ fn a_chosen_tool_does_not_run_when_native_preparation_rejects_the_file() {
assert_eq!(rig.tabs(), 0);
assert!(!rig.export_open() && !rig.password_dialog());
// The notice's wording is the app's; only that an open failure is shown is asserted.
assert!(rig.h.query_by_label_contains("Couldn't open").is_some(), "the open failure is reported");
assert!(rig.notice_says("Couldn't open"), "the open failure is reported");
}
#[test]
@@ -671,7 +677,7 @@ fn file_open_converts_an_office_document_on_the_worker() {
assert_eq!(doc.name, format!("pdfcraft-open-tool-{}-office.pdf", std::process::id()));
assert!(doc.path.is_none(), "the converted PDF is new and unsaved, not the .docx on disk");
} else {
assert!(rig.h.query_by_label_contains("LibreOffice, which isn't installed").is_some(), "the failure names the missing dependency");
assert!(rig.notice_says("LibreOffice, which isn't installed"), "the failure names the missing dependency");
}
}
+3 -4
View File
@@ -186,10 +186,9 @@ fn cancelling_shared_properties_discards_only_the_draft() {
select(&mut h, &["alpha", "beta", "consent"]);
h.get_by_label("Appearance").click();
h.run_steps(4);
// The fill row is the second "No color": border first, then fill.
click_gate(&mut h, "Fill Color:");
h.run_steps(4);
h.get_all_by_label("No color").nth(1).unwrap().click();
h.get_by_role_and_label(Role::Group, "Fill Color:").get_by_label("No fill").click();
h.run_steps(4);
assert_eq!(shared(&h)["fill"]["apply"], true);
assert!(shared(&h)["fill"]["value"].is_null(), "no fill is the draft's value");
@@ -215,7 +214,7 @@ fn locked_field_refuses_the_entire_batch_and_keeps_the_draft_for_correction() {
assert!(shared_open(&h), "the dialog stays open for the correction");
assert!(refused_with(&h, "locked"));
// Unlocking applies the first field's value: alpha is not locked.
h.get_by_label("Locked").click();
click_gate(&mut h, "Locked");
h.run_steps(4);
assert_eq!(shared(&h)["locked"]["value"], false);
assert_eq!(shared(&h)["tooltip"]["value"], "Shared help", "what was typed is kept");
@@ -333,7 +332,7 @@ fn selecting_several_widgets_of_one_radio_group_does_not_duplicate_field_edits()
p.also = vec![("group".into(), 1), ("alpha".into(), 0)];
h.execute("form.field.properties");
h.run_steps(4);
assert_eq!(shared(&h)["names"], serde_json::json!(["group", "alpha"]), "the group is listed once");
assert_eq!(shared(&h)["fields"], serde_json::json!(["group", "alpha"]), "the group is listed once");
h.get_by_role_and_label(Role::Group, "Tooltip:");
set_tooltip(&mut h, "Shared help");
h.get_by_label("OK").click();
+33 -41
View File
@@ -100,6 +100,20 @@ fn click(h: &mut Harness<'static, PdfCraftApp>, x: f32, y: f32) {
h.run_steps(3);
}
/// The toolbar's Fill & Sign slot, named by the command of the tool it shows (`command` is that command's label). The
/// slot's flyout mark carries the same name, inside the slot, so the slot is the first of them.
fn fill_slot<'h>(h: &'h Harness<'static, PdfCraftApp>, command: &'h str) -> egui_kittest::Node<'h> {
h.query_all_by_role_and_label(egui::accesskit::Role::Button, command).next().unwrap_or_else(|| panic!("no toolbar slot named {command:?}"))
}
/// The row of the Fill & Sign slot's flyout that runs `command` (its label).
fn fill_flyout_row<'h>(h: &'h Harness<'static, PdfCraftApp>, command: &str) -> egui_kittest::Node<'h> {
let command = command.to_owned();
h.get_by(move |n| {
matches!(n.role(), egui::accesskit::Role::MenuItem | egui::accesskit::Role::MenuItemRadio) && n.label().as_deref() == Some(command.as_str())
})
}
fn items(h: &Harness<'static, PdfCraftApp>) -> Vec<(String, Option<String>)> {
let s = h.state();
let mut v: Vec<_> = s.session.get(s.views[0].id).unwrap().info.annotations.iter().map(|a| (a.subtype.clone(), a.contents.clone())).collect();
@@ -861,12 +875,8 @@ fn changing_saved_signatures_and_initials_preserves_placed_marks() {
click(&mut h, 40.0, 300.0);
let original = format!("{:?}", h.state().session.get(h.state().views[0].id).unwrap().info.annotations);
// The quick toolbar exposes replacement without changing the normal placement action.
h.get_by_label("Fill & Sign: Place saved signature").click();
h.run_steps(2);
h.get_by_label("Fill & Sign: Sign").click();
h.run_steps(2);
h.get_by_label("Change signature").click();
// Replacing the saved signature leaves the placement tool and the placed marks alone.
assert!(h.execute("sign.fill.signature.change"));
h.run_steps(2);
assert!(pad_open(&h));
assert!(shows(&h, "Change signature"));
@@ -885,11 +895,7 @@ fn changing_saved_signatures_and_initials_preserves_placed_marks() {
click(&mut h, 40.0, 200.0);
assert_eq!(items(&h).len(), 2);
h.get_by_label("Fill & Sign: Place saved signature").click();
h.run_steps(2);
h.get_by_label("Fill & Sign: Sign").click();
h.run_steps(2);
h.get_by_label("Change initials").click();
assert!(h.execute("sign.fill.initials.change"));
h.run_steps(2);
assert!(shows(&h, "Change initials"));
assert!(shows(&h, "AL"), "the pad starts from the saved initials");
@@ -2218,17 +2224,8 @@ fn the_first_save_after_placing_a_signature_asks_to_lock_it() {
assert_eq!(signed(&h), 0, "locked into the page");
assert!(!h.state().session.get(h.state().views[0].id).unwrap().dirty);
assert!(h.state().flatten_fill_sign_on_save, "remembered as the preference");
// The switch is in the panel's Sign yourself section, once; the Sign menu over the page,
// where it was easy to miss, no longer has it.
// The switch is in the panel's Sign yourself section, once.
h.state_mut().flatten_fill_sign_on_save = false;
// With the signature tool on, the quick tool button opens the Sign menu.
h.execute("sign.fill.signature");
h.run_steps(2);
h.get_by_label("Fill & Sign: Sign").click();
h.run_steps(2);
h.get_by_label("Use signature");
assert!(h.query_by_label("Lock into the page when saving").is_none(), "not in the Sign menu");
h.key_press(egui::Key::Escape);
h.run_steps(2);
assert!(h.query_by_label("Lock into the page when saving").is_none(), "the panel is closed");
h.state_mut().left = pdfcraft_ui_egui::LeftPanel::Tool("fill_sign");
@@ -2685,7 +2682,7 @@ fn fill_and_sign_bar_controls_pick_tools_and_restyle_the_selection() {
};
// The fill button shows the tool it picks.
let shows_picked_tool: Row = |h| {
h.get_by_label("Fill & Sign: Add signature").click();
fill_slot(h, "Fill & Sign: sign").click();
h.run_steps(2);
assert_eq!(h.state().quick_tool, QuickTool::Fill(FillTool::Signature));
assert!(pad_open(h), "an empty slot opens the pad");
@@ -2695,23 +2692,18 @@ fn fill_and_sign_bar_controls_pick_tools_and_restyle_the_selection() {
h.state_mut().signature = Some(SavedSig::Typed("Ada Lovelace".into()));
h.state_mut().quick_tool = QuickTool::Select;
h.run_steps(2);
h.get_by_label("Fill & Sign: Place saved signature").click();
fill_slot(h, "Fill & Sign: sign").click();
h.run_steps(2);
assert_eq!(h.state().quick_tool, QuickTool::Fill(FillTool::Signature));
assert!(!pad_open(h), "a saved signature opens no pad");
h.get_by_label("Fill & Sign: Sign").click();
h.run_steps(2);
assert_eq!(
h.get_by_label("Use signature").accesskit_node().toggled(),
Some(egui::accesskit::Toggled::True),
"the active tool's card is marked"
);
h.key_press(egui::Key::Escape);
h.run_steps(2);
h.state_mut().left = pdfcraft_ui_egui::LeftPanel::Tool("fill_sign");
h.state_mut().left_open = true;
h.run_steps(3);
assert_eq!(h.get_by_label("Use signature").accesskit_node().is_selected(), Some(true), "the active tool's card is marked");
h.execute("sign.fill.check");
h.state_mut().quick_tool = QuickTool::Select;
h.run_steps(2);
h.get_by_label("Fill & Sign: Checkmark").click();
fill_slot(h, "Fill & Sign: checkmark").click();
h.run_steps(2);
assert_eq!(h.state().quick_tool, QuickTool::Fill(FillTool::Check), "the button keeps the last Fill & Sign tool");
};
@@ -2726,18 +2718,18 @@ fn fill_and_sign_bar_controls_pick_tools_and_restyle_the_selection() {
h.state_mut().set_full_screen(false);
h.run_steps(2);
assert_eq!(h.state().quick_tool, QuickTool::Fill(FillTool::Date));
h.get_by_label("Fill & Sign: Date");
fill_slot(h, "Fill & Sign: date");
h.state_mut().quick_tool = QuickTool::Select;
h.run_steps(2);
h.get_by_label("Fill & Sign: Checkmark").click();
fill_slot(h, "Fill & Sign: checkmark").click();
h.run_steps(2);
assert_eq!(h.state().quick_tool, QuickTool::Fill(FillTool::Check));
};
// The fill button keeps Date after deselecting and across documents.
let keeps_date: Row = |h| {
h.get_by_label("Fill & Sign: Add signature").click_secondary();
fill_slot(h, "Fill & Sign: sign").click_secondary();
h.run_steps(2);
h.get_by_label("Date").click();
fill_flyout_row(h, "Fill & Sign: date").click();
h.run_steps(2);
assert_eq!(h.state().quick_tool, QuickTool::Fill(FillTool::Date));
h.get_by_label("Select (V)").click();
@@ -2747,7 +2739,7 @@ fn fill_and_sign_bar_controls_pick_tools_and_restyle_the_selection() {
h.state_mut().open_bytes(&ctx_h, "second.pdf", None, FIXTURE.to_vec()).unwrap();
h.state_mut().active = Some(1);
h.run_steps(2);
h.get_by_label("Fill & Sign: Date").click();
fill_slot(h, "Fill & Sign: date").click();
h.run_steps(2);
assert_eq!(h.state().quick_tool, QuickTool::Fill(FillTool::Date), "a click picks the shown tool, not the default");
assert!(!pad_open(h), "the default tool's dialog stays closed");
@@ -2760,7 +2752,7 @@ fn fill_and_sign_bar_controls_pick_tools_and_restyle_the_selection() {
h.state_mut().open_bytes(&ctx_h, "third.pdf", None, FIXTURE.to_vec()).unwrap();
h.state_mut().active = Some(0);
h.run_steps(2);
h.get_by_label("Fill & Sign: Date").click();
fill_slot(h, "Fill & Sign: date").click();
h.run_steps(2);
assert_eq!(h.state().quick_tool, QuickTool::Fill(FillTool::Date), "the tool outlives closing every document");
};
@@ -2810,7 +2802,7 @@ fn a_fill_tool_selected_while_the_quick_bar_is_hidden_is_remembered() {
h.set_option("quick", "select").unwrap();
h.state_mut().mode = mode;
h.run_steps(2);
h.get_by_label("Fill & Sign: Date");
fill_slot(&h, "Fill & Sign: date");
h.state_mut().initials = Some(SavedSig::Typed("AL".into()));
h.set_option("mode", "read").unwrap();
@@ -2823,7 +2815,7 @@ fn a_fill_tool_selected_while_the_quick_bar_is_hidden_is_remembered() {
h.state_mut().quick_tool = QuickTool::Select;
h.state_mut().mode = mode;
h.run_steps(2);
h.get_by_label("Fill & Sign: Place saved initials");
fill_slot(&h, "Fill & Sign: initials");
}
fn commit_typed_text(h: &mut Harness<'static, PdfCraftApp>) {
+7 -2
View File
@@ -65,7 +65,12 @@ fn card_count(h: &Harness<'static, PdfCraftApp>) -> usize {
/// Whether the "Save changes?" prompt is on screen.
fn asks_to_save(h: &Harness<'static, PdfCraftApp>) -> bool {
h.query_by_label("Don't save").is_some()
h.query_by_role_and_label(egui::accesskit::Role::Dialog, "Unsaved changes").is_some()
}
/// The unsaved-changes question's Save answer in the platform's words (the framework dialog asks Yes and No off macOS).
fn save_answer() -> &'static str {
if cfg!(target_os = "macos") { "Save" } else { "Yes" }
}
fn harness() -> Harness<'static, PdfCraftApp> {
@@ -1033,7 +1038,7 @@ fn close_all_saves_text_typed_in_a_tab_that_is_no_longer_active() {
h.state_mut().close_all(&ctx_h);
h.run_steps(2);
assert!(asks_to_save(&h), "the first document has an unsaved change");
h.get_all_by_label("Save").last().expect("the prompt's Save button").click();
h.get_all_by_label(save_answer()).last().expect("the prompt's Save button").click();
wait_for_file(&mut h, &files, &out);
assert_eq!(saved_value(&files, &out, "name"), ["Typed in tab one"]);
let _ = std::fs::remove_dir_all(&dir);
+4 -3
View File
@@ -32,7 +32,8 @@ fn home_community_card_closes_for_this_run() {
assert!(!crate::control::new_app().community_card_closed);
}
/// Runs frames until the node labelled `label` exists and has stopped moving, then returns it.
/// Runs frames until the node labelled `label` exists and has stopped moving, then returns it. A table row is named by
/// its first cell, so a name may be the row's and its cell's: the first (outer) node is the one returned.
///
/// The About dialog is a modal centred on its own size, and switching tabs changes that size, so
/// for a few frames afterwards the modal grows and recentres and every control in it moves. A
@@ -43,9 +44,9 @@ fn settled<'a>(h: &'a mut Harness<'static, PdfCraftApp>, label: &'a str) -> egui
let mut last = None;
for _ in 0..60 {
h.run_steps(1);
let now = h.query_by_label(label).map(|n| n.rect());
let now = h.query_all_by_label(label).next().map(|n| n.rect());
if now.is_some() && now == last {
return h.get_by_label(label);
return h.query_all_by_label(label).next().expect("the node was just found");
}
last = now;
}
+3 -1
View File
@@ -60,10 +60,12 @@ fn links(h: &Harness<'static, PdfCraftApp>) -> Vec<pdfcraft_engine::LinkItem> {
s.session.get(s.views[0].id).unwrap().links().to_vec()
}
/// Types the address into Link Properties' URL field.
/// Types the address over Link Properties' URL field, which starts with the scheme.
fn type_url(h: &mut Harness<'static, PdfCraftApp>) {
h.get_by_role_and_label(Role::TextInput, "Link URL").click();
h.run_steps(1);
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
h.run_steps(1);
h.get_by_role_and_label(Role::TextInput, "Link URL").type_text("https://example.org");
h.run_steps(2);
}
-11
View File
@@ -168,7 +168,6 @@ struct Recorded {
writes: Vec<Vec<Flavor>>,
held: Option<String>,
refused: Option<&'static str>,
refuse_all: bool,
}
impl RecordingClipboard {
@@ -179,13 +178,6 @@ impl RecordingClipboard {
clipboard
}
/// A clipboard with no system behind it: every write is refused (and recorded).
pub fn refusing_all() -> Self {
let clipboard = Self::default();
clipboard.lock().refuse_all = true;
clipboard
}
/// The text the app last copied.
pub fn copied(&self) -> Option<String> {
self.lock().held.clone()
@@ -205,9 +197,6 @@ impl ClipboardBackend for RecordingClipboard {
fn write(&mut self, flavors: &[Flavor]) -> Result<usize, ClipboardError> {
let mut state = self.lock();
state.writes.push(flavors.to_vec());
if state.refuse_all {
return Err(ClipboardError::Unavailable);
}
if let Some(mime) = state.refused
&& flavors.iter().any(|f| f.mime == mime)
{
-14
View File
@@ -320,20 +320,6 @@ fn selected_text_copy_falls_back_to_plain_text_when_html_is_refused() {
assert!(copied(&clipboard, "quick"), "the plain text goes out the usual way");
}
/// With a clipboard that takes no write, no HTML is built and the plain text goes out as before.
#[test]
fn selected_text_copy_without_system_clipboard_builds_no_html() {
// PLAN: assumed RecordingClipboard::refusing_all(): a backend with no clipboard behind it, which takes nothing.
let clipboard = RecordingClipboard::refusing_all();
let (mut h, at) = harness_clip(two_lines(), clipboard.clone(), |_| {});
click(&mut h, at);
click(&mut h, at);
assert!(h.execute("edit.copy"));
h.step();
assert!(html_sets(&clipboard).is_empty());
assert!(copied(&clipboard, "quick"));
}
/// A document that withholds copying gives neither the text nor its HTML.
#[test]
fn selected_text_copy_with_formatting_honours_permissions() {