Merge cfix1/dialogs (comments re-exports: the union)

This commit is contained in:
Dylan M. Taylor
2026-11-18 16:29:22 -05:00
11 changed files with 130 additions and 91 deletions
+8 -11
View File
@@ -4,21 +4,20 @@
//! is a tabbed parameter dialog the app's dialog host shows; [`edited`] maps its values back to
//! the comment's properties.
use craft::host::{PickRequest, Picked};
use craft::theme::Srgba;
use craft::ui::contract::Bind;
use craft::ui::dialog::DialogId;
use craft::ui::dialog::DialogResult;
use craft::ui::patterns::form_dialogs::{
DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind, PropertiesDialog, PropertiesTab, PropertyRow, SharedRows,
};
use craft::ui::runtime::env::UnitKind;
use craft::ui::value_drag::SliderScale;
use craft::theme::Srgba;
use craft::host::{PickRequest, Picked};
use craft::ui::dialog::DialogResult;
use pdfcraft_engine::{BorderShape, CommentProps, Edit, LineEnding, NoteIcon};
use crate::PdfCraftApp;
use crate::colour_picker::PickerHost;
// PLAN: assumed `crate::comments::{palette, fill_choice, border_choice, RecentColours}` re-exported (pdf-comments-w7)
use crate::comments::{RecentColours, border_choice, fill_choice, palette};
/// A comment colour as the dialog's field value.
@@ -194,7 +193,8 @@ fn colour_row(key: &'static str, label: &'static str, optional: Optional, recent
pick.request
}
Optional::Border | Optional::Fill => {
let shown = if optional == Optional::Border { border_choice(ui, current, key, &recent) } else { fill_choice(ui, current, key, &recent) };
let shown =
if optional == Optional::Border { border_choice(ui, current, key, &recent) } else { fill_choice(ui, current, key, &recent) };
if let Some(choice) = shown.choice {
set_optional(fields, key, choice);
}
@@ -287,15 +287,12 @@ fn comment_props_dialog<'b>(
}
for i in 0..o.endings.as_ref().map_or(0, Vec::len) {
let options = LineEnding::ALL.into_iter().map(|l| (l.name().to_string(), ending_label(l).into())).collect();
let label = if i == 0 {
tl!("Line ending").to_string()
} else {
crate::i18n::fmt(tl!("Line ending {n}"), &[("n", &(i + 1).to_string())])
};
let label = if i == 0 { tl!("Line ending").to_string() } else { crate::i18n::fmt(tl!("Line ending {n}"), &[("n", &(i + 1).to_string())]) };
rows.push(PropertyRow::field(Param::new(ending_key(i), label, ParamKind::choice(options, None))));
}
let appearance = PropertiesTab::new(tl!("Appearance"), rows);
let appearance = if o.restylable { appearance } else { appearance.read_only(Some(tl!("This comment's appearance can't be changed yet.").into())) };
let appearance =
if o.restylable { appearance } else { appearance.read_only(Some(tl!("This comment's appearance can't be changed yet.").into())) };
let modified = o.modified.as_deref().map(pdfcraft_render::pretty_date).unwrap_or_else(|| "—".into());
let general = PropertiesTab::new(
+1 -8
View File
@@ -71,7 +71,7 @@ fn results(app: &mut PdfCraftApp, ctx: &egui::Context) {
app.create_stamp_pass(ctx);
app.summarize_pass();
crate::colour_picker::colour_picker_pass(app, ctx);
crate::colour_picker::colour_picker_pass(app);
// Forms.
if let Some(result) = app.dialogs.take::<SignaturePadDialog>() {
super::signature::finish(app, result);
@@ -79,12 +79,6 @@ fn results(app: &mut PdfCraftApp, ctx: &egui::Context) {
crate::prepare::dialog::finish(app);
crate::bulk_fields::finish(app);
crate::field_table_ui::pass(app, ctx);
// PLAN: assumed `fn redact_prompts_pass(app: &mut PdfCraftApp)` (pdf-forms-w13): takes the Apply redactions and
// Sanitize prompts by their instance ids and calls `finish_apply` / `finish_sanitize`.
crate::redact_ui::redact_prompts_pass(app);
// PLAN: assumed `fn lock_prompt_pass(app: &mut PdfCraftApp)` (pdf-forms-w6): takes the lock question by its
// instance id and calls `finish_lock`.
super::signature::lock_prompt_pass(app);
if let Some(fields) = param_ok(app, "redact.pages") {
crate::redact_ui::dialogs::finish_pages(app, &fields);
}
@@ -116,4 +110,3 @@ fn param_ok(app: &mut PdfCraftApp, key: &str) -> Option<DialogFields> {
let result = app.dialogs.take_by_id::<HostedParamDialog>(dialog_id(key))?;
result.ok().map(|r| r.fields)
}
+5 -15
View File
@@ -12,7 +12,7 @@ use craft::ui::runtime::env::Label;
use craft::ui::runtime::memory::SaveKey;
use pdfcraft_engine::{Edit, LabelStyle, PageOrientation, PageParity};
use crate::i18n::{fmt, tl};
use crate::i18n::fmt;
use crate::workflows::files::{ExtractOptions, PickTarget, SplitPlan, pages_to_extract, strip_pdf};
use crate::{PdfCraftApp, dialogs};
@@ -179,19 +179,12 @@ fn rotate_dialog<'b>(fields: &'b mut DialogFields, count: usize, current: usize)
"orientation",
tl!("Rotate:"),
ParamKind::choice(
options(&[
("both", tl!("Landscape and Portrait Pages")),
("landscape", tl!("Landscape Pages")),
("portrait", tl!("Portrait Pages")),
]),
options(&[("both", tl!("Landscape and Portrait Pages")), ("landscape", tl!("Landscape Pages")), ("portrait", tl!("Portrait Pages"))]),
Some("both".into()),
),
),
];
ParamDialog::new(ROTATE, tl!("Rotate Pages"), params)
.ok_enabled(valid)
.remember(SaveKey::new("pdfcraft.page_rotate"))
.values(Bind::bound(fields))
ParamDialog::new(ROTATE, tl!("Rotate Pages"), params).ok_enabled(valid).remember(SaveKey::new("pdfcraft.page_rotate")).values(Bind::bound(fields))
}
/// The label styles Number pages offers.
@@ -374,11 +367,8 @@ impl PdfCraftApp {
let opening = (pages.first().map_or(1, |p| p + 1), pages.last().map_or(1, |p| p + 1));
let target = self.pick_target(Some(id));
let source = Arc::new(ReplaceSource { name, bytes, src_pages, count, pages, opening, target });
let seeds = vec![
("from", FieldValue::from(opening.0 as i64)),
("to", FieldValue::from(opening.1 as i64)),
("src_from", FieldValue::from(1i64)),
];
let seeds =
vec![("from", FieldValue::from(opening.0 as i64)), ("to", FieldValue::from(opening.1 as i64)), ("src_from", FieldValue::from(1i64))];
self.replace_source = Some(source.clone());
self.open_page_dialog(ctx, REPLACE, seeds, move |fields| source.dialog(fields));
}
+10 -13
View File
@@ -71,11 +71,7 @@ impl PinTools {
icon: g.icon,
hue: g.hue,
label: tl!(g.label).to_string(),
detail: g
.sections
.first()
.map(|s| s.items.iter().take(4).map(|i| tl!(i.label)).collect::<Vec<_>>().join(" • "))
.unwrap_or_default(),
detail: g.sections.first().map(|s| s.items.iter().take(4).map(|i| tl!(i.label)).collect::<Vec<_>>().join(" • ")).unwrap_or_default(),
})
.collect();
PinTools { id: dialog_id("pin-tool"), rows, query: String::new(), pinned, toggled: None }
@@ -89,8 +85,8 @@ impl StackDialog for PinTools {
self.id
}
fn key(&self) -> Option<String> {
Some("pin-tool".to_owned())
fn key(&self) -> Option<&str> {
Some("pin-tool")
}
fn show(&mut self, ui: &mut Ui, _stack: &DialogStack) -> Option<DialogResult<()>> {
@@ -103,10 +99,12 @@ impl StackDialog for PinTools {
let texts = |i: &usize| {
rows.get(*i).map(|r| vec![Label::from(r.label.clone()), Label::from(r.detail.clone()), Label::from(r.id)]).unwrap_or_default()
};
List::<usize>::new(tl!("Tools")).select(SelectMode::Single).sizing(Sizing::Content).max_rows(8).filter(query.trim(), texts).show_items(
ui,
&Listed(rows),
&mut |key, _| {
List::<usize>::new(tl!("Tools"))
.select(SelectMode::Single)
.sizing(Sizing::Content)
.max_rows(8)
.filter(query.trim(), texts)
.show_items(ui, &Listed(rows), &mut |key, _| {
let Some(row) = rows.get(*key) else {
return ListRow::new("");
};
@@ -124,8 +122,7 @@ impl StackDialog for PinTools {
pressed.set(Some(at));
}
})
},
);
});
});
});
if let Some(at) = pressed.get() {
+36 -17
View File
@@ -6,8 +6,7 @@ use std::sync::{Arc, Mutex};
use craft::theme::color::{Rgba, Srgba};
use craft::theme::selection::MotionChoice;
use craft::theme::variant::Tone;
// PLAN: assumed `craft::theme_store::{selection::SelectionChange, ui::AppearancePage}` (theme-store L-10)
use craft::theme_store::selection::SelectionChange;
use craft::theme_store::SelectionChange;
use craft::theme_store::ui::AppearancePage;
use craft::ui::contract::{Bind, Entry, Props as _, SaveKey, Show as _};
use craft::ui::dialog::DialogHost;
@@ -18,7 +17,8 @@ use craft::ui::text::TextField;
use egui::Ui;
use crate::PdfCraftApp;
use crate::canvas::{Fit, PageLayout, ViewDefaults};
use crate::canvas::{Fit, PageDisplay, ViewDefaults};
use crate::colour_picker::PickerHost;
use crate::i18n::{self, Lang};
use crate::scroll_speed::ScrollSpeed;
use crate::state::Mode;
@@ -179,8 +179,7 @@ impl PdfCraftApp {
if let Some(request) = output.pick_color {
let answers = Arc::clone(answers);
let key = request.key.clone();
// PLAN: assumed `crate::comments::open_colour_picker(&mut DialogHost, ColorRequest, impl FnOnce(Srgba) + 'static)` (pdf-comments-w10, L-35, q180)
crate::comments::open_colour_picker(host, request, move |colour| {
self.open_colour_picker(PickerHost::Window(host), request, move |_, colour| {
if let Ok(mut queue) = answers.lock() {
queue.push((key, colour));
}
@@ -215,7 +214,9 @@ impl Texts {
String::new()
} else {
i18n::fmt(
tl!("{chars} can't be written into the PDF yet: Fill & Sign text is Western European only. Pick a numeric format such as dd.mm.yyyy."),
tl!(
"{chars} can't be written into the PDF yet: Fill & Sign text is Western European only. Pick a numeric format such as dd.mm.yyyy."
),
&[("chars", &bad)],
)
};
@@ -301,8 +302,8 @@ fn mode_table<'a>() -> Table<'a, Mode> {
]
}
fn layout_table<'a>() -> Table<'a, PageLayout> {
vec![(PageLayout::Single, "single", tl!("Single page")), (PageLayout::TwoUp, "two-up", tl!("Two-page view"))]
fn layout_table<'a>() -> Table<'a, PageDisplay> {
vec![(PageDisplay::Single, "single", tl!("Single page")), (PageDisplay::TwoUp, "two-up", tl!("Two-page view"))]
}
fn fit_table<'a>() -> Table<'a, Fit> {
@@ -459,7 +460,8 @@ impl PreferencesModel for Prefs<'_> {
let suite = self.app.suite_view();
let favorites = self.app.favorite_themes();
let system_dark = self.app.system_dark();
let shown = AppearancePage::new(&suite, Bind::bound(&mut *self.selection)).favorites(&favorites).text_size(false).system_dark(system_dark).show(ui);
let shown =
AppearancePage::new(&suite, Bind::bound(&mut *self.selection)).favorites(&favorites).text_size(false).system_dark(system_dark).show(ui);
if let Some(theme) = shown.favorite_toggled {
self.app.toggle_favorite_theme(theme);
}
@@ -611,7 +613,9 @@ impl Prefs<'_> {
let language = if Lang::from_code(&d.language).is_some() { d.language.as_str() } else { i18n::AUTO };
let mut scales = vec![Entry::new(AUTO_ID, t.auto_scale.as_str())];
scales.extend(t.scale_ids.iter().map(|(id, label)| Entry::new(id.as_str(), label.as_str())));
let scale = d.ui_scale.map_or(AUTO_ID, |f| t.scale_ids.iter().find(|(id, _)| id.parse::<u32>().is_ok_and(|p| p == ui_scale::percent(f))).map_or(AUTO_ID, |(id, _)| id.as_str()));
let scale = d.ui_scale.map_or(AUTO_ID, |f| {
t.scale_ids.iter().find(|(id, _)| id.parse::<u32>().is_ok_and(|p| p == ui_scale::percent(f))).map_or(AUTO_ID, |(id, _)| id.as_str())
});
let mut rows = vec![
RowSpec::new("general.language", tl!("Interface language"), RowKind::choice(language, languages)),
RowSpec::new("general.scale", tl!("Interface size"), RowKind::choice(scale, scales))
@@ -622,7 +626,11 @@ impl Prefs<'_> {
];
#[cfg(not(target_arch = "wasm32"))]
{
rows.push(RowSpec::new("general.reopen", tl!("Reopen the files that were open when PdfCraft last closed"), RowKind::Bool(d.reopen_last_session)));
rows.push(RowSpec::new(
"general.reopen",
tl!("Reopen the files that were open when PdfCraft last closed"),
RowKind::Bool(d.reopen_last_session),
));
rows.push(RowSpec::new(
"general.restore_view",
tl!("Restore the last view (page, zoom and page display) when a document is opened again"),
@@ -655,13 +663,16 @@ impl Prefs<'_> {
let mut modes: Vec<_> = presets.iter().map(|(id, label, _)| Entry::new(*id, *label)).collect();
modes.push(Entry::new("custom", tl!("Custom")));
let custom = mode == "custom";
let (text, background, only_black, line_art) = d.reading_colors.params.map_or(([0, 0, 0], [255, 255, 255], false, true), |p| (p.text, p.background, p.only_black, p.line_art));
let (text, background, only_black, line_art) =
d.reading_colors.params.map_or(([0, 0, 0], [255, 255, 255], false, true), |p| (p.text, p.background, p.only_black, p.line_art));
let reading = vec![
RowSpec::new("appearance.reading.mode", tl!("Reading colours"), RowKind::choice(mode, modes)),
RowSpec::new("appearance.reading.text", tl!("Text"), RowKind::Color(rgb(text))).enabled(custom),
RowSpec::new("appearance.reading.background", tl!("Page background"), RowKind::Color(rgb(background))).enabled(custom),
RowSpec::new("appearance.reading.only_black", tl!("Only change the colour of black text or line art"), RowKind::Bool(only_black)).enabled(custom),
RowSpec::new("appearance.reading.line_art", tl!("Change the colour of line art as well as text"), RowKind::Bool(line_art)).enabled(custom),
RowSpec::new("appearance.reading.only_black", tl!("Only change the colour of black text or line art"), RowKind::Bool(only_black))
.enabled(custom),
RowSpec::new("appearance.reading.line_art", tl!("Change the colour of line art as well as text"), RowKind::Bool(line_art))
.enabled(custom),
];
let display = vec![
RowSpec::new("appearance.edge_shadows", tl!("Show Page Edge Shadows"), RowKind::Bool(d.show_page_edge_shadows)),
@@ -701,7 +712,11 @@ impl Prefs<'_> {
let d = &*self.draft;
let rows = vec![
RowSpec::new("comment.author", tl!("Name on new comments"), RowKind::Text(d.author.as_str())),
RowSpec::new("comment.hide_hover", tl!("Hide hover previews for highlights without comment text"), RowKind::Bool(d.hide_empty_highlight_hover)),
RowSpec::new(
"comment.hide_hover",
tl!("Hide hover previews for highlights without comment text"),
RowKind::Bool(d.hide_empty_highlight_hover),
),
];
PageSpec::new("comment", tl!("Comment"), rows)
}
@@ -719,8 +734,12 @@ impl Prefs<'_> {
let rows = vec![
RowSpec::new("fill.flatten", tl!("Flatten Fill & Sign when saving"), RowKind::Bool(d.flatten_fill_sign_on_save))
.help(tl!("Text, marks and signatures become part of the page. Other comments stay editable.")),
RowSpec::new("fill.ask_lock", tl!("Otherwise, ask on the first save after a signature is placed"), RowKind::Bool(d.ask_to_lock_signatures))
.enabled(!d.flatten_fill_sign_on_save),
RowSpec::new(
"fill.ask_lock",
tl!("Otherwise, ask on the first save after a signature is placed"),
RowKind::Bool(d.ask_to_lock_signatures),
)
.enabled(!d.flatten_fill_sign_on_save),
RowSpec::new("fill.date_preset", tl!("Fill & Sign dates"), RowKind::choice(preset, presets)).keywords(tl!("Date format")),
RowSpec::new("fill.date_pattern", tl!("Pattern"), RowKind::Custom).keywords(tl!("Date format")).help(t.date_help.as_str()),
RowSpec::new("fill.date_language", tl!("Language"), RowKind::choice(language, languages)).keywords(tl!("Date format")),
+33 -4
View File
@@ -16,6 +16,12 @@ pub(crate) struct OpenPrompts {
pub(crate) link: Option<DialogId>,
/// The question about opening `pending_remote_link`.
pub(crate) remote_link: Option<DialogId>,
/// The Apply redactions question.
pub(crate) apply_redactions: Option<DialogId>,
/// The Sanitize question.
pub(crate) sanitize: Option<DialogId>,
/// The question about locking placed signatures into the page before a save (`pending_lock`).
pub(crate) lock_signatures: Option<DialogId>,
}
/// `name` cut to at most `max` characters by replacing its middle with "…", keeping the start and
@@ -92,10 +98,8 @@ impl PdfCraftApp {
if let Some(host) = pdfcraft_engine::links::display_host(&pending.url) {
prompt = prompt.paragraph(host.ascii.clone());
if host.mixed_scripts {
prompt = prompt.tone(
Tone::Bad,
tl!("This web address mixes letters from different alphabets, a common way to imitate another site's name."),
);
prompt = prompt
.tone(Tone::Bad, tl!("This web address mixes letters from different alphabets, a common way to imitate another site's name."));
} else if host.international {
prompt = prompt.tone(Tone::Warn, tl!("This web address uses letters from another alphabet, which can look like familiar ones."));
}
@@ -164,6 +168,31 @@ impl PdfCraftApp {
self.prompts.remote_link = None;
}
}
if let Some(dialog) = self.prompts.apply_redactions
&& let Some(go) = proceeded(self.dialogs.take_by_id::<StandardPrompt>(dialog))
{
self.prompts.apply_redactions = None;
if go {
crate::redact_ui::finish_apply(self);
}
}
if let Some(dialog) = self.prompts.sanitize
&& let Some(go) = proceeded(self.dialogs.take_by_id::<StandardPrompt>(dialog))
{
self.prompts.sanitize = None;
if go {
crate::redact_ui::finish_sanitize(self);
}
}
if let Some(dialog) = self.prompts.lock_signatures
&& let Some(result) = self.dialogs.take_by_id::<StandardPrompt>(dialog)
{
self.prompts.lock_signatures = None;
match result {
DialogResult::Ok(answer) => super::signature::finish_lock(self, answer),
DialogResult::Cancel => self.pending_lock = None,
}
}
if self.pending_link.is_some() && self.prompts.link.is_none() {
self.ask_link();
}
+5 -3
View File
@@ -19,18 +19,20 @@ pub(crate) struct ShortcutsSession {
/// The keys the document view handles itself, which no catalog command binds.
fn fixed_rows(ctx: &egui::Context) -> Vec<FixedRow> {
let key = |s| crate::commands::shortcut_label(ctx, s);
let mac = crate::commands::mac_shortcuts(ctx);
let key = |s: pdfcraft_engine::commands::Shortcut| s.label(mac);
let pair = |a, b| format!("{} / {}", key(a), key(b));
// Key names, translated where a catalog has them (not scanned as UI literals).
let named = |k: &str| tl!(k).to_string();
// Alt+← / Alt+→ (`canvas::shortcuts`): not a registered command, which has no Alt.
let alt_arrows = if crate::commands::mac_shortcuts(ctx) {
let alt_arrows = if mac {
"⌥← / ⌥→".to_owned()
} else {
let alt = crate::i18n::key_name("Alt");
format!("{alt}+← / {alt}+→")
};
let scroll = crate::i18n::fmt(tl!("Zoom in / out (also pinch or {key}-scroll)"), &[("key", crate::commands::command_modifier_label(ctx))]);
let scroll =
crate::i18n::fmt(tl!("Zoom in / out (also pinch or {key}-scroll)"), &[("key", pdfcraft_engine::commands::Shortcut::command_name(mac))]);
let first_last = format!("{} / {}, {}", crate::i18n::key_name("Home"), crate::i18n::key_name("End"), pair(FIRST_PAGE, LAST_PAGE));
let group = tl!("Document view");
// PLAN: `.chord(Trigger)` where a catalog binding could clash needs the engine `Shortcut` to `Trigger` conversion (pdf-chrome-w9's catalog)
+3 -3
View File
@@ -65,9 +65,9 @@ pub(crate) fn ask_lock(app: &mut PdfCraftApp, pending: PendingLock) {
.button(PromptChoice::Alternate, tl!("Keep editable").to_string())
.button(PromptChoice::Cancel, tl!("Cancel").to_string())
.dont_show_again()
.tag(id);
// PLAN: assumed `dialogs::host::open` as above (pdf-hub-w2).
crate::dialogs::host::open(app, prompt);
.tag(id)
.instance("lock-signatures");
app.prompts.lock_signatures = Some(crate::dialogs::host::open(app, prompt));
}
/// The lock question's answer. Lock and Keep editable save as asked, and the box remembers the choice; Cancel drops
+2 -6
View File
@@ -48,7 +48,7 @@ pub(crate) fn percent_id(p: f64) -> String {
format!("percent:{p}")
}
fn magnification_id(m: Magnification) -> String {
pub(crate) fn magnification_id(m: Magnification) -> String {
match (MAGNIFICATIONS.iter().find(|(_, named, _)| *named == m), m) {
(Some((id, ..)), _) => (*id).to_owned(),
(None, Magnification::Percent(p)) => percent_id(p),
@@ -71,11 +71,7 @@ pub(crate) fn description_key(key: &str) -> String {
/// The custom properties the `custom` field holds.
pub(crate) fn custom_pairs(fields: &DialogFields) -> Option<Vec<(String, String)>> {
let value = serde_json::to_value(fields.get("custom")?).ok()?;
value
.as_array()?
.iter()
.map(|entry| Some((entry.get("name")?.as_str()?.to_owned(), entry.get("value")?.as_str()?.to_owned())))
.collect()
value.as_array()?.iter().map(|entry| Some((entry.get("name")?.as_str()?.to_owned(), entry.get("value")?.as_str()?.to_owned()))).collect()
}
/// The `custom` field for `props`.
+2 -1
View File
@@ -41,7 +41,8 @@ pub(crate) use bridge::{
use bridge::hover_tip;
// PLAN: assumed colours exports (pdf-comments-w10): the colour pickers and buttons that `menu` exported before.
pub use colours::{fill_picker, recent_custom_colours, remember_custom_colour, status_badge, swatch_grid};
pub(crate) use colours::{RecentColours, border_colour_button, quick_bar_colour};
pub(crate) use colours::{RecentColours, border_choice, fill_choice, palette};
pub(crate) use colours::{border_colour_button, quick_bar_colour};
pub(crate) use composer::composer;
#[cfg(test)]
use composer::edited_in_view;
+25 -10
View File
@@ -107,7 +107,10 @@ fn props_rows(ui: &mut Ui, d: &mut RedactPrefs) {
}
Text::new(tl!("Shown while the pointer is over a mark.")).shade(Shade::Muted).show(ui);
Field::new(tl!("Opacity:")).show(ui, |ui, _| {
let field = NumberField::new(tl!("Opacity:"), Bind::given(Some(d.opacity * 100.0))).range(10.0..=100.0).commit_decimals(0).unit_kind(UnitKind::Percent);
let field = NumberField::new(tl!("Opacity:"), Bind::given(Some(d.opacity * 100.0)))
.range(10.0..=100.0)
.commit_decimals(0)
.unit_kind(UnitKind::Percent);
if let Some(Some(pct)) = field.show(ui).value().copied() {
d.opacity = (pct / 100.0).clamp(0.1, 1.0);
}
@@ -171,7 +174,10 @@ fn search_rows(ui: &mut Ui, d: &mut SearchDraft, import: &mut bool) {
FieldGroup::new(tl!("Find text and redact")).show(ui, |ui, _| {
RadioGroup::new(tl!("Search for"), Bind::bound(&mut d.mode)).show(ui, |ui, _| {
Radio::new(SearchMode::Phrase).label(tl!("Single word or phrase")).show(ui);
TextField::new(tl!("Text to find"), Bind::bound(&mut d.text)).placeholder(tl!("Text to find")).enabled(mode == SearchMode::Phrase).show(ui);
TextField::new(tl!("Text to find"), Bind::bound(&mut d.text))
.placeholder(tl!("Text to find"))
.enabled(mode == SearchMode::Phrase)
.show(ui);
Radio::new(SearchMode::Words).label(tl!("Multiple words or phrases")).show(ui);
TextField::new(tl!("Words or phrases to redact"), Bind::bound(&mut d.words))
.placeholder(tl!("One word or phrase per line"))
@@ -193,7 +199,11 @@ fn search_rows(ui: &mut Ui, d: &mut SearchDraft, import: &mut bool) {
Checkbox::new(Bind::bound(&mut d.case_sensitive)).label(tl!("Case-sensitive")).enabled(phrase_or_words).show(ui);
Text::new(tl!("Text in images isn't found; recognise text (OCR) first.")).shade(Shade::Muted).show(ui);
if let Some(n) = d.found {
let line = if n == 0 { tl!("No matches.").to_string() } else { crate::i18n::fmt(tl!("{n} match(es) marked for redaction."), &[("n", &n.to_string())]) };
let line = if n == 0 {
tl!("No matches.").to_string()
} else {
crate::i18n::fmt(tl!("{n} match(es) marked for redaction."), &[("n", &n.to_string())])
};
Text::new(line).show(ui);
}
});
@@ -230,32 +240,37 @@ pub(crate) fn show_search(app: &mut PdfCraftApp, ui: &mut Ui) {
}
}
/// Opens the Apply redactions prompt; the host routes a Proceed to `finish_apply`.
/// Opens the Apply redactions prompt; `prompts_pass` routes a Proceed to `finish_apply`.
pub(crate) fn open_apply(app: &mut PdfCraftApp) {
let marks = app.active_ids().and_then(|(_, id)| app.session.get(id)).map_or(0, |d| d.redaction_marks());
let message = if marks == 1 {
tl!("You are about to apply 1 redaction mark. Text, images and drawings under the marks, and comments and form fields that overlap them, are removed permanently.").to_string()
} else {
crate::i18n::fmt(tl!("You are about to apply {n} redaction marks. Text, images and drawings under the marks, and comments and form fields that overlap them, are removed permanently."), &[("n", &marks.to_string())])
crate::i18n::fmt(
tl!(
"You are about to apply {n} redaction marks. Text, images and drawings under the marks, and comments and form fields that overlap them, are removed permanently."
),
&[("n", &marks.to_string())],
)
};
let prompt = StandardPrompt::custom(message)
.title(tl!("Apply redactions"))
.paragraph(tl!("Save the document afterwards: saving rewrites the whole file so no trace of the removed content stays in it."))
.button(PromptChoice::Proceed, tl!("Apply"))
.button(PromptChoice::Cancel, tl!("Cancel"))
.tag("redact.apply");
crate::dialogs::host::open(app, prompt);
.instance("redact-apply");
app.prompts.apply_redactions = Some(crate::dialogs::host::open(app, prompt));
}
/// Opens the Sanitize prompt; the host routes a Proceed to `finish_sanitize`.
/// Opens the Sanitize prompt; `prompts_pass` routes a Proceed to `finish_sanitize`.
pub(crate) fn open_sanitize(app: &mut PdfCraftApp) {
let prompt = StandardPrompt::custom(tl!("Sanitizing removes hidden information from the document: metadata, file attachments, comments, form fields (flattened), hidden text and layers, bookmarks, links, actions and scripts, and private application data."))
.title(tl!("Sanitize document"))
.paragraph(tl!("Save the document afterwards; saving rewrites the whole file so nothing removed stays in it."))
.button(PromptChoice::Proceed, tl!("Sanitize"))
.button(PromptChoice::Cancel, tl!("Cancel"))
.tag("redact.sanitize");
crate::dialogs::host::open(app, prompt);
.instance("redact-sanitize");
app.prompts.sanitize = Some(crate::dialogs::host::open(app, prompt));
}
/// Remove hidden information while `app.hidden_draft` holds the categories found.