mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-24 19:31:51 +01:00
Merge branch 'lookfix/forms' into area/app-1
This commit is contained in:
commit
9bc2ebb153
10 files changed
+64
-27
No files matched your search
@@ -360,6 +360,7 @@ impl PdfCraftApp {
|
||||
script_messages_dropped: 0,
|
||||
script_shown: None,
|
||||
posted_notices: Vec::new(),
|
||||
last_edit_refusal: None,
|
||||
notices: craft::ui::notices::NoticeCenter::new(),
|
||||
progress_requests: Vec::new(),
|
||||
progress_cards: Default::default(),
|
||||
|
||||
@@ -180,7 +180,7 @@ pub(super) fn notices(
|
||||
None
|
||||
};
|
||||
let msg = if scripts_off {
|
||||
Some(("triangle-alert", Tone::Warn, crate::js_ui::scripts_off_notice(), true))
|
||||
Some(("triangle-alert", Tone::Info, crate::js_ui::scripts_off_notice(), true))
|
||||
} else if secured {
|
||||
// A secured form still says what it is, and keeps Highlight fields: the security
|
||||
// sentence follows the form's.
|
||||
@@ -202,15 +202,16 @@ pub(super) fn notices(
|
||||
// What each action returns, by the action's index; `None` is the field highlight toggle.
|
||||
let mut results: Vec<Option<Notice>> = Vec::new();
|
||||
let mut notice = bar(tone, icon, text).dismiss();
|
||||
// The stopped-scripts notice leads with the Console, then the field highlights.
|
||||
if scripts_off {
|
||||
notice = notice.action(NoticeAction::new(tl!("JavaScript Console").to_string()));
|
||||
results.push(Some(Notice::Console));
|
||||
}
|
||||
if fields {
|
||||
let label = if view.session.highlight_fields { tl!("Hide field highlights") } else { tl!("Highlight fields") };
|
||||
notice = notice.action(NoticeAction::new(label.to_string()));
|
||||
results.push(None);
|
||||
}
|
||||
if scripts_off {
|
||||
notice = notice.action(NoticeAction::new(tl!("JavaScript Console").to_string()));
|
||||
results.push(Some(Notice::Console));
|
||||
}
|
||||
if secured {
|
||||
notice = notice.action(NoticeAction::new(tl!("Security settings").to_string()));
|
||||
results.push(Some(Notice::Security));
|
||||
|
||||
@@ -22,7 +22,7 @@ pub(crate) fn open(app: &mut PdfCraftApp, ctx: &egui::Context, name: String) {
|
||||
fields.set(FIELD, name.clone());
|
||||
let line = crate::i18n::fmt(tl!("Duplicate \"{name}\" onto:"), &[("name", &name)]);
|
||||
let dialog = HostedParamDialog::new(ctx, "form.duplicate_field", fields, move |fields| {
|
||||
let rows = vec![PageRangeOptions::param("pages", "", count, current, PageRangeChoices::Acrobat)];
|
||||
let rows = vec![PageRangeOptions::param("pages", "", count, current, PageRangeChoices::FromTo)];
|
||||
ParamDialog::new("form.duplicate_field", tl!("Duplicate Field"), rows).title_note(line.clone()).values(Bind::bound(fields))
|
||||
});
|
||||
crate::dialogs::host::open(app, dialog);
|
||||
|
||||
@@ -314,7 +314,9 @@ impl PdfCraftApp {
|
||||
}
|
||||
}
|
||||
let message = if matches!(edit, Edit::MoveObjects { .. }) { crate::object_ui::move_error(&e) } else { e.to_string() };
|
||||
self.notify_fmt("{label} failed: {e}", &[("label", &crate::i18n::edit_label(&label)), ("e", &message)]);
|
||||
let text = crate::i18n::fmt(tl!("{label} failed: {e}"), &[("label", &crate::i18n::edit_label(&label)), ("e", &message)]);
|
||||
self.last_edit_refusal = Some(text.clone());
|
||||
self.notify(text);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,6 +473,8 @@ pub struct PdfCraftApp {
|
||||
pub(crate) script_shown: Option<js_ui::ScriptShown>,
|
||||
/// The notices posted since the last pass, which `notices::show` hands to the toast service.
|
||||
pub(crate) posted_notices: Vec<craft::ui::notices::PostedNotice>,
|
||||
/// The text of the last refused edit's notice, for a dialog that shows the refusal in place.
|
||||
pub(crate) last_edit_refusal: Option<String>,
|
||||
/// The notice center that posts them and shows the cards.
|
||||
pub(crate) notices: craft::ui::notices::NoticeCenter,
|
||||
/// The changes to progress cards made since the last pass, which `notices::show` applies in order.
|
||||
|
||||
@@ -414,10 +414,12 @@ fn apply(ctx: &egui::Context, app: &mut PdfCraftApp, draft: &Draft) -> Result<()
|
||||
return Ok(());
|
||||
}
|
||||
// `apply_edit` posts its own reason as a notice; the dialog's refusal is this fixed text.
|
||||
app.last_edit_refusal = None;
|
||||
if app.apply_edit(ctx, Edit::Batch { label: "Change field properties".into(), edits }) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(tl!("The field properties could not be changed.").to_owned().into())
|
||||
// The edit's own reason (a locked field says to unlock it), as the dialog shows it.
|
||||
Err(app.last_edit_refusal.take().map_or_else(|| tl!("The field properties could not be changed.").to_owned().into(), Label::from))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,9 +533,21 @@ fn body(ui: &mut Ui, d: &mut Draft, recent: &RecentColours, request: &mut Option
|
||||
match d.tab {
|
||||
Tab::General => {
|
||||
let c = &mut d.tooltip;
|
||||
row(ui, "Tooltip:", c, false, |ui, shown| {
|
||||
TextField::new(tl!("Tooltip").to_owned(), Bind::bound_mixed(shown)).show(ui);
|
||||
// A mixed tooltip shows the first field's text, editable, and says it is mixed.
|
||||
let was_mixed = c.mixed;
|
||||
let mut text = c.value.clone();
|
||||
row(ui, "Tooltip:", c, false, |ui, _| {
|
||||
ui.horizontal(|ui| {
|
||||
TextField::new(tl!("Tooltip").to_owned(), Bind::bound(&mut text)).show(ui);
|
||||
if was_mixed {
|
||||
Text::new(tl!("Mixed").to_owned()).show(ui);
|
||||
}
|
||||
});
|
||||
});
|
||||
if text != c.value {
|
||||
c.value = text;
|
||||
c.mixed = false;
|
||||
}
|
||||
yes_no(ui, "Read Only", &mut d.read_only);
|
||||
yes_no(ui, "Required", &mut d.required);
|
||||
yes_no(ui, "Locked", &mut d.locked);
|
||||
|
||||
@@ -11,7 +11,9 @@ use craft::ui::canvas_controls::SelectionOutline;
|
||||
use craft::ui::choice::{Radio, RadioGroup};
|
||||
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::dialog::{DialogId, DialogResult, DialogStack, StackDialog, dialog_id};
|
||||
use craft::ui::display::{Shade, Text};
|
||||
use craft::ui::form::{Field, FieldGroup, Help};
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::patterns::form_dialogs::FormDialog;
|
||||
use craft::ui::pickers::Select;
|
||||
use craft::ui::primitives::Draw;
|
||||
@@ -337,6 +339,7 @@ fn pick<T: Clone + PartialEq + std::fmt::Debug + Send + Sync + 'static>(
|
||||
/// The Link Appearance group.
|
||||
fn appearance(ui: &mut egui::Ui, d: &mut LinkDraft, request: &mut Option<ColorRequest>, recent: &RecentColours) {
|
||||
FieldGroup::new(tl!("Link Appearance").to_string()).show(ui, |ui, _| {
|
||||
Text::new(tl!("Link Appearance").to_uppercase()).shade(Shade::Muted).show(ui);
|
||||
let visible = [(true, tl!("Visible Rectangle").to_string()), (false, tl!("Invisible Rectangle").to_string())];
|
||||
if let Some(v) = pick(ui, tl!("Link Type").to_string(), d.style.visible, visible.to_vec()) {
|
||||
d.style.visible = v;
|
||||
@@ -385,6 +388,7 @@ fn appearance(ui: &mut egui::Ui, d: &mut LinkDraft, request: &mut Option<ColorRe
|
||||
/// The Link Action group.
|
||||
fn action(ui: &mut egui::Ui, d: &mut LinkDraft, pages: usize) {
|
||||
FieldGroup::new(tl!("Link Action").to_string()).show(ui, |ui, _| {
|
||||
Text::new(tl!("Link Action").to_uppercase()).shade(Shade::Muted).show(ui);
|
||||
if d.preserve_action {
|
||||
Field::new(tl!("Action").to_string())
|
||||
.help(Help::Text(tl!("The existing action will be preserved.").to_string().into()))
|
||||
@@ -403,14 +407,17 @@ fn action(ui: &mut egui::Ui, d: &mut LinkDraft, pages: usize) {
|
||||
});
|
||||
Radio::new(false).label(tl!("Go to a page view").to_string()).show(ui);
|
||||
Field::new(tl!("Page").to_string()).show(ui, |ui, _| {
|
||||
let page = NumberField::new(tl!("Page").to_string(), Bind::given(Some(d.target as f64)))
|
||||
.range(1.0..=pages.max(1) as f64)
|
||||
.step(1.0)
|
||||
.enabled(!web)
|
||||
.show(ui);
|
||||
if let Some(n) = page.edit.events.landed().cloned().flatten() {
|
||||
d.target = (n.round().max(1.0) as usize).min(pages.max(1));
|
||||
}
|
||||
Row::new().show(ui, |ui, _| {
|
||||
let page = NumberField::new(tl!("Page").to_string(), Bind::given(Some(d.target as f64)))
|
||||
.range(1.0..=pages.max(1) as f64)
|
||||
.step(1.0)
|
||||
.enabled(!web)
|
||||
.show(ui);
|
||||
if let Some(n) = page.edit.events.landed().cloned().flatten() {
|
||||
d.target = (n.round().max(1.0) as usize).min(pages.max(1));
|
||||
}
|
||||
Text::new(crate::i18n::fmt(tl!("of {pages}"), &[("pages", &pages.max(1).to_string())]).to_string()).shade(Shade::Muted).show(ui);
|
||||
});
|
||||
});
|
||||
// The destination's own zoom, past what the dialog offers, stays a choice.
|
||||
let mut zooms = ZOOMS.to_vec();
|
||||
|
||||
@@ -7,6 +7,7 @@ use craft::theme::Srgba;
|
||||
use craft::ui::buttons::Button;
|
||||
use craft::ui::choice::{Checkbox, Radio, RadioGroup};
|
||||
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::dialog::{PromptChoice, StandardPrompt};
|
||||
use craft::ui::display::{Shade, Text};
|
||||
use craft::ui::form::{Field, FieldGroup};
|
||||
@@ -186,7 +187,7 @@ pub(crate) fn open_pages(app: &mut PdfCraftApp, ctx: &egui::Context) {
|
||||
let range = PageRange { scope: PageScope::Current, ..PageRange::default() };
|
||||
let fields = DialogFields::from_pairs([("pages", PageRangeOptions::field_value(&range))]);
|
||||
let dialog = HostedParamDialog::new(ctx, "redact.pages", fields, move |fields| {
|
||||
let rows = vec![PageRangeOptions::param("pages", "", count, current, PageRangeChoices::Current)];
|
||||
let rows = vec![PageRangeOptions::param("pages", "", count, current, PageRangeChoices::CurrentFromTo)];
|
||||
ParamDialog::new("redact.pages", tl!("Mark Page Range"), rows).values(Bind::bound(fields))
|
||||
});
|
||||
crate::dialogs::host::open(app, dialog);
|
||||
@@ -321,9 +322,12 @@ pub(crate) fn show_hidden(app: &mut PdfCraftApp, ui: &mut Ui) {
|
||||
.show(ui, |ui, _, d: &mut HiddenDraft| {
|
||||
Text::new(tl!("Select the items to remove from this document.")).shade(Shade::Muted).show(ui);
|
||||
for (h, n, on) in d.found.iter_mut() {
|
||||
Checkbox::new(Bind::bound(on)).label(tl!(h.label())).enabled(*n > 0).show(ui);
|
||||
let count = if *n == 0 { tl!("None found").to_string() } else { n.to_string() };
|
||||
Text::new(count).shade(Shade::Muted).show(ui);
|
||||
// The count stands beside its checkbox, on one row.
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Checkbox::new(Bind::bound(on)).label(tl!(h.label())).enabled(*n > 0).show(ui);
|
||||
let count = if *n == 0 { tl!("None found").to_string() } else { n.to_string() };
|
||||
Text::new(count).shade(Shade::Muted).show(ui);
|
||||
});
|
||||
}
|
||||
Text::new(tl!("Form fields are flattened: their values stay visible. Saving rewrites the whole file.")).shade(Shade::Muted).show(ui);
|
||||
true
|
||||
|
||||
@@ -8,9 +8,9 @@ use craft::docpath::names::{CopyNumbering, unique_file_name};
|
||||
use craft::host::queue::Priority;
|
||||
use craft::host::{Files, PickRequest, Picked, WriteIntent};
|
||||
use craft::ui::buttons::Button;
|
||||
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::contract::{Bind, Entry, Props as _, RowAlign, Show as _, ShowContainer as _};
|
||||
use craft::ui::dialog::{DialogId, DialogResult, DialogStack, StackDialog, dialog_id};
|
||||
use craft::ui::display::Text;
|
||||
use craft::ui::display::{Shade, Text};
|
||||
use craft::ui::form::{Field, FieldGroup};
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::patterns::form_dialogs::{FormDialog, ListManager, ListManagerAction, ListManagerChoice, ListManagerEntry, ListManagerWords};
|
||||
@@ -132,7 +132,9 @@ impl StackDialog for ActionEditorDialog {
|
||||
}
|
||||
let mut remove = None;
|
||||
for (i, s) in d.steps.iter_mut().enumerate() {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
let plain = s.arg_mut().is_none();
|
||||
let spread = if plain { RowAlign::SpaceBetween } else { RowAlign::Start };
|
||||
Row::new().fill_width().align(spread).show(ui, |ui, _| {
|
||||
let label = format!("{}. {}", i + 1, tl!(s.label()));
|
||||
Text::new(label.clone()).show(ui);
|
||||
if let Some(arg) = s.arg_mut() {
|
||||
@@ -160,6 +162,9 @@ impl StackDialog for ActionEditorDialog {
|
||||
}
|
||||
});
|
||||
});
|
||||
if taken {
|
||||
Text::new(tl!("An action with this name already exists.")).shade(Shade::Muted).show(ui);
|
||||
}
|
||||
true
|
||||
});
|
||||
match (shown.accepted, shown.closed) {
|
||||
|
||||
@@ -216,7 +216,8 @@ fn locked_field_refuses_the_entire_batch_and_keeps_the_draft_for_correction() {
|
||||
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");
|
||||
// The field shows the first field's own text (the tooltip is mixed), so typing adds to it.
|
||||
assert!(shared(&h)["tooltip"]["value"].as_str().is_some_and(|v| v.ends_with("Shared help")), "what was typed is kept");
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(4);
|
||||
assert!(!shared_open(&h));
|
||||
@@ -225,7 +226,7 @@ fn locked_field_refuses_the_entire_batch_and_keeps_the_draft_for_correction() {
|
||||
.form
|
||||
.iter()
|
||||
.filter(|f| ["alpha", "beta"].contains(&f.name.as_str()))
|
||||
.all(|f| !f.locked() && f.tooltip.as_deref() == Some("Shared help"))
|
||||
.all(|f| !f.locked() && f.tooltip.as_deref().is_some_and(|t| t.ends_with("Shared help")))
|
||||
);
|
||||
h.execute("edit.undo");
|
||||
h.run_steps(4);
|
||||
|
||||
Reference in new issue
Block a user