From 6e7c1d4e7cbdf58d15db53a33129f3e3a2f0cc84 Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 12:44:56 +0000 Subject: [PATCH] merge-fwe: FW16 E6: PathSetting, a Preferences path row over the settings draft (Browse through the host's file service, keys naming list entries); PathRow files host picks itself, PathField uses it --- crates/dialogs/src/ui/path_field.rs | 29 ++---- .../src/patterns/form_dialogs/path_row.rs | 47 +++++++-- .../patterns/preferences/document/draft.rs | 97 +++++++++++++++---- .../src/patterns/preferences/mod.rs | 4 + .../src/patterns/preferences/path_setting.rs | 89 +++++++++++++++++ .../preferences/path_setting/stories.rs | 25 +++++ .../ui-patterns/tests/it/preferences/mod.rs | 1 + .../tests/it/preferences/path_setting.rs | 74 ++++++++++++++ 8 files changed, 318 insertions(+), 48 deletions(-) create mode 100644 crates/ui-patterns/src/patterns/preferences/path_setting.rs create mode 100644 crates/ui-patterns/src/patterns/preferences/path_setting/stories.rs create mode 100644 crates/ui-patterns/tests/it/preferences/path_setting.rs diff --git a/crates/dialogs/src/ui/path_field.rs b/crates/dialogs/src/ui/path_field.rs index 3f8d25367..2df57c390 100644 --- a/crates/dialogs/src/ui/path_field.rs +++ b/crates/dialogs/src/ui/path_field.rs @@ -3,7 +3,7 @@ use craft_behavior::{EditEvent, Mixed}; use craft_host::target::Caps; use craft_host::{PickId, PickRequest}; -use craft_ui::contract::{Bind, Held, NoValue, Outcome, Remember as _, ShowContainer as _, Validity}; +use craft_ui::contract::{Bind, Held, NoValue, Outcome, Props as _, ShowContainer as _, Validity}; use craft_ui::form::Field; use craft_ui::patterns::form_dialogs::PathRow; use craft_ui::runtime::env::{Env, Label, Message}; @@ -17,10 +17,6 @@ craft_ui::words! { } } -/// The pick the field is waiting for, kept in the field's container while it is shown. -#[derive(Clone, Copy, Default)] -struct Ticket(Option); - /// What the path field reports. #[derive(Debug)] #[non_exhaustive] @@ -44,8 +40,8 @@ impl Outcome for PathFieldOutput { } /// A label, then the path row (a text field with the path and a Browse button) over the bound path. Typing commits on -/// Enter or focus loss; Browse queues `request` through `host.files()` and the answer fills the field on a later pass -/// (the field matches tickets, so several fields can browse in turn). Tab order: field, then Browse. With `must_exist` +/// Enter or focus loss; Browse queues `request` through `host.files()` ([`PathRow::pick`]) and the answer fills the +/// field on a later pass (rows match tickets, so several fields can browse in turn). Tab order: field, then Browse. With `must_exist` /// set, a path that does not exist shows the not-found message under the field. #[must_use = "show the field with `show`"] #[derive(craft_ui::contract::Pattern, craft_ui::contract::Props)] @@ -74,27 +70,14 @@ impl<'a> PathField<'a> { let mut browsing = None; let shown = Field::new(label.clone()).show(ui, |ui, cx| { let before = held.read(cx).unwrap_or_default(); - let host = cx.env.host().cloned(); let looks = must_exist && cx.env.shell().caps.contains(Caps::FILE_SYSTEM); let not_found = words.not_found.clone(); let check = move |path: &String| { if looks && path_is_missing(path) { Validity::Warn(Message::new(not_found.clone())) } else { Validity::Ok } }; - let mut answered = None; - if let Some(ticket) = cx.memory::().0 - && let Some(picked) = cx.take_pick_answer(ticket) - { - cx.memory::().0 = None; - answered = picked.first_path().map(|path| path.to_string_lossy().into_owned()); - } - let row = PathRow::new(label.clone(), Bind::given(before.clone()).check(check)).show(ui); - if row.browse - && let Some(host) = &host - { - let id = host.files().pick(request.clone()); - cx.memory::().0 = Some(id); - browsing = Some(id); - } + let row = PathRow::new(label.clone(), Bind::given(before.clone()).check(check)).pick(request.clone()).show(ui); + browsing = row.browsing; + let answered = row.picked; let typed = row .edit .into_iter() diff --git a/crates/ui-patterns/src/patterns/form_dialogs/path_row.rs b/crates/ui-patterns/src/patterns/form_dialogs/path_row.rs index faf7aac19..3ce657d83 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/path_row.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/path_row.rs @@ -4,11 +4,12 @@ mod stories; use crate::buttons::Button; -use crate::contract::{Bind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, Sizing, clicked}; +use crate::contract::{Bind, NoValue, Outcome, Props as _, Remember as _, Show as _, ShowContainer as _, Sizing, clicked}; use crate::layout_components::Row; use crate::runtime::env::{Env, Label}; use crate::text::TextField; use craft_behavior::EditEvents; +use craft_host::{PickId, PickRequest}; use egui::{Response, Ui}; craft_ui::words! { @@ -27,7 +28,13 @@ pub struct PathRowOutput { /// The text field's edits of the path in this pass; a given value is applied by the caller. pub edit: EditEvents, /// Browse was pressed this pass: the host asks for a path by its own route and writes the answer into the value. + /// With [`PathRow::pick`] the row has asked the host's file service itself. pub browse: bool, + /// With [`PathRow::pick`]: Browse filed this pick through the host's file service this pass. + pub browsing: Option, + /// With [`PathRow::pick`]: the path the host's file service answered, on the pass the answer arrived. The caller + /// writes it into the value as a set. + pub picked: Option, } impl Outcome for PathRowOutput { @@ -40,8 +47,10 @@ impl Outcome for PathRowOutput { /// A text field with the path, taking the row's room, and a Browse button after it, for a row whose enclosing `Field` /// shows the label. Typing edits the bound path; the binding's check shows under the field (a file that is not there). -/// A press on Browse is reported, and the host files its pick request: a `PathRequest` in a form dialog, or a pick from -/// the host's file service. Tab order: the field, then Browse. +/// A press on Browse is reported, and the host files its pick request: a `PathRequest` in a form dialog. With +/// [`pick`](Self::pick) the row files the pick through the host's file service itself, keeps the ticket while it is shown +/// and reports the answer in [`PathRowOutput::picked`] (rows match tickets, so several can browse in turn). Tab order: +/// the field, then Browse. #[must_use = "show the row with `show`"] #[derive(crate::contract::Pattern, crate::contract::Props)] pub struct PathRow<'a> { @@ -53,28 +62,52 @@ pub struct PathRow<'a> { /// Shown in the empty field. #[prop(into)] placeholder: Option