From 1205c6a1d0d1ea2cdbb90c56733336d2f69aad92 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 21 Nov 2026 02:26:30 -0600 Subject: [PATCH 1/2] Assign Profile: ask before assigning on a document with layers Edit > Assign Profile on a document with anything but a lone Background layer first asks whether to go on, since another profile can change how the layers look: OK opens the Assign Profile dialog, Cancel or Escape ends the command with nothing changed, and an unticked "Don't show again" is kept with the other dialog preferences. A flat document and runs with params (scripts, actions, agents, the control channel) never ask. Fixes #14235 --- crates/ui-egui/src/control/dialogs.rs | 1 + crates/ui-egui/src/dialogs.rs | 14 ++- .../dialogs/assign_profile_layers_alert.rs | 56 ++++++++++ .../assign_profile_layers_alert_tests.rs | 105 ++++++++++++++++++ crates/ui-egui/src/menus/invoke.rs | 4 + 5 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 crates/ui-egui/src/dialogs/assign_profile_layers_alert.rs create mode 100644 crates/ui-egui/src/dialogs/assign_profile_layers_alert_tests.rs diff --git a/crates/ui-egui/src/control/dialogs.rs b/crates/ui-egui/src/control/dialogs.rs index e1bd171839..ede12b7e8b 100644 --- a/crates/ui-egui/src/control/dialogs.rs +++ b/crates/ui-egui/src/control/dialogs.rs @@ -252,6 +252,7 @@ pub(crate) const FIELD_KEYS: &[FieldKey] = &[ prompt!(crate::dialogs::rasterize_prompt::Rasterize, &[("rasterize", "proceed"), ("smartObject", "alternate"), CANCEL]), prompt!(crate::dialogs::preset_group_prompt::PresetClash, &[("new", "proceed"), ("replace", "alternate"), CANCEL]), prompt!(crate::dialogs::live_shape_prompt::LiveShapeAsk, &[("yes", "proceed"), ("no", "cancel"), CANCEL]), + prompt!(crate::dialogs::assign_profile_layers_alert::AssignProfileAsk, &[("ok", "proceed"), CANCEL]), prompt!(crate::dialogs::delete_layer_prompt::PendingDelete, &[("delete", "proceed"), CANCEL]), prompt!(crate::dialogs::open_prompt::DamageTag, &[("continue", "proceed"), ("open", "proceed"), CANCEL]), prompt!(crate::dialogs::open_prompt::MemoryTag, &[("continue", "proceed"), ("open", "proceed"), CANCEL]), diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 8e827d7e4d..1ebf5108b6 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -406,6 +406,7 @@ pub(crate) const PROMPTS: &[PromptRow] = &[ disk_change_prompt::answer, rasterize_prompt::answer, live_shape_prompt::answer, + assign_profile_layers_alert::answer, preset_group_prompt::answer, open_prompt::answer_prompt, alerts::answer, @@ -622,8 +623,14 @@ const ENGINE_READ: &[&str] = &["ui.layersPanelOptions", "file.print", "file.expo /// The "Don't show again" entries (`{"skip": true}`), by key, as their prompt modules read them. Told apart by key, not /// by the shape of the value. -fn dont_show_again_keys() -> [&'static str; 4] { - [delete_layer_prompt::PREF, live_shape_prompt::PREF, crate::analysis::note_alerts::DELETE_NOTE_PREF, crate::retouch_ui::CAM_NO_PIXELS_PREF] +fn dont_show_again_keys() -> [&'static str; 5] { + [ + delete_layer_prompt::PREF, + live_shape_prompt::PREF, + assign_profile_layers_alert::PREF, + crate::analysis::note_alerts::DELETE_NOTE_PREF, + crate::retouch_ui::CAM_NO_PIXELS_PREF, + ] } /// Where the remembered value of the preference entry `key` goes: `None` keeps it in `Preferences.dialogs`, else the @@ -687,6 +694,9 @@ pub mod adjust_preview; pub mod alerts; #[cfg(test)] mod arbitrary_ruler_prefill_tests; +pub mod assign_profile_layers_alert; +#[cfg(test)] +mod assign_profile_layers_alert_tests; pub(crate) mod bitmap_dialog; pub mod blend_options; pub mod blur_pins; diff --git a/crates/ui-egui/src/dialogs/assign_profile_layers_alert.rs b/crates/ui-egui/src/dialogs/assign_profile_layers_alert.rs new file mode 100644 index 0000000000..6e16df36eb --- /dev/null +++ b/crates/ui-egui/src/dialogs/assign_profile_layers_alert.rs @@ -0,0 +1,56 @@ +//! Edit › Assign Profile on a document with layers first asks whether to go on (#14235): giving the document another +//! profile can change how its layers look. OK (the default) and Cancel, and a "Don't show again" box kept with the +//! other dialog preferences. OK opens the Assign Profile dialog; Cancel or Escape ends the command with nothing changed. +//! A document with only a Background layer never asks, nor does `edit.assignProfile` run with params (scripts, +//! actions, agents, the control channel), which the menu arm leaves to the command. + +use craft::ui::dialog::{DialogId, PromptAnswer, PromptChoice, StandardPrompt}; + +use super::alerts; +use crate::PhotocraftApp; + +/// Its "Don't show again", under `Preferences::dialogs`. +pub const PREF: &str = "edit.assignProfile.layers"; + +/// PhotoCraft's own wording of the reference application's warning. +const QUESTION: &str = "Giving the document another profile can change how its layers look. Assign a profile anyway?"; + +/// The tag of the open question. +pub(crate) struct AssignProfileAsk; + +/// Whether the menu's Assign Profile asks first: the active document has anything but a lone Background layer, and +/// "Don't show again" was not ticked. +pub fn asks(app: &PhotocraftApp) -> bool { + let Some(st) = app.session.active() else { return false }; + let flat = st.doc.layers.len() == 1 && st.doc.background().is_some(); + !flat && !alerts::dismissed(app, PREF) +} + +/// Opens the question; the id of the question already open when there is one. +pub fn open(app: &mut PhotocraftApp) -> DialogId { + let prompt = StandardPrompt::custom(tl!(QUESTION).to_owned()) + .title(tl!("Assign Profile").to_owned()) + .button(PromptChoice::Proceed, tl!("OK").to_owned()) + .button(PromptChoice::Cancel, tl!("Cancel").to_owned()) + .dont_show_again() + .tag(AssignProfileAsk); + alerts::open_prompt(app, prompt).unwrap_or_else(|open| open) +} + +/// The `PROMPTS` entry: OK keeps a ticked "Don't show again" and opens the Assign Profile dialog; Cancel changes +/// nothing. `false` for another family's answer. +pub(crate) fn answer(app: &mut PhotocraftApp, _ctx: &egui::Context, answer: &mut PromptAnswer) -> bool { + if answer.take_tag::().is_none() { + return false; + } + if answer.choice != PromptChoice::Proceed { + return true; + } + if answer.skip { + alerts::remember_skip(app, PREF); + } + if let Err(error) = crate::filter_dialog::open(app, "edit.assignProfile") { + alerts::report_error(app, error); + } + true +} diff --git a/crates/ui-egui/src/dialogs/assign_profile_layers_alert_tests.rs b/crates/ui-egui/src/dialogs/assign_profile_layers_alert_tests.rs new file mode 100644 index 0000000000..f1235e4e53 --- /dev/null +++ b/crates/ui-egui/src/dialogs/assign_profile_layers_alert_tests.rs @@ -0,0 +1,105 @@ +//! #14235: Edit › Assign Profile on a document with layers asks first, with OK, Cancel and an unticked "Don't show +//! again". OK opens the Assign Profile dialog, Cancel changes nothing; a flat document and a run with params never ask; +//! a ticked box with OK keeps the question away. + +use craft::ui::dialog::{DialogId, StackDialog as _, StandardPrompt}; +use craft::ui::patterns::form_dialogs::HostedParamDialog; +use serde_json::{Value, json}; + +use super::alerts; +use super::assign_profile_layers_alert::{AssignProfileAsk, PREF}; +use crate::PhotocraftApp; + +/// An RGB document; with `layers`, a pixel layer above the Background. +fn app(layers: bool) -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 40, "height": 30})).unwrap(); + if layers { + app.run("layer.new.layer", json!({})).unwrap(); + } + app +} + +fn menu(app: &mut PhotocraftApp) -> Value { + let ctx = app.ctx().clone(); + crate::menus::invoke(app, &ctx, "edit.assignProfile", json!({})).unwrap() +} + +fn question(app: &PhotocraftApp) -> Option { + alerts::prompt_tagged::(app) +} + +fn assign_dialog_open(app: &PhotocraftApp) -> bool { + app.framework.dialogs.get::().is_some() +} + +fn answer(app: &mut PhotocraftApp, id: DialogId, choice: &str, skip: bool) { + let ctx = app.ctx().clone(); + app.framework.dialogs.set_json_field(&ctx, id, "choice", json!(choice)).unwrap(); + app.framework.dialogs.set_json_field(&ctx, id, "skip", json!(skip)).unwrap(); + crate::dialogs::confirm(app, &ctx, id).unwrap(); +} + +fn steps(app: &PhotocraftApp) -> usize { + app.session.active().unwrap().history.past_len() +} + +#[test] +fn a_document_with_layers_asks_before_the_dialog() { + let mut app = app(true); + let before = steps(&app); + menu(&mut app); + assert!(question(&app).is_some(), "the question"); + assert!(!assign_dialog_open(&app), "the dialog waits for the answer"); + let fields = app.framework.dialogs.get::().and_then(|p| p.json_fields()).unwrap(); + assert_eq!(fields["skip"], json!(false), "Don't show again starts unticked"); + assert_eq!(steps(&app), before); +} + +#[test] +fn ok_opens_the_assign_profile_dialog() { + let mut app = app(true); + menu(&mut app); + let id = question(&app).unwrap(); + answer(&mut app, id, "proceed", false); + assert!(question(&app).is_none() && assign_dialog_open(&app)); +} + +#[test] +fn cancel_ends_the_command_with_nothing_changed() { + let mut app = app(true); + let before = steps(&app); + menu(&mut app); + let id = question(&app).unwrap(); + answer(&mut app, id, "cancel", false); + assert!(question(&app).is_none() && !assign_dialog_open(&app), "no dialog"); + assert_eq!(steps(&app), before, "no history state"); + menu(&mut app); + assert!(question(&app).is_some(), "a Cancel keeps nothing: it asks again"); +} + +#[test] +fn a_flat_document_and_a_run_with_params_never_ask() { + let mut app = app(false); + menu(&mut app); + assert!(question(&app).is_none() && assign_dialog_open(&app), "only a Background: the dialog opens at once"); + let mut app = self::app(true); + app.run("edit.assignProfile", json!({"profile": "none"})).unwrap(); + assert!(question(&app).is_none(), "a scripted run doesn't ask"); +} + +#[test] +fn dont_show_again_with_ok_keeps_the_question_away() { + let mut app = app(true); + menu(&mut app); + let id = question(&app).unwrap(); + answer(&mut app, id, "proceed", true); + assert!(alerts::dismissed(&app, PREF)); + let ctx = app.ctx().clone(); + for d in app.framework.dialogs.open_dialogs() { + let _ = crate::dialogs::cancel(&mut app, &ctx, d.id); + } + assert!(!assign_dialog_open(&app)); + menu(&mut app); + assert!(question(&app).is_none() && assign_dialog_open(&app), "the dialog opens without asking"); +} diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index 9b24124092..2d01f0df91 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -779,6 +779,10 @@ fn invoke_view_command(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, p crate::equalize_ui::COMMAND if params.as_object().is_none_or(|object| object.is_empty()) && crate::equalize_ui::asks(app) => { Some(Ok(dialog_reply(crate::equalize_ui::open(app)))) } + // Edit › Assign Profile on a document with layers asks first (#14235). + "edit.assignProfile" if params.as_object().is_none_or(|object| object.is_empty()) && crate::dialogs::assign_profile_layers_alert::asks(app) => { + Some(Ok(dialog_reply(crate::dialogs::assign_profile_layers_alert::open(app)))) + } fl if crate::filter_dialog::has_dialog(fl) && params.as_object().is_none_or(|object| object.is_empty()) => { Some(crate::filter_dialog::open(app, fl).map(dialog_reply)) } From 8c06f525d8a5bdb3a220a4aac10efe2ee9970152 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 21 Nov 2026 03:56:49 -0600 Subject: [PATCH 2/2] Freeform Pen: Shift leaves the freehand stroke as drawn The Freeform Pen's trace is no longer built with locking_shift_drags, so a drag with Shift held gives the same path as without it, corners kept, as the reference's Freeform Pen does. The stale FreeformPen entry leaves stroke_constraint::applies; Shift keeps constraining the painting tools and the Gradient tool. Tests: the old shift_drag_constrains_freeform_pen_to_a_straight_line (which asserted the lock) is removed, as the issue asks; snapping_angles now checks that the Freeform Pen passes through. Fixes #12832 --- crates/ui-egui/src/tools.rs | 2 + .../ui-egui/src/tools/freeform_shift_tests.rs | 45 +++++++++++++++++++ crates/ui-egui/src/tools/stroke_constraint.rs | 13 +++--- .../ui-egui/src/tools/vector_ui/freeform.rs | 3 +- .../src/tools/vector_ui/freeform_pen_tests.rs | 17 ------- 5 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 crates/ui-egui/src/tools/freeform_shift_tests.rs diff --git a/crates/ui-egui/src/tools.rs b/crates/ui-egui/src/tools.rs index d23b04cd3b..3d2f26f082 100644 --- a/crates/ui-egui/src/tools.rs +++ b/crates/ui-egui/src/tools.rs @@ -65,6 +65,8 @@ mod count_show_extras_tests; #[cfg(test)] mod crop_mode_tests; #[cfg(test)] +mod freeform_shift_tests; +#[cfg(test)] mod gradient_options_bar_mode_tests; #[cfg(test)] mod line_tool_defaults_tests; diff --git a/crates/ui-egui/src/tools/freeform_shift_tests.rs b/crates/ui-egui/src/tools/freeform_shift_tests.rs new file mode 100644 index 0000000000..1db9d463e5 --- /dev/null +++ b/crates/ui-egui/src/tools/freeform_shift_tests.rs @@ -0,0 +1,45 @@ +//! #12832: Shift held while drawing with the Freeform Pen leaves the freehand stroke as drawn: a vee gives the same +//! path with Shift as without, its corner kept. Shift keeps constraining the painting tools (their own tests). + +use egui::Modifiers; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::testing; +use crate::state::Tool; +use craft::draw::ui::VectorMode; + +fn app() -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 800, "height": 600})).unwrap(); + app.sync_views(); + app.ui.tool = Tool::FreeformPen; + app.ui.extras.snap = false; + app.ui.tool_options.vector_mode = VectorMode::Path; + app +} + +/// The anchors of the Work Path a vee from (100,450) down to (250,550) and up to (400,450) leaves, drawn with `mods`. +fn vee(mods: Modifiers) -> Vec<[f64; 2]> { + let mut app = app(); + testing::press(&mut app, [100.0, 450.0], mods); + for i in 1..=10 { + let t = f64::from(i) / 10.0; + testing::move_to(&mut app, [100.0 + 150.0 * t, 450.0 + 100.0 * t], mods); + } + for i in 1..=10 { + let t = f64::from(i) / 10.0; + testing::move_to(&mut app, [250.0 + 150.0 * t, 550.0 - 100.0 * t], mods); + } + testing::release(&mut app, [400.0, 450.0], mods); + let work = app.session.active().unwrap().doc.work_path.clone().expect("the stroke committed a work path"); + work.subpaths[0].knots.iter().map(|k| [k.anchor.x, k.anchor.y]).collect() +} + +#[test] +fn shift_leaves_the_freehand_vee_as_drawn() { + let plain = vee(Modifiers::NONE); + let shifted = vee(Modifiers::SHIFT); + assert_eq!(shifted, plain, "the same path with and without Shift"); + assert!(shifted.iter().any(|a| a[1] > 520.0), "the corner is kept: {shifted:?}"); +} diff --git a/crates/ui-egui/src/tools/stroke_constraint.rs b/crates/ui-egui/src/tools/stroke_constraint.rs index a7567029d9..f1ac398169 100644 --- a/crates/ui-egui/src/tools/stroke_constraint.rs +++ b/crates/ui-egui/src/tools/stroke_constraint.rs @@ -37,10 +37,10 @@ pub struct Axis { pub dir: Option<[f64; 2]>, } -/// Tools whose drag ⇧ constrains: every painting tool, the Gradient tool, and the Freeform Pen -/// (Photoshop's freehand path segment with ⇧, #7171). +/// Tools whose drag ⇧ constrains: every painting tool and the Gradient tool. The Freeform Pen draws freehand with ⇧ +/// too (#12832). pub fn applies(tool: Tool) -> bool { - tool.is_brushlike() || tool == Tool::Gradient || tool == Tool::FreeformPen + tool.is_brushlike() || tool == Tool::Gradient } /// Tools that ⇧-click connects to the previous stroke with a straight line. @@ -208,8 +208,8 @@ mod tests { // The Brush never locks to a diagonal: this slightly-more-vertical movement goes vertical. let mut axis = None; assert!(close(p([40.0, 43.0], &mut axis), [10.0, 43.0]), "the Brush's near-diagonal goes vertical"); - // Every other ⇧-constrained drag keeps the 45° lock (#178, and #7304 for the Freeform Pen). - for tool in [Tool::Pencil, Tool::Eraser, Tool::FreeformPen] { + // Every other ⇧-constrained drag keeps the 45° lock (#178). + for tool in [Tool::Pencil, Tool::Eraser] { let mut axis = None; let q = constrain(tool, &mut axis, o, o, [40.0, 43.0], true, 1.0); assert!((q[0] - 10.0 - (q[1] - 10.0)).abs() < 1e-9, "{tool:?} should lock to 45°: {q:?}"); @@ -219,8 +219,9 @@ mod tests { let mut axis = None; assert!(close(p([100.0, 100.0], &mut axis), o), "exact tie stays on the start point"); assert!(close(p([160.0, 140.0], &mut axis), [160.0, 10.0]), "a later point breaks the tie"); - // Other tools pass through. + // Other tools pass through, the Freeform Pen too (#12832). assert!(close(constrain(Tool::Move, &mut None, o, o, [30.0, 12.0], true, 1.0), [30.0, 12.0])); + assert!(close(constrain(Tool::FreeformPen, &mut None, o, o, [40.0, 43.0], true, 1.0), [40.0, 43.0])); } #[test] diff --git a/crates/ui-egui/src/tools/vector_ui/freeform.rs b/crates/ui-egui/src/tools/vector_ui/freeform.rs index 26ad0bbde3..b635c1b68f 100644 --- a/crates/ui-egui/src/tools/vector_ui/freeform.rs +++ b/crates/ui-egui/src/tools/vector_ui/freeform.rs @@ -67,7 +67,8 @@ impl Default for FreeformPenTool { Self { admit: Admit::Open, refused: false, - draft: OutlineDraft::new(DraftKind::Mixed, DraftReach::new(0.0, 0.0)).locking_shift_drags(), + // ⇧ leaves the freehand trace as drawn, as the reference's Freeform Pen does (#12832). + draft: OutlineDraft::new(DraftKind::Mixed, DraftReach::new(0.0, 0.0)), owner: None, target: None, closed: None, diff --git a/crates/ui-egui/src/tools/vector_ui/freeform_pen_tests.rs b/crates/ui-egui/src/tools/vector_ui/freeform_pen_tests.rs index 40a513eddb..b840d776bd 100644 --- a/crates/ui-egui/src/tools/vector_ui/freeform_pen_tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/freeform_pen_tests.rs @@ -133,20 +133,3 @@ fn another_freeform_trace_cannot_replace_a_failed_owned_draft_or_retry_it_automa assert_eq!(app.session.journal.len(), journal, "drawing must not retry the failed engine command"); } } - -#[test] -fn shift_drag_constrains_freeform_pen_to_a_straight_line() { - let mut app = app(); - app.ui.tool_options.vector_mode = VectorMode::Path; - let shift = Modifiers::SHIFT; - testing::press(&mut app, [10.0, 60.0], shift); - for (x, y) in [(30.0, 63.0), (50.0, 55.0), (80.0, 68.0), (100.0, 52.0)] { - testing::move_to(&mut app, [x, y], shift); - } - testing::release(&mut app, [100.0, 52.0], shift); - let work = app.session.active().unwrap().doc.work_path.clone().expect("the stroke committed a work path"); - let knots = &work.subpaths[0].knots; - assert!(knots.len() >= 2, "{knots:?}"); - let y0 = knots[0].anchor.y; - assert!(knots.iter().all(|k| (k.anchor.y - y0).abs() < 1e-6), "⇧ keeps the freehand segment horizontal: {knots:?}"); -}