From e2796a8a30bfd37d9ce12a3608d8372d963f6295 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 21 Nov 2026 21:28:03 +0700 Subject: [PATCH] files-w2: net change of 1 commits - files-w2: written from its sheet --- crates/color-ui/src/ui/profile_prompts.rs | 69 +++++++++++++---- .../src/ui/profile_prompts/stories.rs | 22 ++++++ crates/color-ui/tests/it/profile_prompts.rs | 38 ++++++++++ crates/ui-panels/src/dialog/job_progress.rs | 76 ++++++++++++++----- crates/ui-panels/src/dialog/mod.rs | 2 +- crates/ui-panels/src/dialog/recovery.rs | 32 ++++++-- crates/ui-panels/src/dialog/stories.rs | 49 +++++++++++- crates/ui-panels/src/dialog/words.rs | 3 +- crates/ui-panels/tests/it/dialogs.rs | 55 +++++++++++++- 9 files changed, 301 insertions(+), 45 deletions(-) diff --git a/crates/color-ui/src/ui/profile_prompts.rs b/crates/color-ui/src/ui/profile_prompts.rs index d03dda727..992b48f7b 100644 --- a/crates/color-ui/src/ui/profile_prompts.rs +++ b/crates/color-ui/src/ui/profile_prompts.rs @@ -8,8 +8,9 @@ use craft_cms::ColorSpace; use craft_cms::profile::Profile; use craft_ui::choice::{Checkbox, Radio, RadioGroup}; -use craft_ui::contract::{Bind, Props as _, Show as _, ShowContainer as _}; +use craft_ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _}; use craft_ui::dialog::{DialogId, DialogResult, DialogStack, FieldRefusal, Prompt, StackDialog, dialog_id}; +use craft_ui::pickers::Select; use craft_ui::runtime::env::{Env, Label}; use craft_ui::runtime::words::CommonWords; use craft_ui::sections::{DialogRole, FooterButton}; @@ -221,6 +222,8 @@ pub struct ProfileMismatchDialog { action: ProfileAction, rememberable: bool, remember: bool, + profiles: Vec, + chosen: usize, open: bool, } @@ -239,6 +242,8 @@ impl ProfileMismatchDialog { action, rememberable: false, remember: false, + profiles: Vec::new(), + chosen: 0, open: true, } } @@ -253,9 +258,10 @@ impl ProfileMismatchDialog { /// The profiles the Assign profile `Select` lists under its radio row, a Missing Profile prompt only; it starts on /// the first name. #[must_use] - pub fn profiles(self, names: Vec) -> ProfileMismatchDialog { - let _ = names; - todo!("fl.F18") + pub fn profiles(mut self, names: Vec) -> ProfileMismatchDialog { + self.profiles = names; + self.chosen = 0; + self } /// Offers "Remember this choice"; only for a mismatch (ignored for a missing profile). @@ -265,14 +271,31 @@ impl ProfileMismatchDialog { self } + /// Whether Assign profile is offered: a missing profile and a list of profiles to assign. + fn offers_profile(&self) -> bool { + !self.profiles.is_empty() && matches!(self.question, ProfileQuestion::Missing { .. }) + } + /// The actions the question offers, in radio order. - fn offered(&self) -> &'static [ProfileAction] { + fn offered(&self) -> Vec { match self.question { - ProfileQuestion::Mismatch { .. } => &[ProfileAction::UseEmbedded, ProfileAction::ConvertToWorking, ProfileAction::Discard], - ProfileQuestion::Missing { .. } => &[ProfileAction::LeaveAsIs, ProfileAction::AssignWorking], + ProfileQuestion::Mismatch { .. } => vec![ProfileAction::UseEmbedded, ProfileAction::ConvertToWorking, ProfileAction::Discard], + ProfileQuestion::Missing { .. } => { + let mut offered = vec![ProfileAction::LeaveAsIs, ProfileAction::AssignWorking]; + if self.offers_profile() { + offered.push(ProfileAction::AssignProfile); + } + offered + } } } + /// The answer the dialog's state gives: the profile's name only for Assign profile. + fn answer(&self) -> ProfileAnswer { + let profile = if self.action == ProfileAction::AssignProfile { self.profiles.get(self.chosen).cloned() } else { None }; + ProfileAnswer { action: self.action, profile, remember: self.remember && self.can_remember() } + } + /// Whether "Remember this choice" shows: a mismatch the app made rememberable. fn can_remember(&self) -> bool { self.rememberable && matches!(self.question, ProfileQuestion::Mismatch { .. }) @@ -300,16 +323,16 @@ impl StackDialog for ProfileMismatchDialog { /// The chosen action, as OK gives it; `None` for an action the question does not offer. fn confirm(&mut self, _: &Context) -> Option { - self.offered().contains(&self.action).then(|| ProfileAnswer { - action: self.action, - profile: None, - remember: self.remember && self.can_remember(), - }) + self.offered().contains(&self.action).then(|| self.answer()) } - /// `action`, the chosen one of the question's actions, and `remember` while the box shows. + /// `action`, the chosen one of the question's actions, `profile` while Assign profile is offered, and `remember` + /// while the box shows. fn json_fields(&self) -> Option { let mut fields = json!({ "action": action_name(self.action) }); + if self.offers_profile() { + fields["profile"] = Value::String(self.profiles.get(self.chosen).cloned().unwrap_or_default()); + } if self.can_remember() { fields["remember"] = Value::Bool(self.remember); } @@ -323,6 +346,11 @@ impl StackDialog for ProfileMismatchDialog { let Some(picked) = picked else { return Err(FieldRefusal::Rejects(&value).message(field)) }; self.action = picked; } + "profile" if self.offers_profile() => { + let at = value.as_str().and_then(|name| self.profiles.iter().position(|profile| profile == name)); + let Some(at) = at else { return Err(FieldRefusal::Rejects(&value).message(field)) }; + self.chosen = at; + } "remember" if self.can_remember() => match value.as_bool() { Some(on) => self.remember = on, None => return Err(FieldRefusal::Rejects(&value).message(field)), @@ -335,8 +363,10 @@ impl StackDialog for ProfileMismatchDialog { fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option> { let env = Env::of(ui); let (words, common) = (env.words::(), env.words::()); - let (offered, can_remember) = (self.offered(), self.can_remember()); - let Self { file_name, mode, question, action, remember, open, .. } = self; + let (offered, can_remember, offers_profile) = (self.offered(), self.can_remember(), self.offers_profile()); + let entries: Vec> = + if offers_profile { self.profiles.iter().enumerate().map(|(at, name)| Entry::new(at, name.clone())).collect() } else { Vec::new() }; + let Self { file_name, mode, question, action, remember, chosen, open, .. } = self; let mode_word = mode.word(&words); let name = file_name.as_str(); let (title, message, embedded, working) = match &*question { @@ -365,10 +395,12 @@ impl StackDialog for ProfileMismatchDialog { }) .collect(); let group_label = title.clone(); + let select_label = words.assign_profile.clone(); let (remember_label, remember_tip) = (words.remember.clone(), words.remember_tip.clone()); let answers = [FooterButton::new(common.ok.clone(), DialogRole::Accept), FooterButton::new(common.cancel.clone(), DialogRole::Cancel)]; let held = &mut *action; let ticked = &mut *remember; + let picked_profile = &mut *chosen; let shown = Prompt::new(title, message) .answers(answers) .extras(move |ui| { @@ -377,6 +409,11 @@ impl StackDialog for ProfileMismatchDialog { Radio::new(value).label(text).show(ui); } }); + if offers_profile { + Select::new(select_label.clone(), Bind::bound(&mut *picked_profile), &entries) + .enabled(*held == ProfileAction::AssignProfile) + .show(ui); + } if can_remember { Checkbox::new(Bind::bound(&mut *ticked)).label(remember_label.clone()).tooltip(remember_tip.clone()).show(ui); } @@ -384,7 +421,7 @@ impl StackDialog for ProfileMismatchDialog { .opened(Bind::bound(open)) .show(ui); match shown.picked { - Some(0) => Some(DialogResult::Ok(ProfileAnswer { action: *action, profile: None, remember: *remember && can_remember })), + Some(0) => Some(DialogResult::Ok(self.answer())), Some(_) => Some(DialogResult::Cancel), None => None, } diff --git a/crates/color-ui/src/ui/profile_prompts/stories.rs b/crates/color-ui/src/ui/profile_prompts/stories.rs index 53733c357..2c5a186fb 100644 --- a/crates/color-ui/src/ui/profile_prompts/stories.rs +++ b/crates/color-ui/src/ui/profile_prompts/stories.rs @@ -1,6 +1,7 @@ //! Stories of the profile prompts. use super::{ProfileMismatchDialog, ProfileMode, ProfileQuestion}; +use craft_ui::dialog::stories::hosted; use craft_ui::dialog::{DialogStack, StackDialog as _}; use craft_ui::testing::{Drive, StoryData, StoryOutput, story}; use egui::Ui; @@ -18,6 +19,27 @@ fn profile_mismatch(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { shown(ui, ProfileMismatchDialog::new("photo.psd", ProfileMode::Rgb, question).rememberable(true)) } +/// A Missing Profile prompt for a scan that offers `names` to assign. +fn missing_with(names: &[&str]) -> ProfileMismatchDialog { + let question = ProfileQuestion::Missing { working: "sRGB IEC61966-2.1".into() }; + ProfileMismatchDialog::new("photo.psd", ProfileMode::Rgb, question).profiles(names.iter().map(|name| (*name).to_owned()).collect()) +} + +#[story(ProfileMismatchDialog, covers = [], drive = Drive::Never)] +fn profile_missing_with_profiles(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + hosted(ui, data, (), || missing_with(&["Adobe RGB (1998)", "Display P3", "ProPhoto RGB"])) +} + +#[story(ProfileMismatchDialog, covers = [], drive = Drive::Never)] +fn profile_missing_with_long_profile_names(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + hosted(ui, data, (), || { + missing_with(&[ + "Coated FOGRA39 (ISO 12647-2:2004) with a perceptual rendering intent and black point compensation", + "Japan Color 2001 Coated", + ]) + }) +} + #[story(ProfileMismatchDialog, covers = [], drive = Drive::Never)] fn profile_missing(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { let question = ProfileQuestion::Missing { working: "sRGB IEC61966-2.1".into() }; diff --git a/crates/color-ui/tests/it/profile_prompts.rs b/crates/color-ui/tests/it/profile_prompts.rs index 5a6741d2b..a57b0d9ba 100644 --- a/crates/color-ui/tests/it/profile_prompts.rs +++ b/crates/color-ui/tests/it/profile_prompts.rs @@ -11,6 +11,44 @@ fn fields(host: &DialogHost, id: DialogId) -> Value { host.open_dialogs().into_iter().find(|dialog| dialog.id == id).and_then(|dialog| dialog.fields).unwrap_or(Value::Null) } +/// The Assign profile list is offered with a profile list only; `profile` refuses a name not listed; OK answers the +/// name for Assign profile and none for another action. +#[trial] +fn assign_profile_answers_the_profile_chosen_in_its_list() { + let ctx = Context::default(); + let mut host = DialogHost::new(); + let names = || vec!["Dot Gain 20%".to_owned(), "Gray Gamma 2.2".to_owned()]; + let missing = || ProfileMismatchDialog::new("scan.tif", ProfileMode::Gray, ProfileQuestion::missing("Gray Gamma 2.2")); + + let id = host.open(missing()); + assert!(host.set_json_field(&ctx, id, "profile", json!("Dot Gain 20%")).is_err_and(|e| e.contains("unknown field")), "no list, no field"); + assert!(host.set_json_field(&ctx, id, "action", json!("assignProfile")).is_err(), "no list, no Assign profile"); + assert!(host.cancel_by_id(&ctx, id)); + host.take::(); + + let id = host.open(missing().profiles(names())); + assert_eq!(fields(&host, id), json!({"action": "leaveAsIs", "profile": "Dot Gain 20%"})); + assert!(host.set_json_field(&ctx, id, "profile", json!("Nope")).is_err_and(|e| e.contains("can't take"))); + assert_eq!(host.set_json_field(&ctx, id, "profile", json!("Gray Gamma 2.2")), Ok(())); + assert!(host.confirm_by_id(&ctx, id)); + let answer = host.take::().and_then(DialogResult::ok); + assert_eq!(answer.map(|answer| (answer.action, answer.profile)), Some((ProfileAction::LeaveAsIs, None))); + + let id = host.open(missing().profiles(names())); + assert_eq!(host.set_json_field(&ctx, id, "action", json!("assignProfile")), Ok(())); + assert_eq!(host.set_json_field(&ctx, id, "profile", json!("Gray Gamma 2.2")), Ok(())); + assert!(host.confirm_by_id(&ctx, id)); + let answer = host.take::().and_then(DialogResult::ok); + assert_eq!( + answer.map(|answer| (answer.action, answer.profile)), + Some((ProfileAction::AssignProfile, Some("Gray Gamma 2.2".to_owned()))) + ); + + let mismatch = ProfileMismatchDialog::new("poster.psd", ProfileMode::Rgb, ProfileQuestion::mismatch("Adobe RGB (1998)", "sRGB")).profiles(names()); + let id = host.open(mismatch); + assert_eq!(fields(&host, id), json!({"action": "useEmbedded"}), "a mismatch has no profile list"); +} + /// A mismatch takes its three actions and, only when rememberable, `remember`; a missing profile has no `discard`; /// OK answers the action and the box as set. // craft-color-ui has no craft-automation dev-dependency (color/Cargo.toml is dialogs-w6's), so the trial drives the diff --git a/crates/ui-panels/src/dialog/job_progress.rs b/crates/ui-panels/src/dialog/job_progress.rs index c20045456..fea56f94f 100644 --- a/crates/ui-panels/src/dialog/job_progress.rs +++ b/crates/ui-panels/src/dialog/job_progress.rs @@ -1,13 +1,21 @@ //! `JobProgress`: the modal window of a running job, a configuration of `Prompt` with a progress bar. -use crate::runtime::env::Label; +use super::prompt::{Prompt, Reply, buttons}; +use super::words::DialogWords; +use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _}; +use crate::display::{Progress, Text}; +use crate::layout_components::Row; +use crate::runtime::env::{Env, Label}; +use crate::runtime::words::CommonWords; +use crate::sections::DialogRole; +use crate::style::TypeRole; +use craft_theme::variant::Tone; use egui::{Response, Ui}; /// Modal progress window for a running job: a progress bar (or an indeterminate one), counts and the percentage, the /// queued line, and Cancel (and Hide, when `can_hide`). Escape and the close action give Cancel. -// P3(files-w2): fl.F12 `#[pattern(dialog)]` needs `StackDialog` (`dialog_probe`); plain `Pattern` registers it +// PLAN: `#[pattern(dialog)]` needs `StackDialog` (`dialog_probe`); the app draws this window directly, so it registers as a plain `Pattern` #[derive(crate::contract::Pattern)] -#[allow(dead_code)] // P3(files-w2): fl.F12 pub struct JobProgress { title: Label, step: Label, @@ -20,42 +28,72 @@ pub struct JobProgress { impl JobProgress { /// A progress window titled `title` showing the current `step`. pub fn new(title: impl Into