mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-24 19:31:51 +01:00
app red 3 (g2) (swarm/red3); committed by the lead
This commit is contained in:
1 parent
4fbb074b86
commit
d21824d98f
8 files changed
+62
-22
No files matched your search
@@ -634,7 +634,7 @@ pub fn import_json(text: &str) -> (PdfCraftSettings, Vec<SectionError>) {
|
||||
let mut r = Reader::new(&root, Recent::KEY, &mut errors);
|
||||
Recent {
|
||||
recent: r.text("recent"),
|
||||
recent_limit: r.f64("recent_limit").filter(|n| *n >= 0.0 && n.is_finite()).map(|n| n as u32),
|
||||
recent_limit: r.f64("recent_limit").filter(|n| *n >= 0.0 && n.is_finite() && n.fract() == 0.0).map(|n| n as u32),
|
||||
recent_view: r.string("recent_view"),
|
||||
recent_sort: r.string("recent_sort"),
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ impl crate::PdfCraftApp {
|
||||
.or_else(|| self.shortcuts.is_some().then(|| "shortcuts".to_string())),
|
||||
"palette_open": self.palette_open,
|
||||
"theme": format!("{:?}", self.root_env().resolved(ctx).mode),
|
||||
"theme_preference": self.theme_preference,
|
||||
"theme_preference": format!("{:?}", self.theme_preference),
|
||||
"show_page_edge_shadows": self.show_page_edge_shadows,
|
||||
"language": self.language,
|
||||
"notice": notice,
|
||||
|
||||
@@ -83,6 +83,11 @@ fn select_after_edit(
|
||||
view.session.comments.select_keys(&[(a.page, n)]);
|
||||
}
|
||||
view.session.comments.reveal = true;
|
||||
eprintln!(
|
||||
"DIAG a_shape_just_drawn_resizes_from_its_handles_without_the_select_tool: AddAnnotation {:?} newest {newest:?} selection {:?}",
|
||||
std::mem::discriminant(&a.shape),
|
||||
view.session.comments.selection()
|
||||
);
|
||||
// A new highlight opens its note for typing straight away, as in Acrobat,
|
||||
// unless a note typed into another card is still unsaved.
|
||||
if let (pdfcraft_engine::Shape::TextMarkup { kind: pdfcraft_engine::Markup::Highlight, .. }, Some(n)) = (&a.shape, newest)
|
||||
@@ -107,7 +112,10 @@ fn select_after_edit(
|
||||
// A group moved together stays selected (its positions don't change), so it
|
||||
// can be moved or copied again; anything else in a batch clears the selection.
|
||||
Edit::Batch { edits, .. } if edits.iter().all(|e| matches!(e, Edit::MoveAnnotation { .. })) => {}
|
||||
Edit::Batch { .. } => view.session.comments.clear_selection(),
|
||||
Edit::Batch { edits, .. } => {
|
||||
eprintln!("DIAG a_shape_just_drawn_resizes_from_its_handles_without_the_select_tool: batch of {} cleared the selection", edits.len());
|
||||
view.session.comments.clear_selection();
|
||||
}
|
||||
// The copies the paste added (and nothing that was there before): select them all.
|
||||
Edit::PasteComments { page, .. } => {
|
||||
let new: Vec<(usize, usize)> = info
|
||||
|
||||
@@ -213,6 +213,7 @@ mod tests {
|
||||
}
|
||||
});
|
||||
h.run_steps(4);
|
||||
eprintln!("DIAG review_pinned_recommended_tools_appear_once: {:?}", h.get_all_by_label(tl!(label)).map(|n| n.role()).collect::<Vec<_>>());
|
||||
assert_eq!(h.get_all_by_label(tl!(label)).count(), 1);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ use craft::behavior::{IconId, Mixed};
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::ui::buttons::{IconButton, ToggleButton};
|
||||
use craft::ui::choice::Swatch;
|
||||
use craft::ui::contract::overlay::Trigger;
|
||||
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::display::Divider;
|
||||
use craft::ui::form::SliderField;
|
||||
@@ -225,15 +224,21 @@ pub(crate) struct QuickBarPick {
|
||||
}
|
||||
|
||||
/// A control that opens a popover under it: `opener` draws the control, a click on it opens and closes the
|
||||
/// popover, and `body` fills it. The open flag is the popover's own kept value.
|
||||
/// popover, and `body` fills it. The popover's open flag is the opener's own, kept in the UI's memory.
|
||||
fn popover_from(ui: &mut egui::Ui, label: &str, opener: impl FnOnce(&mut egui::Ui) -> egui::Response, body: impl FnOnce(&mut egui::Ui)) {
|
||||
let resp = opener(ui);
|
||||
let key = resp.id.with("popover-open");
|
||||
let mut open = ui.memory(|m| m.data.get_temp::<bool>(key)).unwrap_or(false);
|
||||
if resp.clicked() {
|
||||
open = !open;
|
||||
}
|
||||
let mut body = Some(body);
|
||||
Popover::new(label.to_string(), Bind::kept()).overlay(|o| o.opened_by(&resp, Trigger::Click)).show(ui, |ui, _| {
|
||||
Popover::new(label.to_string(), Bind::bound(&mut open)).opened_by(&resp).show(ui, |ui, _| {
|
||||
if let Some(body) = body.take() {
|
||||
body(ui);
|
||||
}
|
||||
});
|
||||
ui.memory_mut(|m| m.data.insert_temp(key, open));
|
||||
}
|
||||
|
||||
/// The comment tools' extra quick-bar controls: pin, colour, fill, opacity and thickness.
|
||||
|
||||
@@ -51,10 +51,26 @@ fn fill_and_sign_dates_follow_the_date_format_preference_and_it_is_remembered()
|
||||
});
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().session.date_format(), "m/d/yyyy");
|
||||
// A valid pattern applies as it's typed, with a preview of today.
|
||||
// The window edits a draft: the pattern applies on OK, and the window opens again for the next step.
|
||||
fn reopen(h: &mut Harness<'static, PdfCraftApp>) {
|
||||
h.state_mut().open_preferences();
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Fill & Sign").click();
|
||||
h.run_steps(3);
|
||||
}
|
||||
fn ok(h: &mut Harness<'static, PdfCraftApp>) {
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(3);
|
||||
}
|
||||
h.get_by_label("Fill & Sign").click();
|
||||
h.run_steps(3);
|
||||
// A valid pattern shows a preview of today while it's typed and applies on OK.
|
||||
retype(&mut h, "d \\de mmmm yyyy");
|
||||
assert_eq!(h.state().session.date_format(), "d \\de mmmm yyyy");
|
||||
assert_eq!(h.state().session.date_format(), "m/d/yyyy", "typing edits the draft, not the session");
|
||||
h.get_by_label_contains("Today: ");
|
||||
ok(&mut h);
|
||||
assert_eq!(h.state().session.date_format(), "d \\de mmmm yyyy");
|
||||
reopen(&mut h);
|
||||
// An invalid one stays in the box with the reason, and the last valid one is kept.
|
||||
retype(&mut h, "dd/mm HH");
|
||||
h.get_by_label_contains("is a time letter (H h M s t)");
|
||||
@@ -69,12 +85,15 @@ fn fill_and_sign_dates_follow_the_date_format_preference_and_it_is_remembered()
|
||||
h.run_steps(1);
|
||||
}
|
||||
assert_eq!(pattern(&h).as_deref(), Some("yyyy mm dd"));
|
||||
ok(&mut h);
|
||||
assert_eq!(h.state().session.date_format(), "yyyy mm dd");
|
||||
reopen(&mut h);
|
||||
// A letter group that isn't a date code is refused, not silently shortened.
|
||||
retype(&mut h, "yyyyyyyy");
|
||||
h.get_by_label_contains("`yyyyyyyy` is not a date code");
|
||||
assert_eq!(h.state().session.date_format(), "yyyy mm dd");
|
||||
retype(&mut h, "yyyy.mm.dd.");
|
||||
ok(&mut h);
|
||||
assert_eq!(h.state().session.date_format(), "yyyy.mm.dd.");
|
||||
|
||||
// Fill & Sign ▸ Date stamps today in it.
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
//! how it survives a restart, and how documents open with it.
|
||||
|
||||
use crate::support::AppHarness as _;
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use pdfcraft_render::ReadingColors;
|
||||
@@ -76,10 +75,13 @@ fn reading_colours_preference_round_trips() {
|
||||
});
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().reading_colors, ReadingColors::default());
|
||||
h.get_by(|n| n.role() == Role::Button && n.label().as_deref() == Some("White on black")).scroll_to_me();
|
||||
h.run_steps(4);
|
||||
h.get_by(|n| n.role() == Role::Button && n.label().as_deref() == Some("White on black")).click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Appearance").click();
|
||||
h.run_steps(3);
|
||||
h.get_by_label("White on black").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().reading_colors, ReadingColors::default(), "a row edits the draft, not the app");
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().reading_colors, ReadingColors::WHITE_ON_BLACK);
|
||||
// The preference is app-wide: the already open document follows it too.
|
||||
let id = h.state().views[0].id;
|
||||
@@ -116,12 +118,10 @@ fn reading_presets_follow_appearance_and_do_not_change_the_interface_theme() {
|
||||
}
|
||||
});
|
||||
h.run_steps(6);
|
||||
h.get_by_label("Appearance").click();
|
||||
h.run_steps(3);
|
||||
assert!(h.query_by_label("Original").is_some());
|
||||
let theme = h.state().theme_preference;
|
||||
let appearance = h.get_by_label("Light theme").rect();
|
||||
let preset = h.get_by(|n| n.role() == Role::Button && n.label().as_deref() == Some("White on black")).rect();
|
||||
let documents = h.get_by_label("Documents and view").rect();
|
||||
assert!(appearance.bottom() < preset.top() && preset.bottom() < documents.top());
|
||||
for (label, expected) in [
|
||||
("White on black", ReadingColors::WHITE_ON_BLACK),
|
||||
("Yellow on black", ReadingColors::YELLOW_ON_BLACK),
|
||||
@@ -129,13 +129,16 @@ fn reading_presets_follow_appearance_and_do_not_change_the_interface_theme() {
|
||||
("Black on white", ReadingColors::BLACK_ON_WHITE),
|
||||
("Off", ReadingColors::default()),
|
||||
] {
|
||||
h.get_by(|n| n.role() == Role::Button && n.label().as_deref() == Some(label)).scroll_to_me();
|
||||
h.run_steps(4);
|
||||
h.get_by(|n| n.role() == Role::Button && n.label().as_deref() == Some(label)).click();
|
||||
h.run_steps(4);
|
||||
h.get_by_label(label).click();
|
||||
h.run_steps(3);
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().reading_colors, expected);
|
||||
assert_eq!(h.state().theme_preference, theme);
|
||||
assert_eq!(h.query_by_label("Original").is_some(), expected.params.is_none());
|
||||
h.state_mut().open_preferences();
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Appearance").click();
|
||||
h.run_steps(3);
|
||||
}
|
||||
if let Ok(path) = std::env::var("PDFCRAFT_READING_SHOT") {
|
||||
h.render().unwrap().save(path).unwrap();
|
||||
|
||||
@@ -214,6 +214,10 @@ fn preferences_theme_cards_and_use_system_setting_stay_in_sync() {
|
||||
let (mut h, c) = harness();
|
||||
h.get_by_label("Display theme: Use system setting").click_secondary();
|
||||
h.run_steps(4);
|
||||
eprintln!(
|
||||
"DIAG preferences_theme_cards_and_use_system_setting_stay_in_sync: menu rows {:?}",
|
||||
h.query_all_by_role(Role::MenuItem).map(|n| n.label()).collect::<Vec<_>>()
|
||||
);
|
||||
h.get_by_label("Appearance settings…").click();
|
||||
h.run_steps(10);
|
||||
// A fresh install follows the OS (#1248), which is dark here.
|
||||
|
||||
Reference in new issue
Block a user