diff --git a/crates/ui-egui/src/dialogs/recolor.rs b/crates/ui-egui/src/dialogs/recolor.rs index e9c0760844..3768c182d2 100644 --- a/crates/ui-egui/src/dialogs/recolor.rs +++ b/crates/ui-egui/src/dialogs/recolor.rs @@ -1505,6 +1505,7 @@ impl Feed { /// What the pump works on with the app, out of the host: the values, their steps and what `show` /// asked for. struct Work { + opening: Arc<()>, fields: Fields, steps: Steps, filed: Filed, @@ -1544,7 +1545,7 @@ impl Work { randomize(app, &mut self.fields, sb); } if filed.library { - pick_library(app); + pick_library(app, Arc::clone(&self.opening)); } let d = &mut self.fields; if let Some(before) = filed.edited { @@ -1591,16 +1592,16 @@ fn randomize(app: &mut VectorcraftApp, d: &mut Fields, sb: bool) { /// Other Library…: import a library (.ase, .acb, .gpl, .vcswatches or a document's swatches) and /// limit to it. -fn pick_library(app: &mut VectorcraftApp) { +fn pick_library(app: &mut VectorcraftApp, opening: Arc<()>) { let request = builtin_open_filters().fold(PickRequest::open("library"), |request, (name, exts)| request.filter(name, exts)); - // PLAN: assumed `file_asks::Owner::Free` (fl.A3's owner of a continuation no document holds), as appearance-w19 codes it. - crate::file_asks::ask(app, request, crate::file_asks::Owner::Free, |app, picked| { + // A loaded library belongs to the session. The Limit to Library choice belongs to the opening that asked. + crate::file_asks::ask(app, request, crate::file_asks::Owner::Free, move |app, picked| { let Some(path) = picked.first_path() else { return Ok(Value::Null) }; let r = app.run("swatch.library.load", json!({ "path": path }))?; let library = r["library"].clone(); if let Some(dialogs) = app.dialogs() { dialogs.with(|host| { - if let Some(d) = host.get_mut::() { + if let Some(d) = host.get_mut_by_id::(dialog_id(KIND)).filter(|d| Arc::ptr_eq(&opening, &d.opening)) { d.fields.fields.insert("limitTo".into(), library); } }); @@ -1765,6 +1766,8 @@ fn confirm(app: &mut VectorcraftApp, fields: &Fields) -> Result<(), String> { /// commits the recolour. pub(crate) struct RecolorDialog { id: DialogId, + /// The identity of this opening, since Recolor Artwork reuses its dialog ID. + opening: Arc<()>, fields: Fields, steps: Steps, held: HeldAnswer, @@ -1787,6 +1790,7 @@ impl RecolorDialog { fn new(app: &VectorcraftApp, fields: Fields) -> Self { RecolorDialog { id: dialog_id(KIND), + opening: Arc::new(()), feed: Feed::of(app, &fields), steps: Steps::opened(snapshot(&fields)), fields, @@ -1803,6 +1807,7 @@ impl RecolorDialog { /// The values, steps and requests, for the pump to work on with the app. fn take_work(&mut self) -> Work { Work { + opening: Arc::clone(&self.opening), fields: std::mem::take(&mut self.fields), steps: std::mem::replace(&mut self.steps, Steps::opened(Snapshot::new())), filed: std::mem::take(&mut self.filed), diff --git a/crates/ui-egui/src/tests/recolor.rs b/crates/ui-egui/src/tests/recolor.rs index b56303f960..b4fa530205 100644 --- a/crates/ui-egui/src/tests/recolor.rs +++ b/crates/ui-egui/src/tests/recolor.rs @@ -447,6 +447,39 @@ fn a_gray_row_keeps_the_hsb_sliders_while_it_is_edited() { assert_eq!(field(&r, "sliderMode"), json!("hsb")); } +#[test] +fn other_library_picker_only_limits_the_recolor_opening_that_requested_it() { + let path = vectorcraft_testkit::temp_dir("recolor-other-library").join("Recolor Test.gpl"); + std::fs::write(&path, "GIMP Palette\nName: Recolor Test\n#\n12 34 56 Test Color\n").unwrap(); + let path = path.to_str().unwrap(); + for reopen in [true, false] { + let mut r = open(app(), json!({"colors": ["#123456"], "library": "document"})); + let picker = super::picks::scripted(&mut r.app()); + r.settled(); + tap(&mut r, "Other Library…"); + assert_eq!(picker.requests().len(), 1, "the dialog asked for a file"); + if reopen { + r.cancel(); + assert!(!r.is_open(), "the first opening closed while its answer was pending"); + r.app().run("ui.recolorDialog", json!({"colors": ["#abcdef"], "library": "document"})).unwrap(); + r.settled(); + } + assert_eq!(field(&r, "limitTo"), "document"); + + picker.answer(&[path]); + crate::file_asks::poll(&mut r.app()); + r.settled(); + let libraries = r.app().run("swatch.library.list", json!({})).unwrap(); + let imported = libraries["libraries"].as_array().unwrap().iter().find(|lib| lib["category"] == "loaded").expect("the library still loads"); + if reopen { + assert_eq!(field(&r, "limitTo"), "document", "the reopened dialog keeps its own Limit to Library choice"); + } else { + assert_eq!(field(&r, "limitTo"), imported["id"], "an answer for the current opening selects its library"); + } + r.cancel(); + } +} + /// With Limit to Library, a row whose new color is a spot color of the library shows Tint, whose T /// slider sets the row's tint of it; OK links the art to the spot color at that tint. #[test]