From 59d39a20494a1517a4fcf28ad185a4315a9ba95a Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Wed, 18 Nov 2026 22:43:21 +0000 Subject: [PATCH] fu-dialogs: app batch 1 rulings (S-L285, S-L289, S-L301, S-L310, S-L312) FormCx::accept files or closes as the OK press; FormButtons::Close leaves out OK; ListManager::name_box binds the name box; FindReplaceDialog::show_tab and set_go_to_kinds, and options() opens Search Options; ParagraphFormat::contextual_spacing. --- .../text/src/ui/character/paragraph_dialog.rs | 10 +++ crates/text/src/ui/character/stories.rs | 7 ++ crates/text/src/ui/find/dialog.rs | 20 ++++- crates/text/tests/it/find.rs | 36 +++++++- crates/text/tests/it/paragraph.rs | 27 +++++- crates/ui-panels/src/sections/footer.rs | 2 +- .../src/patterns/form_dialogs/form.rs | 79 +++++++++++++++-- .../src/patterns/form_dialogs/form/stories.rs | 64 +++++++++++++- .../src/patterns/form_dialogs/list_manager.rs | 84 ++++++++++++------- .../form_dialogs/list_manager/stories.rs | 30 +++++++ .../src/patterns/form_dialogs/mod.rs | 2 +- .../tests/it/form_dialogs/dialog.rs | 77 ++++++++++++++++- .../tests/it/form_dialogs/list_manager.rs | 32 ++++++- 13 files changed, 422 insertions(+), 48 deletions(-) diff --git a/crates/text/src/ui/character/paragraph_dialog.rs b/crates/text/src/ui/character/paragraph_dialog.rs index 13495dbdb..615540345 100644 --- a/crates/text/src/ui/character/paragraph_dialog.rs +++ b/crates/text/src/ui/character/paragraph_dialog.rs @@ -80,6 +80,7 @@ craft_ui::words! { left_to_right: "paragraphDialog.leftToRight" = "Left-to-right"; right_to_left: "paragraphDialog.rightToLeft" = "Right-to-left"; mirror_indents: "paragraphDialog.mirrorIndents" = "Mirror indents"; + contextual_spacing: "paragraphDialog.contextualSpacing" = "Don't add space between paragraphs of the same style"; inside: "paragraphDialog.inside" = "Inside"; outside: "paragraphDialog.outside" = "Outside"; exceptions: "paragraphDialog.exceptions" = "Formatting exceptions"; @@ -215,6 +216,10 @@ pub struct ParagraphFormat { /// Mirror indents: Left and Right read Inside and Outside when on. The outer `None` hides it; `Some(None)` is mixed. #[serde(default, skip_serializing_if = "Option::is_none", with = "shown_or_hidden")] pub mirror_indents: Option>, + /// Don't add space between paragraphs of the same style (Word's contextual spacing): the spacing before and after + /// is left out between two paragraphs of one style. The outer `None` hides it; `Some(None)` is mixed. + #[serde(default, skip_serializing_if = "Option::is_none", with = "shown_or_hidden")] + pub contextual_spacing: Option>, /// The Line and Page Breaks check boxes. `None` hides the page. pub breaks: Option, /// The Asian Typography check boxes. `None` hides the page. @@ -809,6 +814,11 @@ impl ParagraphDialog { } self.field(ui, scope, Row::At, &words.at, valid); + if let Some(current) = self.format.contextual_spacing + && let Some(on) = check(ui, &words.contextual_spacing, current) + { + self.format.contextual_spacing = Some(Some(on)); + } } fn answer(&self, open_tabs: bool) -> ParagraphAnswer { diff --git a/crates/text/src/ui/character/stories.rs b/crates/text/src/ui/character/stories.rs index 5e09df4e4..a12701147 100644 --- a/crates/text/src/ui/character/stories.rs +++ b/crates/text/src/ui/character/stories.rs @@ -146,6 +146,13 @@ fn indents_and_spacing(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { StoryOutput::default() } +/// Paragraphs that differ in "Don't add space between paragraphs of the same style": the box under the spacing rows is +/// mixed. +#[story(ParagraphDialog, covers = [], drive = Drive::Never)] +fn contextual_spacing_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + hosted(ui, data, (), || ParagraphDialog::new(ParagraphFormat { contextual_spacing: Some(None), ..indented() }).word(true)) +} + #[story(ParagraphDialog, covers = [], drive = Drive::Never)] fn line_and_page_breaks(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { hosted(ui, data, (), || ParagraphDialog::new(indented()).word(true).tab(ParagraphTab::LineAndPageBreaks)) diff --git a/crates/text/src/ui/find/dialog.rs b/crates/text/src/ui/find/dialog.rs index 3055ce8cd..41d7a4f8f 100644 --- a/crates/text/src/ui/find/dialog.rs +++ b/crates/text/src/ui/find/dialog.rs @@ -271,13 +271,31 @@ impl FindReplaceDialog { self } - /// Sets the starting options for Match case, Whole words and the rest. + /// Sets the starting options for Match case, Whole words and the rest. An option that only Search Options shows + /// (Match prefix, Match suffix, Ignore punctuation, Ignore white-space, Regular expressions) opens Search Options, + /// so an option that is on is never hidden. #[must_use] pub fn options(mut self, options: FindOptions) -> Self { self.options = options; + self.more |= options.prefix || options.suffix || options.ignore_punctuation || options.ignore_space || options.regex; self } + /// Shows `tab` in the open dialog, and puts `query` in Find what when given (Find or Replace asked again with a + /// selection). Replace with, the options, Search Options and the Go To target stay as they are. + pub fn show_tab(&mut self, tab: FindTab, query: Option) { + self.tab = tab; + if let Some(query) = query { + self.query = query; + } + } + + /// Replaces Go To's kinds in the open dialog (the document's bookmarks changed, say); the chosen kind and target + /// stay. + pub fn set_go_to_kinds(&mut self, kinds: Vec) { + self.go_to_kinds = kinds; + } + /// Go To's kinds (Page, Section, Line, Bookmark, Comment, …), the app's. #[must_use] pub fn go_to_kinds(mut self, kinds: Vec) -> Self { diff --git a/crates/text/tests/it/find.rs b/crates/text/tests/it/find.rs index 33749ba00..0ef2a36fc 100644 --- a/crates/text/tests/it/find.rs +++ b/crates/text/tests/it/find.rs @@ -1,5 +1,6 @@ -//! Go To in Find and Replace: the requests the app glue answers. +//! Go To in Find and Replace: the requests the app glue answers; the dialog asked for again while open. +use craft_text::find::FindOptions; use craft_text::ui::find::{FindReplaceDialog, FindRequest, FindTab, GoToKind}; use craft_ui::dialog::{DialogStack, StackDialog as _}; use craft_ui::runtime::access::Role; @@ -61,3 +62,36 @@ fn go_to_steps_on_an_empty_page_and_names_a_bookmark() { fixture.click(&go).idle(4); assert_eq!(dialog.borrow_mut().take_request(), None, "Go To is disabled without names"); } + +// Find and Replace asked for again while open: `show_tab` switches the tab and puts a given Find what in, keeping +// Replace with, the options and Search Options; `set_go_to_kinds` replaces the open dialog's kinds. An option only +// Search Options shows opens it from the start. +#[trial] +fn a_reopened_find_switches_its_tab_and_keeps_what_the_user_set() { + let options = FindOptions { regex: true, ..FindOptions::default() }; + let dialog = Rc::new(RefCell::new(FindReplaceDialog::new("cat", FindTab::Replace).word(true).options(options))); + let shown = dialog.clone(); + let mut fixture = Fixture::new(move |ui| { + let _ = shown.borrow_mut().show(ui, &DialogStack::default()); + }); + fixture.idle(30); + assert!(fixture.by_label("Regular expressions").is_some(), "an option only Search Options shows opens Search Options"); + let with = fixture.by_role(Role::TEXT_INPUT).get(1).copied().expect("the Replace with field"); + fixture.click(&with).type_text("dog").idle(4); + + dialog.borrow_mut().show_tab(FindTab::Find, Some("bird".to_owned())); + fixture.idle(4); + let fields = dialog.borrow().json_fields().expect("the dialog's fields"); + assert_eq!(fields["tab"], "find", "the tab switches"); + assert_eq!(fields["query"], "bird", "a given query replaces Find what"); + assert_eq!(fields["with"], "dog", "Replace with stays"); + assert_eq!(fields["regex"], true, "the options stay"); + assert_eq!(fields["more"], true, "Search Options stays open"); + + dialog.borrow_mut().show_tab(FindTab::GoTo, None); + dialog.borrow_mut().set_go_to_kinds(vec![GoToKind::named("Bookmark", vec!["Intro".to_owned()], "No bookmarks")]); + fixture.idle(10); + let fields = dialog.borrow().json_fields().expect("the dialog's fields"); + assert_eq!(fields["query"], "bird", "without a query Find what stays"); + assert_eq!(fields["goToTarget"], "Intro", "the new kinds show: the target names the new bookmark"); +} diff --git a/crates/text/tests/it/paragraph.rs b/crates/text/tests/it/paragraph.rs index 0e7006d75..d41390346 100644 --- a/crates/text/tests/it/paragraph.rs +++ b/crates/text/tests/it/paragraph.rs @@ -1,4 +1,5 @@ -//! The Word Paragraph dialog's pages: a check box whose paragraphs differ stays mixed across page switches until clicked. +//! The Word Paragraph dialog's pages: a check box whose paragraphs differ stays mixed across page switches until clicked; +//! the contextual spacing box. use craft_behavior::Mixed; use craft_text::ui::character::{AsianTypography, LineBreakOptions, ParagraphDialog, ParagraphFormat, ParagraphTab}; @@ -44,3 +45,27 @@ fn word_paragraph_tabs_leave_mixed_boxes_unset_until_clicked() { assert_eq!(breaks.widow_control, None, "a box left alone stays unset"); assert_eq!(answer.format.asian.expect("the page is answered").kinsoku, None); } + +/// "Don't add space between paragraphs of the same style" under the spacing rows: shown mixed for paragraphs that +/// differ, a click turns it on, and the answer carries it. +#[trial] +fn a_mixed_contextual_spacing_box_clicked_is_on_in_the_answer() { + const LABEL: &str = "Don't add space between paragraphs of the same style"; + let mut format = ParagraphFormat::default(); + format.contextual_spacing = Some(None); + let dialog = Rc::new(RefCell::new(ParagraphDialog::new(format).word(true).held_ok())); + let shown = dialog.clone(); + let mut fixture = Fixture::new(move |ui| { + let _ = shown.borrow_mut().show(ui, &DialogStack::default()); + }); + fixture.idle(30); + assert!(matches!(toggled(&fixture, LABEL), Some(Mixed::Mixed)), "paragraphs that differ show the box mixed"); + let boxed = fixture.by_label(LABEL).expect("the box is shown"); + fixture.click(&boxed).idle(4); + assert!(matches!(toggled(&fixture, LABEL), Some(Mixed::Same(true))), "a click turns the mixed box on"); + + let ok = fixture.by_label("OK").expect("OK is shown"); + fixture.click(&ok).idle(4); + let answer = dialog.borrow_mut().take_ok().expect("OK filed its answer"); + assert_eq!(answer.format.contextual_spacing, Some(Some(true)), "the answer carries the box"); +} diff --git a/crates/ui-panels/src/sections/footer.rs b/crates/ui-panels/src/sections/footer.rs index 0272497f7..49737cddb 100644 --- a/crates/ui-panels/src/sections/footer.rs +++ b/crates/ui-panels/src/sections/footer.rs @@ -484,7 +484,7 @@ impl FooterButton { } /// Whether the button can be activated. - pub(crate) const fn is_enabled(&self) -> bool { + pub const fn is_enabled(&self) -> bool { self.enabled } } diff --git a/crates/ui-patterns/src/patterns/form_dialogs/form.rs b/crates/ui-patterns/src/patterns/form_dialogs/form.rs index dd448537c..c8a6887a4 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/form.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/form.rs @@ -37,9 +37,24 @@ craft_ui::words! { /// The words a form dialog adds beside the common OK and Cancel. pub struct FormDialogWords { preview: "formDialog.preview" = "Preview"; + /// The one closing button of a form without OK ([`FormButtons::Close`]). + close: "formDialog.close" = "Close"; } } +/// The buttons a form dialog's footer starts with, before its [extra buttons](FormDialog::extra_buttons). +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub enum FormButtons { + /// OK and Cancel (Reset while Alt is held). + #[default] + OkCancel, + /// No OK: one button with `DialogRole::Cancel`, labelled by [`cancel_label`](FormDialog::cancel_label) or Close. + /// The work is in the extra buttons, whose [`FormOutput::picked`] indexes still start at 2. Enter picks the one + /// enabled extra button with `DialogRole::Accept` when there is one, and does nothing otherwise. Nothing is filed + /// as a held OK, and [`FormCx::accept`] does nothing. + Close, +} + /// The dialog's own undo history of its value while it is open: made on the opening pass, stepped by Undo and Redo. #[derive(Clone)] struct History(Option>); @@ -85,6 +100,7 @@ pub struct FormCx<'a, 'b> { first: bool, answers: Vec, requests: &'a mut HostRequests, + accept: bool, } impl FormCx<'_, '_> { @@ -102,6 +118,16 @@ impl FormCx<'_, '_> { pub fn requests(&mut self) -> &mut HostRequests { self.requests } + + /// The body's activation is the OK press: a double click or Enter on a grid cell, say. After the body, the dialog + /// takes it as a press of OK while the values can be accepted. Under [`held`](FormDialog::held) it files the values + /// and stays open for the app's answer (nothing while an answer is out); with + /// [`accept_stays_open`](FormDialog::accept_stays_open) it reports the pick and stays open; otherwise it closes as + /// `CloseReason::Activated` with the value. A measuring run and a form without OK ([`FormButtons::Close`]) take + /// none. + pub fn accept(&mut self) { + self.accept = true; + } } impl<'b> Deref for FormCx<'_, 'b> { @@ -127,7 +153,8 @@ pub struct FormOutput { /// How the dialog closed in this pass; `None` while it stays open. pub closed: Option, /// The index of the footer button picked in this pass, in the order `ResetFooter::buttons` gives them, then the - /// [`extra_buttons`](FormDialog::extra_buttons) from 2 on. + /// [`extra_buttons`](FormDialog::extra_buttons) from 2 on. A [`FormCx::accept`] that leaves the dialog open is + /// OK's pick, 0. Without OK ([`FormButtons::Close`]) Close is 1 and the extras keep their indexes. pub picked: Option, /// The value, the pass the dialog closed as OK while it could be accepted. pub accepted: Option, @@ -155,7 +182,10 @@ type ResetWithFn<'a, V> = Box V + 'a>; /// `V::default()` each time the dialog opens. /// - Keys: Enter is OK unless the body owns it or [`enter_confirms`](FormDialog::enter_confirms) is off, Escape cancels. Holding Alt turns Cancel into Reset, which restores /// the value from when the dialog opened (and runs [`on_reset`](FormDialog::on_reset) for what the body keeps). -/// - The body returns whether the value can be accepted; OK is enabled while it can and `ok_enabled` is true. +/// - The body returns whether the value can be accepted; OK is enabled while it can and `ok_enabled` is true. The +/// body's own activation (a double click on a cell) is OK through [`FormCx::accept`]. +/// - [`buttons`](FormDialog::buttons) with [`FormButtons::Close`] leaves out OK, for a form whose work is in its extra +/// buttons. /// - With [`history`](FormDialog::history), Cmd/Ctrl+Z and Shift+Cmd/Ctrl+Z step the dialog's own value; a drag or a /// typing run is one step. /// - The footer goes across the foot, the Preview check box and the footer controls at its start edge; with @@ -171,6 +201,7 @@ pub struct FormDialog<'a, V: Value + Default> { open: Option>, ok_label: Option