mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Address review: one group-name set for clashes, test the .grd prompt (#10640)
- free_group's brush check builds the set of group names once instead of scanning every preset for each numbered candidate. - reimporting_a_gradient_file_asks_before_touching_its_group covers the gradient branch of the prompt: no prompt for a new group, Cancel imports nothing, Import as New Group adds "Fire (2)", Replace swaps "Fire" alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
2ab2ab2f0d
commit
586563fc2b
2 files changed
+39
-2
No files matched your search
@@ -133,8 +133,9 @@ fn add_abr_presets(s: &mut Session, p: &Value, group: String, imp: photocraft_io
|
||||
s.tools.presets.retain(|x| x.builtin || x.group != group);
|
||||
group
|
||||
} else {
|
||||
let presets = &s.tools.presets;
|
||||
free_group(&group, |g| presets.iter().any(|x| x.group == g))
|
||||
// One pass over the library, not one per numbered candidate.
|
||||
let groups: std::collections::HashSet<&str> = s.tools.presets.iter().map(|x| x.group.as_str()).collect();
|
||||
free_group(&group, |g| groups.contains(g))
|
||||
};
|
||||
let mut taken = UniqueNames::new(s.tools.presets.iter().map(|x| x.name.as_str()));
|
||||
let mut names = Vec::with_capacity(imp.presets.len());
|
||||
|
||||
@@ -225,6 +225,42 @@ mod tests {
|
||||
assert!(prompt(&app).is_none());
|
||||
}
|
||||
|
||||
/// The same prompt guards a gradient group: `Fire.grd` again asks, Cancel imports nothing,
|
||||
/// Import as New Group adds "Fire (2)", Replace swaps "Fire" alone (#10640).
|
||||
#[test]
|
||||
fn reimporting_a_gradient_file_asks_before_touching_its_group() {
|
||||
use photocraft_psd::grd::{GrdColor, GrdGradient, GrdStop, write};
|
||||
let stop = |location: f32, color| GrdStop { location, midpoint: 0.5, color };
|
||||
let ember =
|
||||
GrdGradient { name: "Ember".into(), stops: vec![stop(0.0, GrdColor::Foreground), stop(1.0, GrdColor::Rgb([1.0, 0.0, 0.0]))], ..Default::default() };
|
||||
let grd = write(&[ember]);
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
let groups = |app: &PhotocraftApp, g: &str| app.session.presets.gradients.iter().filter(|x| x.name == g).count();
|
||||
let prompt = |app: &PhotocraftApp| app.ui.dialogs.iter().find(|d| crate::preset_group_prompt::owns(&d.fields)).map(|d| d.id);
|
||||
open(&mut app, "Fire.grd", &grd).unwrap().unwrap();
|
||||
assert_eq!(groups(&app, "Fire"), 1);
|
||||
assert!(prompt(&app).is_none(), "a new group imports without asking");
|
||||
|
||||
open(&mut app, "Fire.grd", &grd).unwrap().unwrap();
|
||||
let id = prompt(&app).expect("the prompt is open");
|
||||
crate::dialogs::cancel(&mut app, id).unwrap();
|
||||
assert_eq!((groups(&app, "Fire"), groups(&app, "Fire (2)")), (1, 0));
|
||||
|
||||
open(&mut app, "Fire.grd", &grd).unwrap().unwrap();
|
||||
let id = prompt(&app).expect("the prompt is open");
|
||||
crate::dialogs::confirm(&mut app, id).unwrap();
|
||||
assert_eq!((groups(&app, "Fire"), groups(&app, "Fire (2)")), (1, 1));
|
||||
assert!(app.ui.status.ends_with("from Fire into “Fire (2)”"), "{}", app.ui.status);
|
||||
|
||||
open(&mut app, "Fire.grd", &grd).unwrap().unwrap();
|
||||
let id = prompt(&app).expect("the prompt is open");
|
||||
if let Some(d) = app.ui.dialogs.iter_mut().find(|d| d.id == id) {
|
||||
d.fields.insert("choice".into(), json!("replace"));
|
||||
}
|
||||
crate::dialogs::confirm(&mut app, id).unwrap();
|
||||
assert_eq!((groups(&app, "Fire"), groups(&app, "Fire (2)"), groups(&app, "Fire (3)")), (1, 1, 0));
|
||||
}
|
||||
|
||||
/// Import Brushes… with a PNG: the image becomes the current brush's tip (TOOL-213-12).
|
||||
#[test]
|
||||
fn import_brushes_turns_an_image_into_a_brush_tip() {
|
||||
|
||||
Reference in new issue
Block a user