diff --git a/crates/develop/src/recipe.rs b/crates/develop/src/recipe.rs index c660c88247..f9ddeead92 100644 --- a/crates/develop/src/recipe.rs +++ b/crates/develop/src/recipe.rs @@ -176,6 +176,34 @@ pub fn generic_name(name: &str) -> bool { n.is_empty() || n == "Mask" || n.strip_prefix("Mask ").is_some_and(|d| !d.is_empty() && d.chars().all(|c| c.is_ascii_digit())) } +/// Whether `name` is `base` or `base` numbered ("Brush", "Brush 2"): an automatic name that +/// [`unique_name`] may have numbered. +pub fn numbered_name(name: &str, base: &str) -> bool { + name == base || name.strip_prefix(base).and_then(|r| r.strip_prefix(' ')).is_some_and(|d| !d.is_empty() && d.chars().all(|c| c.is_ascii_digit())) +} + +/// `base`, or `base` with the lowest number from 2 up that none of `taken` has ("Brush 2"), so +/// two masks of a photo never share an automatic name. +pub fn unique_name(base: &str, taken: &[&str]) -> String { + if !taken.contains(&base) { + return base.to_string(); + } + (2..=taken.len().saturating_add(2)).map(|n| format!("{base} {n}")).find(|c| !taken.contains(&c.as_str())).unwrap_or_else(|| base.to_string()) +} + +/// What a mask is made of: the kinds of its components in order, each once ("Radial Gradient, +/// Brush", "People - Eyes"); Copy Settings shows it next to each mask's name. +pub fn composition(m: &Mask) -> String { + let mut kinds: Vec = Vec::new(); + for c in &m.components { + let n = shape_name(&c.shape); + if !kinds.contains(&n) { + kinds.push(n); + } + } + kinds.join(", ") +} + /// A preset's name without a leading catalogue code and trailing filler ("P10 Sun Kissed" → "Sun /// Kissed", "P5 Enhance Portrait......" → "Enhance Portrait"). pub fn short_preset_name(name: &str) -> String { @@ -655,6 +683,34 @@ mod tests { assert_eq!(short_preset_name("2026"), "2026"); } + #[test] + fn automatic_names_are_numbered_only_where_they_would_repeat() { + assert_eq!(unique_name("Brush", &["Sky", "Subject"]), "Brush"); + assert_eq!(unique_name("Brush", &["Brush"]), "Brush 2"); + assert_eq!(unique_name("Brush", &["Brush", "Brush 2", "Brush 4"]), "Brush 3"); + assert_eq!(unique_name("", &[""]), " 2"); + assert!(numbered_name("Brush", "Brush") && numbered_name("Brush 12", "Brush")); + assert!(!numbered_name("Brush two", "Brush") && !numbered_name("Brush ", "Brush") && !numbered_name("Brushes", "Brush")); + assert!(!numbered_name("Sky", "Brush")); + let comp = |op, shape| MaskComponent { anchor: None, name: None, op, invert: false, shape }; + let radial = MaskShape::Radial { center: Point::new(0.5, 0.5), rx: 0.2, ry: 0.2, angle: 0.0, feather: 50.0, invert: false }; + let m = Mask { + components: vec![ + comp(MaskOp::Add, radial.clone()), + comp(MaskOp::Add, MaskShape::Brush { strokes: vec![] }), + comp(MaskOp::Subtract, radial), + ], + ..Default::default() + }; + assert_eq!(composition(&m), "Radial Gradient, Brush"); + let eyes = Mask { + components: vec![comp(MaskOp::Add, MaskShape::People { person: 0, parts: vec!["Eyes".into()], who: None, seg: None })], + ..Default::default() + }; + assert_eq!(composition(&eyes), "People - Eyes"); + assert_eq!(composition(&Mask::default()), ""); + } + #[test] fn who_and_anchor_serialize_plainly() { let w: Who = serde_json::from_value(serde_json::json!({"role": "Bride"})).unwrap(); diff --git a/crates/engine/src/cmd/develop.rs b/crates/engine/src/cmd/develop.rs index 692b7c1e3b..44347a42ee 100644 --- a/crates/engine/src/cmd/develop.rs +++ b/crates/engine/src/cmd/develop.rs @@ -106,6 +106,19 @@ fn pick_param(p: &Value, c: &str) -> Result> { Ok(Some(SettingsPick { groups: groups.unwrap_or_default(), settings }.normalized())) } +/// `masks` (Copy: which of the photo's masks, by id); `None` when not given. +fn mask_ids_param(p: &Value, c: &str) -> Result>> { + match p.get("masks") { + None | Some(Value::Null) => Ok(None), + Some(Value::Array(a)) => a + .iter() + .map(|v| v.as_u64().and_then(|n| u32::try_from(n).ok()).ok_or_else(|| bad(c, format!("invalid mask id `{v}` (develop.get: masks[].id)")))) + .collect::>>() + .map(Some), + Some(_) => Err(bad(c, "`masks` must be a list of mask ids (develop.get: masks[].id)")), + } +} + /// A preset group named like `name` (trimmed, any case) that exists already, else `name` trimmed: /// typing "wedding " never makes a second "Wedding" group. pub(crate) fn existing_preset_group(s: &Session, name: &str) -> String { @@ -1416,23 +1429,46 @@ pub fn specs() -> Vec { "Copy Edit Settings", ["Photo", "Develop Settings"], Some("Cmd+C"), - "{groups?: [settingsGroup], settings?: [settingItem] (single settings of a group, develop.settingItems)} (default: what was ticked last; at first all but crop, masks, remove): the choice is remembered → {groups, settings}", + "{groups?: [settingsGroup], settings?: [settingItem] (single settings of a group, develop.settingItems), masks?: [maskId] (with the masks group: only these of the photo's masks, by id (develop.get); default all)} (default: what was ticked last; at first all but crop, masks, remove): the group choice is remembered, the masks one is for this copy only → {groups, settings, masks? (the mask ids copied, when `masks` was given)}", has_active, |s, p| { let c = "develop.copy"; let id = active(s, c)?; - if let Some(pick) = pick_param(p, c)? + let pick = pick_param(p, c)?; + let only_masks = mask_ids_param(p, c)?; + let d = s.develop_of(id).unwrap_or_default(); + if let Some(only) = &only_masks { + if !pick.as_ref().unwrap_or(&s.dialogs.copy).has(SettingsGroup::Masks.id()) { + return Err(bad(c, "`masks` picks which masks to copy: add \"masks\" to `groups`")); + } + if let Some(unknown) = only.iter().find(|m| !d.masks.iter().any(|x| x.id == **m)) { + return Err(bad(c, format!("this photo has no mask {unknown} (develop.get: masks[].id)"))); + } + } + if let Some(pick) = pick && pick != s.dialogs.copy { s.dialogs.copy = pick; remember_dialogs(s); } - let d = s.develop_of(id).unwrap_or_default(); + let mut copied = s.dialogs.copy.extract(&d); + if let Some(only) = &only_masks + && let Some(masks) = copied.get_mut("masks").and_then(Value::as_array_mut) + { + // (in the photo's own order, whatever order they were named in) + masks.retain(|m| m.get("id").and_then(Value::as_u64).and_then(|v| u32::try_from(v).ok()).is_some_and(|mid| only.contains(&mid))); + } // portable: pasted in another catalog, a flat-field map still applies - let copied = s.dialogs.copy.extract(&d); s.clipboard = Some(s.portable(&copied)); s.clipboard_from = Some(id); - Ok(json!({"groups": s.dialogs.copy.groups, "settings": s.dialogs.copy.settings})) + let mut out = json!({"groups": s.dialogs.copy.groups, "settings": s.dialogs.copy.settings}); + if let Some(only) = only_masks + && let Some(o) = out.as_object_mut() + { + let ids: Vec = d.masks.iter().map(|m| m.id).filter(|mid| only.contains(mid)).collect(); + o.insert("masks".into(), json!(ids)); + } + Ok(out) } ), cmd!( @@ -1765,7 +1801,8 @@ pub fn specs() -> Vec { // photographer gave it ("Warmth") is kept for k in 0..d.masks.len() { let Some(m) = d.masks.get(k).cloned() else { continue }; - if s.auto_mask_name(id, &m) == m.name + // (numbered too: "Brush 2" next to another Brush) + if lcc_develop::recipe::numbered_name(&m.name, &s.auto_mask_name(id, &m)) && let Some(m) = d.masks.get_mut(k) { m.name.clear(); diff --git a/crates/engine/src/people_smart.rs b/crates/engine/src/people_smart.rs index 03dfc4c751..4b4d52b3f4 100644 --- a/crates/engine/src/people_smart.rs +++ b/crates/engine/src/people_smart.rs @@ -106,13 +106,30 @@ impl Session { } /// Give the masks of `after` that still carry an automatic name (a placeholder such as - /// "Mask 3", or the name they had automatically in `before`) the name of what they select now; - /// a name the photographer gave is kept. + /// "Mask 3", or the name they had automatically in `before`, numbered or not) the name of what + /// they select now; a name the photographer gave is kept. A name another mask of the photo + /// has already gets a number ("Brush 2", issue #1268); a mask whose name doesn't change keeps + /// it, so masks that shared a name before (imported ones too) keep theirs. pub(crate) fn refresh_mask_names(&mut self, id: PhotoId, before: &[lcc_develop::Mask], after: &mut [lcc_develop::Mask]) { - for m in after.iter_mut().filter(|m| !m.components.is_empty()) { + use lcc_develop::recipe::{generic_name, numbered_name, unique_name}; + for i in 0..after.len() { + let Some(m) = after.get(i).filter(|m| !m.components.is_empty()).cloned() else { continue }; let was = before.iter().find(|b| b.id == m.id).filter(|b| !b.components.is_empty()).map(|b| self.auto_mask_name(id, b)); - if lcc_develop::recipe::generic_name(&m.name) || was.as_deref() == Some(m.name.as_str()) { - m.name = self.auto_mask_name(id, m); + let placeholder = generic_name(&m.name); + if !placeholder && !was.as_deref().is_some_and(|w| numbered_name(&m.name, w)) { + continue; + } + let base = self.auto_mask_name(id, &m); + if !placeholder && was.as_deref() == Some(base.as_str()) { + // selects what it selected: its name (and number) stays + continue; + } + let name = { + let taken: Vec<&str> = after.iter().enumerate().filter(|(k, _)| *k != i).map(|(_, x)| x.name.as_str()).collect(); + unique_name(&base, &taken) + }; + if let Some(m) = after.get_mut(i) { + m.name = name; } } } diff --git a/crates/engine/src/tests_mask_links.rs b/crates/engine/src/tests_mask_links.rs index fc5cdd9f47..fbfecb02bf 100644 --- a/crates/engine/src/tests_mask_links.rs +++ b/crates/engine/src/tests_mask_links.rs @@ -391,3 +391,96 @@ fn the_selected_mask_follows_the_active_photo_to_its_linked_copy() { s.execute("library.select", &json!({"ids": [c.0]})).unwrap(); assert_eq!(s.active_mask, None, "a photo without it: none"); } + +/// Issue #1268: Copy can take some of the photo's masks (`masks`: their ids); Paste puts just +/// those on, in the photo's order and linked to their originals. Without `masks` every mask goes, +/// as before. A mask id the photo doesn't have, or a malformed list, is an error. +#[test] +fn copy_takes_a_subset_of_the_masks_and_paste_links_just_those() { + let (mut s, [a, b, c]) = photos::<3>(); + s.execute("library.select", &json!({"ids": [a.0]})).unwrap(); + s.execute("mask.add", &json!({"kind": "radial"})).unwrap(); + s.execute("mask.add", &json!({"kind": "linear", "start": [0.5, 0.0], "end": [0.5, 0.5]})).unwrap(); + s.execute("mask.add", &json!({"kind": "radial", "center": [0.2, 0.2]})).unwrap(); + let mine = masks(&s, a); + assert_eq!(mine.len(), 3); + let names: Vec<&str> = mine.iter().map(|m| m.name.as_str()).collect(); + assert_eq!(names, ["Radial Gradient", "Linear Gradient", "Radial Gradient 2"], "two radials don't share a name"); + let (first, third) = (mine[0].id, mine[2].id); + + // asked in reverse order: copied in the photo's order + let out = s.execute("develop.copy", &json!({"groups": ["masks"], "masks": [third, first]})).unwrap(); + assert_eq!(out["masks"], json!([first, third])); + select(&mut s, &[b, c], b); + s.execute("develop.paste", &json!({})).unwrap(); + for id in [b, c] { + let got = masks(&s, id); + let names: Vec<&str> = got.iter().map(|m| m.name.as_str()).collect(); + assert_eq!(names, ["Radial Gradient", "Radial Gradient 2"], "only the two picked, in order"); + } + let orig = masks(&s, a); + assert!(orig[1].link.is_empty(), "the mask left behind isn't linked"); + for (k, o) in [(0, &orig[0]), (1, &orig[2])] { + assert!(!o.link.is_empty()); + assert!([b, c].iter().all(|id| masks(&s, *id)[k].link == o.link), "each copy joins its own original"); + } + + // no `masks`: all of them, as before + s.execute("library.select", &json!({"ids": [a.0]})).unwrap(); + let out = s.execute("develop.copy", &json!({"groups": ["masks"]})).unwrap(); + assert!(out.get("masks").is_none()); + s.execute("library.select", &json!({"ids": [c.0]})).unwrap(); + s.execute("develop.paste", &json!({})).unwrap(); + assert_eq!(masks(&s, c).len(), 3); + + // an empty pick copies no mask + s.execute("library.select", &json!({"ids": [a.0]})).unwrap(); + s.execute("develop.copy", &json!({"groups": ["masks"], "masks": []})).unwrap(); + assert_eq!(s.clipboard.as_ref().and_then(|c| c.get("masks")).and_then(|m| m.as_array()).map(Vec::len), Some(0)); + + // hostile: errors, and the clipboard and the remembered choice stay as they were + let clip = s.clipboard.clone(); + let remembered = s.dialogs.copy.clone(); + for bad in [ + json!({"groups": ["masks"], "masks": [9999]}), + json!({"groups": ["masks"], "masks": [-1]}), + json!({"groups": ["masks"], "masks": ["one"]}), + json!({"groups": ["masks"], "masks": [u64::MAX]}), + json!({"groups": ["masks"], "masks": 3}), + json!({"groups": ["light"], "masks": [first]}), + ] { + assert!(s.execute("develop.copy", &bad).is_err(), "{bad}"); + } + assert_eq!(s.clipboard, clip); + assert_eq!(s.dialogs.copy, remembered); +} + +/// Issue #1268: a placeholder name the photographer gave ("Warmth") stays; an automatic name +/// that would repeat gets a number, and a numbered name keeps its number while the mask selects +/// the same; masks that already share a name keep it. +#[test] +fn automatic_mask_names_get_a_number_only_where_they_would_repeat() { + let (mut s, [a]) = photos::<1>(); + s.execute("library.select", &json!({"ids": [a.0]})).unwrap(); + s.execute("mask.add", &json!({"kind": "radial"})).unwrap(); + s.execute("mask.add", &json!({"kind": "radial", "name": "Warmth"})).unwrap(); + s.execute("mask.add", &json!({"kind": "radial"})).unwrap(); + let names = |s: &Session| masks(s, a).iter().map(|m| m.name.clone()).collect::>(); + assert_eq!(names(&s), ["Radial Gradient", "Warmth", "Radial Gradient 2"]); + // an edit that doesn't change what it selects keeps the number + let third = masks(&s, a)[2].id; + s.execute("mask.adjust", &json!({"id": third, "values": {"exposure": 0.5}})).unwrap(); + assert_eq!(names(&s)[2], "Radial Gradient 2"); + // a component of another kind: its new name, unique + s.execute("mask.addComponent", &json!({"id": third, "op": "add", "kind": "linear"})).unwrap(); + assert_eq!(names(&s)[2], "Radial Gradient + Linear Gradient"); + // masks that already shared a name (imported, or from before) keep it + let mut d = (*s.develop_of(a).unwrap()).clone(); + for m in &mut d.masks { + m.name = "Radial Gradient".into(); + } + s.set_develop(a, d, "test").unwrap(); + let first = masks(&s, a)[0].id; + s.execute("mask.adjust", &json!({"id": first, "values": {"exposure": 0.2}})).unwrap(); + assert!(names(&s).iter().all(|n| n == "Radial Gradient"), "{:?}", names(&s)); +} diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 1bf9e4c5c8..a867978b4e 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -2399,7 +2399,7 @@ pub fn run_ui_command(app: &mut LccApp, id: &str, p: &Value) -> Option { let groups = app.session.dialogs.copy.to_ids(); - app.ui.dialog = Some(Dialog::CopySettings { groups }); + app.ui.dialog = Some(Dialog::CopySettings { groups, masks_off: Vec::new() }); Ok(Value::Null) } "dialog.slideshowExport" => { diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs index a1833b4634..8e06fdd4d6 100644 --- a/crates/ui-egui/src/panels/dialogs.rs +++ b/crates/ui-egui/src/panels/dialogs.rs @@ -1041,8 +1041,10 @@ pub fn show(app: &mut LccApp, ctx: &egui::Context) { crate::widgets::named(r, crate::i18n::tr("Folder name")); }); } - Dialog::CopySettings { groups } => { - let _ = group_checklist(ui, "copyGroup", groups, None); + Dialog::CopySettings { groups, masks_off } => { + let rows = copy_mask_rows(&app.session); + let mask_rows = MaskRows { rows: &rows, off: masks_off }; + let _ = group_checklist_with(ui, "copyGroup", groups, None, Some(mask_rows)); } Dialog::SyncSettings { groups, controls } => { let n = app.session.selection.ids.len().saturating_sub(1); @@ -2399,7 +2401,10 @@ pub fn confirm_dialog(app: &mut LccApp, dlg: &Dialog) -> Result app.run("app.print", json!({})), Dialog::CropOverlays { picked } => app.run("view.cropOverlays", json!({"overlays": picked})), Dialog::BookPrefs { prefs } => app.run("book.preferences", json!(prefs)), - Dialog::CopySettings { groups } => app.run("develop.copy", pick_params(groups)), + Dialog::CopySettings { groups, masks_off } => { + let params = copy_params(&app.session, groups, masks_off); + app.run("develop.copy", params) + } Dialog::PasteSettings { groups } => app.run("develop.paste", pick_params(groups)), Dialog::SyncSettings { groups, .. } => app.run("develop.sync", pick_params(groups)), Dialog::SyncCopies { groups } => { @@ -3652,6 +3657,124 @@ pub(crate) fn export_settings(app: &mut LccApp, ui: &mut egui::Ui, f: ExportForm /// `:`, `:open:`, `:all`, `:none`. → `Some(true/false)` when /// Check All / Check None was pressed. fn group_checklist(ui: &mut egui::Ui, tag: &str, ids: &mut Vec, offered: Option<&SettingsPick>) -> Option { + group_checklist_with(ui, tag, ids, offered, None) +} + +/// The masks of the active photo under Masking in Copy Settings (issue #1268): a box per mask, its +/// name and what it is made of. `off` holds the masks left unticked while Masking is ticked. +struct MaskRows<'a> { + rows: &'a [(u32, String)], + off: &'a mut Vec, +} + +/// Each mask of the active photo with its row text: its name and what it is made of ("Mask 2: +/// Radial Gradient, Brush"); an automatic name that already says it is shown alone. +pub(crate) fn copy_mask_rows(session: &lcc_engine::Session) -> Vec<(u32, String)> { + let Some(d) = session.active().and_then(|id| session.develop_of(id)) else { return Vec::new() }; + d.masks + .iter() + .map(|m| { + let comp = lcc_develop::recipe::composition(m); + let name = m.name.trim(); + let text = if name.is_empty() { + lcc_develop::recipe::content_name(m) + } else if comp.is_empty() || lcc_develop::recipe::numbered_name(name, &lcc_develop::recipe::content_name(m)) || name == comp { + name.to_string() + } else { + format!("{name}: {comp}") + }; + (m.id, text) + }) + .collect() +} + +/// Copy Settings' parameters: the ticked settings, and the masks ticked when some are left out. +fn copy_params(session: &lcc_engine::Session, ids: &[String], masks_off: &[u32]) -> serde_json::Value { + let mut p = pick_params(ids); + let masks_ticked = SettingsPick::from_ids(ids).has(SettingsGroup::Masks.id()); + if masks_ticked && !masks_off.is_empty() { + let on: Vec = copy_mask_rows(session).iter().map(|(id, _)| *id).filter(|id| !masks_off.contains(id)).collect(); + if let Some(o) = p.as_object_mut() { + o.insert("masks".into(), json!(on)); + } + } + p +} + +/// The Masking group with a box per mask under it (opened with the arrow, as a group's single +/// settings). Widget ids: `:masks`, `:open:masks`, `:mask:`. +fn mask_group(ui: &mut egui::Ui, tag: &str, ids: &mut Vec, m: &mut MaskRows<'_>, t: &Tokens) { + let gid = SettingsGroup::Masks.id(); + let rows = m.rows; + // (a mask deleted since is forgotten; none ticked is Masking unticked) + m.off.retain(|x| rows.iter().any(|(id, _)| id == x)); + if m.off.len() >= rows.len() { + ids.retain(|x| x != gid); + m.off.clear(); + } + let copied = ids.iter().any(|x| x == gid); + let open_id = egui::Id::new(("settings-tree-open", tag, gid)); + let mut open = ui.data(|d| d.get_temp::(open_id)).unwrap_or(false); + ui.horizontal(|ui| { + ui.spacing_mut().item_spacing.x = 2.0; + let (rect, arrow) = ui.allocate_exact_size(egui::vec2(16.0, 16.0), egui::Sense::click()); + let colour = if arrow.hovered() { t.text } else { t.text_dim }; + let icon = if open { crate::icons::Icon::ChevronDown } else { crate::icons::Icon::ChevronRight }; + crate::icons::paint(ui.painter(), egui::Rect::from_center_size(rect.center(), egui::vec2(14.0, 14.0)), icon, colour); + let arrow = arrow.on_hover_text(crate::i18n::tr(if open { "Hide the single settings" } else { "Show the single settings" })); + crate::access::button(&arrow, if open { "Hide the single settings" } else { "Show the single settings" }); + crate::widgets::register(ui.ctx(), format!("{tag}:open:{gid}"), arrow.rect); + if arrow.clicked() { + open = !open; + ui.data_mut(|d| d.insert_temp(open_id, open)); + } + let mut on = copied && m.off.is_empty(); + let partial = copied && !m.off.is_empty(); + let r = ui.add(egui::Checkbox::new(&mut on, crate::i18n::tr(SettingsGroup::Masks.label())).indeterminate(partial)); + crate::widgets::register(ui.ctx(), format!("{tag}:{gid}"), r.rect); + if r.changed() { + // a partly ticked group ticks all of it, as the other groups do + let on = partial || on; + m.off.clear(); + ids.retain(|x| x != gid); + if on { + ids.push(gid.to_string()); + } + } + }); + if !open { + return; + } + for (mid, text) in rows { + ui.horizontal(|ui| { + ui.add_space(38.0); + let mut on = copied && !m.off.contains(mid); + let r = ui.checkbox(&mut on, text.as_str()); + crate::widgets::register(ui.ctx(), format!("{tag}:mask:{mid}"), r.rect); + if !r.changed() { + return; + } + if on && !ids.iter().any(|x| x == gid) { + // the first mask ticked: Masking with just this one + ids.push(gid.to_string()); + *m.off = rows.iter().map(|(id, _)| *id).filter(|id| id != mid).collect(); + } else if on { + m.off.retain(|x| x != mid); + } else if !m.off.contains(mid) { + m.off.push(*mid); + } + }); + } +} + +/// [`group_checklist`] with the masks of the photo under Masking (Copy Settings). +fn group_checklist_with( + ui: &mut egui::Ui, + tag: &str, + ids: &mut Vec, + offered: Option<&SettingsPick>, + mut masks: Option>, +) -> Option { // (ids from an older ui.json may name whole groups: one tick per setting from here on) let normal = SettingsPick::from_ids(ids).to_ids(); if normal != *ids { @@ -3675,6 +3798,14 @@ fn group_checklist(ui: &mut egui::Ui, tag: &str, ids: &mut Vec, offered: let half = SettingsGroup::ALL.len().div_ceil(2); for (i, g) in SettingsGroup::ALL.into_iter().enumerate() { let Some(ui) = cols.get_mut(usize::from(i >= half)) else { continue }; + if g == SettingsGroup::Masks + && can(g.id()) + && let Some(m) = masks.as_mut() + && !m.rows.is_empty() + { + mask_group(ui, tag, ids, m, &t); + continue; + } let mine: Vec<&str> = leaves(g).into_iter().filter(|id| can(id)).collect(); let ticked = mine.iter().filter(|id| ids.iter().any(|x| x == *id)).count(); let open_id = egui::Id::new(("settings-tree-open", tag, g.id())); @@ -3728,12 +3859,18 @@ fn group_checklist(ui: &mut egui::Ui, tag: &str, ids: &mut Vec, offered: crate::widgets::register(ui.ctx(), format!("{tag}:all"), all.rect); if all.clicked() { *ids = SettingsGroup::ALL.into_iter().flat_map(leaves).filter(|id| can(id)).map(str::to_string).collect(); + if let Some(m) = masks.as_mut() { + m.off.clear(); + } return Some(true); } let none = ui.small_button(crate::i18n::tr("Check None")); crate::widgets::register(ui.ctx(), format!("{tag}:none"), none.rect); if none.clicked() { ids.clear(); + if let Some(m) = masks.as_mut() { + m.off.clear(); + } return Some(false); } ui.label(egui::RichText::new(crate::i18n::tr("Open a group with its arrow to pick single settings.")).small().color(t.text_dim)); diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 5587e3968f..47c6d28763 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -2313,8 +2313,12 @@ pub enum Dialog { name: String, parent: Option, }, + /// `masks_off`: the active photo's masks left unticked under Masking (issue #1268; empty: all + /// of them, as before). CopySettings { groups: Vec, + #[serde(default)] + masks_off: Vec, }, /// Synchronize Settings (Lightroom Classic's Sync…): the groups the active photo's settings /// carry to the other selected photos, plus single Basic Tone controls when Light is unchecked. diff --git a/crates/ui-egui/src/tests_copy_paste_dialogs.rs b/crates/ui-egui/src/tests_copy_paste_dialogs.rs index 92df602b39..0a8e298bf2 100644 --- a/crates/ui-egui/src/tests_copy_paste_dialogs.rs +++ b/crates/ui-egui/src/tests_copy_paste_dialogs.rs @@ -107,3 +107,52 @@ fn the_left_bar_copies_pastes_and_opens_export() { assert_eq!(h.app.ui.module, crate::module::ModuleId::Export, "Export… opens the Export module"); assert!(h.app.ui.dialog.is_none(), "not the dialog: {:?}", h.app.ui.dialog); } + +/// Issue #1268: Copy Settings lists the photo's masks under Masking, each with its name and what +/// it is made of; ticking two of three copies just those two, and Check All copies all again. +#[test] +fn copy_settings_picks_single_masks() { + let (mut h, ids) = edited(); + exec(&mut h, "mask.add", json!({"kind": "radial"})); + exec(&mut h, "mask.addComponent", json!({"op": "add", "kind": "brush"})); + exec(&mut h, "mask.add", json!({"kind": "linear"})); + exec(&mut h, "mask.add", json!({"kind": "radial"})); + // (a mask from before automatic names keeps its placeholder) + let mut d = (*h.app.session.develop_of(PhotoId(ids[0])).unwrap()).clone(); + d.masks[2].name = "Mask 3".into(); + h.app.session.set_develop(PhotoId(ids[0]), d, "test").unwrap(); + let masks = h.app.session.develop_of(PhotoId(ids[0])).unwrap().masks.clone(); + let rows = crate::panels::dialogs::copy_mask_rows(&h.app.session); + let texts: Vec<&str> = rows.iter().map(|(_, t)| t.as_str()).collect(); + assert_eq!(texts, ["Radial Gradient + Brush", "Linear Gradient", "Mask 3: Radial Gradient"], "{masks:?}"); + + copy_dialog(&mut h); + click(&mut h, "copyGroup:none"); + click(&mut h, "copyGroup:open:masks"); + click(&mut h, &format!("copyGroup:mask:{}", masks[0].id)); + click(&mut h, &format!("copyGroup:mask:{}", masks[2].id)); + assert!( + matches!(&h.app.ui.dialog, Some(Dialog::CopySettings { groups, masks_off }) if groups == &["masks"] && masks_off == &[masks[1].id]), + "{:?}", + h.app.ui.dialog + ); + key(&mut h, json!({"key": "Enter"})); + assert!(h.app.ui.dialog.is_none()); + exec(&mut h, "library.select", json!({"ids": [ids[1]]})); + exec(&mut h, "develop.paste", json!({})); + let pasted: Vec = h.app.session.develop_of(PhotoId(ids[1])).unwrap().masks.iter().map(|m| m.name.clone()).collect(); + assert_eq!(pasted, [masks[0].name.clone(), masks[2].name.clone()]); + assert_eq!(exposure(&h, ids[1]), 0.0, "Check None left Light out"); + + // Check All: every mask again + exec(&mut h, "library.select", json!({"ids": [ids[0]]})); + copy_dialog(&mut h); + click(&mut h, "copyGroup:none"); + // (Masking stays open from before) + click(&mut h, &format!("copyGroup:mask:{}", masks[1].id)); + click(&mut h, "copyGroup:all"); + assert!(matches!(&h.app.ui.dialog, Some(Dialog::CopySettings { masks_off, .. }) if masks_off.is_empty()), "{:?}", h.app.ui.dialog); + key(&mut h, json!({"key": "Enter"})); + let copied = h.app.session.clipboard.as_ref().and_then(|c| c.get("masks")).and_then(Value::as_array).map(Vec::len); + assert_eq!(copied, Some(3)); +} diff --git a/crates/ui-egui/src/tests_dialogs.rs b/crates/ui-egui/src/tests_dialogs.rs index 1978f364bf..3f53059c20 100644 --- a/crates/ui-egui/src/tests_dialogs.rs +++ b/crates/ui-egui/src/tests_dialogs.rs @@ -143,7 +143,7 @@ fn modal_dialogs_close_menus_and_block_background_shortcuts_and_clicks() { assert_eq!(r["ok"], true, "{r}"); h.step(); let choices = h.app.ui.dialog.clone(); - assert!(matches!(&choices, Some(crate::state::Dialog::CopySettings { groups }) if groups.is_empty())); + assert!(matches!(&choices, Some(crate::state::Dialog::CopySettings { groups, .. }) if groups.is_empty())); let r = h.request("ui.clickWidget", json!({"id": "icon:copyGear"}), T); assert_eq!(r["ok"], true, "{r}"); h.step(); diff --git a/docs/changelog/unreleased/2026-11-18-copy-some-masks.md b/docs/changelog/unreleased/2026-11-18-copy-some-masks.md new file mode 100644 index 0000000000..df360cdffc --- /dev/null +++ b/docs/changelog/unreleased/2026-11-18-copy-some-masks.md @@ -0,0 +1,5 @@ +## Develop and masking + +- **Copy some of the masks:** Copy Settings lists each mask of the photo under Masking with its name and what it is + made of, so you copy only the masks you tick; the pasted masks stay linked. A new mask whose automatic name + another mask already has gets a number ("Brush 2"). `develop.copy` takes `masks` (mask ids). Issue #1268. diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index c336e9dad3..9cfd2f3284 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -378,7 +378,7 @@ under the UI command that wraps it (a no-op error); the UI command now wins. | Id | Feature | Tier | Status | Evidence | Missing / notes | |---|---|---|---|---|---| -| LR-MASK-PANEL | Masks panel | P0 | ✅ | `cmd:panel.masking`, `cmd:mask.add`, `cmd:mask.select`, `cmd:mask.rename`, `cmd:mask.duplicate` (`invert`), `cmd:mask.move`, `cmd:mask.visible`, `cmd:mask.delete`, `crates/ui-egui/src/panels/masking.rs` | list with per-mask show/hide eye and, on hover, a bin that deletes the mask (issue #642), double-click rename, right-click menu (duplicate, duplicate and invert, invert, hide, move up/down, rename, delete); fits any panel width (create tiles go to three columns, mask actions wrap, long component names are cut short); no drag-to-reorder; each mask and each of its parts shows a thumbnail (white on black over a small rendition of the photo, `crates/ui-egui/src/mask_thumbs.rs`, ported from OneSlips) | +| LR-MASK-PANEL | Masks panel | P0 | ✅ | `cmd:panel.masking`, `cmd:mask.add`, `cmd:mask.select`, `cmd:mask.rename`, `cmd:mask.duplicate` (`invert`), `cmd:mask.move`, `cmd:mask.visible`, `cmd:mask.delete`, `crates/ui-egui/src/panels/masking.rs` | list with per-mask show/hide eye and, on hover, a bin that deletes the mask (issue #642), double-click rename, right-click menu (duplicate, duplicate and invert, invert, hide, move up/down, rename, delete); fits any panel width (create tiles go to three columns, mask actions wrap, long component names are cut short); masks are named after what they select, and an automatic name another mask of the photo already has gets a number ("Brush 2", issue #1268; given and imported names stay as they are); no drag-to-reorder; each mask and each of its parts shows a thumbnail (white on black over a small rendition of the photo, `crates/ui-egui/src/mask_thumbs.rs`, ported from OneSlips) | | LR-MASK-SUBJECT | Select subject | P2 | 🟡 | `cmd:mask.add` (`subject`), `crates/pipeline/src/masks.rs`, `crates/segment/src/birefnet.rs`, `cmd:segment.subject.download` | BiRefNet_lite (MIT, pure-Rust port, downloaded on request) when installed — demo-scene IoU 0.44 (sharp synthetic bokeh read as objects), real photos unmeasured, ~5.7 s per photo on CPU; otherwise boundary-prior saliency over the whole photo (`crates/pipeline/src/auto_mask.rs`; IoU 0.88 on the demo macro scenes), no segmentation model; a photo that carries person mattes (DNG semantic masks: iPhone ProRAW portrait / skin / hair / teeth / glasses mattes) uses them instead (synthetic files only: no corpus file carries person mattes) | | LR-MASK-SKY | Select sky | P2 | 🟡 | `cmd:mask.add` (`sky`), `crates/pipeline/src/masks.rs` (`Mattes`), `crates/raw/src/semantic.rs`, `crates/pipeline/src/auto_mask.rs` | whole-photo analysis (sky colour model + per-column split; IoU 0.79 on 21 labelled demo scenes); a photo that carries a sky matte (DNG semantic mask, e.g. iPhone ProRAW) uses it instead, through orientation / crop / lens corrections, preview = export (checked on one CC0 iPhone 12 Pro ProRAW and synthetic files); optionally the EoMT scene model (MIT, COCO; on-request download, `cmd:ai.models.setSceneModel`, ported by OneSlips) instead of the analysis: on the real weights it finds a drawn sky, not yet measured on real photos | | LR-MASK-BACKGROUND | Select background | P2 | 🟡 | `cmd:mask.add` (`background`), `crates/segment/src/birefnet.rs` | inverse of the subject mask (BiRefNet when installed, else the heuristic, or the photo's person mattes) | @@ -405,7 +405,7 @@ under the UI command that wraps it (a no-op error); the UI command now wins. | LR-MASK-PINS | Pins | P1 | ✅ | `cmd:view.maskPins`, `cmd:view.toolOverlay`, `crates/ui-egui/src/panels/detail.rs`, `crates/ui-egui/src/tests_tool_overlay.rs` | a pin per radial/linear/brush component: click selects its mask, drag moves it; Show Pins on follows the Tool Overlay mode (Auto: while the pointer is over the photo, hidden while brushing; Always; Selected: the selected mask's; Never; ⇧H cycles, #224); no pins for range/AI components | | LR-MASK-UPDATE | Recompute AI masks | P2 | ✅ | `cmd:mask.updateAi`, `cmd:masks.updateAi`, `cmd:masks.recompute`, `crates/engine/src/tests_segment.rs` | Update AI Mask in the mask list's menu, a component's menu, the photo's right-click menu (a pin right-clicked opens its mask's menu) and Photo ▸ Develop Settings ▸ Update All AI Masks (the selection); a stale AI mask (copied, synced, a preset's) has an amber badge on its row, click to update; an Object without clicks on this photo asks to be picked again. In the app the selections compute on the AI worker as one cancellable activity row (`aiMasks`); undo cancels, redo and presets start it by themselves (ported from OneSlips) | | LR-MASK-GEOMETRY | Masks stay on the photo under lens corrections, Upright, Transform and Rotate | P1 | ✅ | `crates/pipeline/src/mask_space.rs`, `crates/pipeline/src/tests_mask_geometry.rs`, `crates/engine/src/tests_mask_geometry.rs` | a mask's coordinates live on the photo before the warp (`Mask::on_photo`); renders (CPU and GPU, equivalence-tested; gradients under a warp evaluate on the CPU) and the on-photo tools map them through it, Rotate Left / Right turns them with the photo, and the AI models see the photo without lens corrections, Upright, Transform and flips. Masks from before move onto the photo, without moving on screen, at their next edit (ported from OneSlips) | -| LR-MASK-SYNC | Copy masks to other photos | P1 | ✅ | `cmd:develop.copy` (`groups`), `cmd:develop.autoSync`, `crates/develop/src/recipe.rs` (`sync_masks`, `for_other_photo`) | Auto Sync merges a mask edit into each selected photo's own masks; Object / Describe masks travel as recipes, found on each photo; masks applied to several photos in one go (Auto Sync, a preset on a selection, Paste, Sync Settings, Paste from Previous) are linked: with Auto Sync on an edit reaches the selected linked copies only (hand-made parts exactly, AI parts keep their own selection) | +| LR-MASK-SYNC | Copy masks to other photos | P1 | ✅ | `cmd:develop.copy` (`groups`, `masks`), `cmd:develop.autoSync`, `crates/develop/src/recipe.rs` (`sync_masks`, `for_other_photo`) | Auto Sync merges a mask edit into each selected photo's own masks; Object / Describe masks travel as recipes, found on each photo; masks applied to several photos in one go (Auto Sync, a preset on a selection, Paste, Sync Settings, Paste from Previous) are linked: with Auto Sync on an edit reaches the selected linked copies only (hand-made parts exactly, AI parts keep their own selection); Copy Settings can copy some of a photo's masks (`masks`: their ids), which paste in the photo's order and link to their originals (issue #1268) | | LR-MASK-ADAPTIVE | Adaptive presets | P2 | ⬜ | | | ## L. Presets (PRE) @@ -436,7 +436,7 @@ under the UI command that wraps it (a no-op error); the UI command now wins. | Id | Feature | Tier | Status | Evidence | Missing / notes | |---|---|---|---|---|---| | LR-SYNC-COPY | Copy edit settings | P0 | ✅ | `cmd:develop.copy` | | -| LR-SYNC-CHOOSE | Choose settings to copy | P0 | ✅ | `cmd:dialog.copySettings` | groups are coarser than per-slider | +| LR-SYNC-CHOOSE | Choose settings to copy | P0 | ✅ | `cmd:dialog.copySettings`, `cmd:develop.copy` (`groups`, `settings`, `masks`) | a box per group and, under its arrow, per single setting; under Masking a box per mask of the photo, with its name and what it is made of ("Mask 2: Radial Gradient, Brush"), so only some masks are copied (issue #1268; the mask choice is for that copy only, default all) | | LR-SYNC-PASTE | Paste to selection | P0 | ✅ | `cmd:develop.paste` | no separate "paste selected" (choose at copy time instead) | | LR-SYNC-SYNCBTN | Sync active → selected | P1 | ✅ | `cmd:develop.sync`, `cmd:dialog.syncSettings` | Was only a menu command without a choice of settings (should have been 🟡); now Synchronize Settings (group checkboxes, Check All / Check None, Synchronize / Cancel) from Photo ▸ Develop Settings ▸ Sync Settings… (⇧⌘S), the Develop panel's Sync… button and Library's Sync Settings button (2026-10-13); single Basic Tone controls (Exposure … Blacks) via `controls` (2026-10-14) | | LRC-LIB-SYNCMETA | Sync Metadata (active photo → selection) | P1 | ✅ | `cmd:photo.syncMetadata` | Metadata ▸ Sync Metadata and Library's Sync Metadata button: the active photo's title, caption, copyright, creator, location and keywords to the other selected photos, one undo step; no field-picking dialog yet (`fields` param only) | diff --git a/docs/whats-new/2026-11-18-copy-some-masks.md b/docs/whats-new/2026-11-18-copy-some-masks.md new file mode 100644 index 0000000000..f8baffe835 --- /dev/null +++ b/docs/whats-new/2026-11-18-copy-some-masks.md @@ -0,0 +1,6 @@ +### Copy only the masks you want +- In Copy Settings, open Masking with its arrow to see each mask of the photo, its name and what it is made of + ("Mask 2: Radial Gradient, Brush"). Tick the ones to copy: AI masks that carry over to other photos, say, + while a brush mask stays behind. The pasted masks stay linked to the photo they came from (issue #1268). +- A new mask whose automatic name another mask of the photo already has gets a number ("Brush 2"), so every mask + in the list has its own name. Names you gave and names from Lightroom stay as they are.