diff --git a/crates/ui-egui/src/panels/actions.rs b/crates/ui-egui/src/panels/actions.rs index 73675c83f6d..8c411f732fd 100644 --- a/crates/ui-egui/src/panels/actions.rs +++ b/crates/ui-egui/src/panels/actions.rs @@ -1703,7 +1703,12 @@ fn duplicate_selection(app: &mut PhotocraftApp) -> Result { return Ok(result); } let action = app.ui.actions.selected.ok_or_else(|| tl!("Select an action first").to_string())?; - let step = app.ui.actions.selected_step; + duplicate_row(app, action, app.ui.actions.selected_step) +} + +/// Duplicate one action or step (the selected row, or one dropped on Create new action, #12373) +/// and select the copy. +fn duplicate_row(app: &mut PhotocraftApp, action: usize, step: Option) -> Result { let count = app.session.actions.list.len(); let expanded = app.ui.actions.expanded.get(action).copied().unwrap_or(false); let result = app.run("actions.duplicate", json!({"action": action, "step": step}))?; @@ -1727,19 +1732,53 @@ fn duplicate_selection(app: &mut PhotocraftApp) -> Result { fn delete_selection(app: &mut PhotocraftApp) { let Some(action) = app.ui.actions.selected else { return }; let step = app.ui.actions.selected_step; - let mut params = json!({"action": action}); - if let Some(step) = step { - params["step"] = json!(step); - } - if app.run("actions.delete", params).is_err() { + if !delete_row(app, action, step) { return; } // Clear selection after deletion so a second click cannot delete a different // step or unexpectedly fall back to deleting the entire action. app.ui.actions.selected = None; app.ui.actions.selected_step = None; - if step.is_none() && action < app.ui.actions.expanded.len() { - app.ui.actions.expanded.remove(action); +} + +/// Delete one action or step (the selected row, or one dropped on the trash, #12373) and keep +/// the selection and disclosure rows pointing at the same rows. False when the engine refused. +fn delete_row(app: &mut PhotocraftApp, action: usize, step: Option) -> bool { + let mut params = json!({"action": action}); + if let Some(step) = step { + params["step"] = json!(step); + } + if app.run("actions.delete", params).is_err() { + return false; + } + let ui = &mut app.ui.actions; + match (step, ui.selected) { + (None, Some(sel)) if sel == action => { + ui.selected = None; + ui.selected_step = None; + } + (None, Some(sel)) if sel > action => ui.selected = Some(sel - 1), + (Some(step), Some(sel)) if sel == action => match ui.selected_step { + Some(s) if s == step => { + ui.selected = None; + ui.selected_step = None; + } + Some(s) if s > step => ui.selected_step = Some(s - 1), + _ => {} + }, + _ => {} + } + if step.is_none() && action < ui.expanded.len() { + ui.expanded.remove(action); + } + true +} + +/// Outline a footer button a dragged row would be dropped on. +fn drop_target_highlight(ui: &egui::Ui, response: &egui::Response, active: bool, t: &Tokens) { + if active && response.contains_pointer() { + ui.painter().rect_filled(response.rect, t.radius_sm, t.hover); + ui.painter().rect_stroke(response.rect, t.radius_sm, Stroke::new(1.0, t.accent), egui::StrokeKind::Inside); } } @@ -2153,16 +2192,34 @@ pub fn panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) { app.ui.status = e; app.ui.status_error = true; } - if crate::icons::button(ui, "plus", 24.0, false, tl!("Create new action")).clicked() && !recording_now { + let dragged = egui::DragAndDrop::payload::(ui.ctx()).map(|row| *row); + let plus = crate::icons::button(ui, "plus", 24.0, false, tl!("Create new action")); + if plus.clicked() && !recording_now { begin_recording(app, false); } + // A row dragged onto Create new action is duplicated, as in Photoshop (#12373). + drop_target_highlight(ui, &plus, dragged.is_some() && !recording_now, &t); + if !recording_now + && let Some(row) = plus.dnd_release_payload::() + && let Err(e) = duplicate_row(app, row.action, row.step) + { + app.ui.status = e; + app.ui.status_error = true; + } let can_delete = app.ui.actions.selected.is_some() && (!recording_now || app.ui.actions.selected_step.is_some()); - ui.add_enabled_ui(can_delete, |ui| { + // While recording only a step may be deleted, by the button or by a drop. + let can_drop = dragged.is_some_and(|row| !recording_now || row.step.is_some()); + ui.add_enabled_ui(can_delete || can_drop, |ui| { let response = crate::icons::button(ui, "trash", 24.0, false, tl!("Delete")); - response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, can_delete, tl!("Delete"))); + response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, can_delete || can_drop, tl!("Delete"))); if response.clicked() { delete_selection(app); } + // A row dragged onto the trash is deleted without a confirmation (#12373). + drop_target_highlight(ui, &response, can_drop, &t); + if can_drop && let Some(row) = response.dnd_release_payload::() { + delete_row(app, row.action, row.step); + } }); let mode_label = if app.ui.actions.button_mode { tl!("Button Mode On") } else { tl!("Button Mode") }; let mode_button = ui.add_enabled(!recording_now, egui::Button::new(mode_label).small()).on_hover_text(tl!("Button Mode")); @@ -2293,3 +2350,6 @@ mod stop_tests; #[cfg(test)] mod playback_tests; + +#[cfg(test)] +mod drag_drop_tests; diff --git a/crates/ui-egui/src/panels/actions/drag_drop_tests.rs b/crates/ui-egui/src/panels/actions/drag_drop_tests.rs new file mode 100644 index 00000000000..2b0268b9f98 --- /dev/null +++ b/crates/ui-egui/src/panels/actions/drag_drop_tests.rs @@ -0,0 +1,105 @@ +//! #12373: an Actions panel row dragged onto the trash is deleted, onto Create new action duplicated. +use super::*; +use egui_kittest::{Harness, kittest::Queryable}; + +fn names(app: &PhotocraftApp) -> Vec { + app.session.actions.list.iter().map(|a| a.name.clone()).collect() +} + +fn steps(app: &PhotocraftApp, action: usize) -> Vec { + app.session.actions.list[action].steps.iter().map(|s| s.0.clone()).collect() +} + +fn harness() -> Harness<'static, PhotocraftApp> { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.session.actions.list.push(Action { + name: "First".into(), + steps: vec![("view.zoomOut".into(), json!({})), ("view.fitOnScreen".into(), json!({})), ("view.actualPixels".into(), json!({}))], + ..Default::default() + }); + app.session.actions.list.push(Action { name: "Second".into(), steps: vec![("view.zoomIn".into(), json!({}))], ..Default::default() }); + app.ui.actions.expanded = vec![true, false]; + let mut h = Harness::builder().with_size(vec2(320.0, 400.0)).build_ui_state(|ui, app| panel(app, ui), app); + h.run_steps(4); + h +} + +fn drag(h: &mut Harness<'_, PhotocraftApp>, from: egui::Pos2, to: egui::Pos2) { + h.event(egui::Event::PointerMoved(from)); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE }); + h.run_steps(1); + h.event(egui::Event::PointerMoved(from + vec2(10.0, 0.0))); + h.run_steps(2); + h.event(egui::Event::PointerMoved(to)); + h.run_steps(2); + h.event(egui::Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: egui::Modifiers::NONE }); + h.run_steps(3); +} + +fn center(h: &Harness<'_, PhotocraftApp>, label: &str) -> egui::Pos2 { + h.get_by_label(label).rect().center() +} + +#[test] +fn step_dragged_onto_trash_deletes_only_that_step() { + let mut h = harness(); + let (from, to) = (center(&h, "Fit on Screen"), center(&h, "Delete")); + drag(&mut h, from, to); + assert_eq!(names(h.state()), ["First", "Second"]); + assert_eq!(steps(h.state(), 0), ["view.zoomOut", "view.actualPixels"]); +} + +#[test] +fn action_dragged_onto_trash_is_deleted_even_when_another_is_selected() { + let mut h = harness(); + h.state_mut().ui.actions.select(1, None); + h.run_steps(2); + let (from, to) = (center(&h, "First"), center(&h, "Delete")); + drag(&mut h, from, to); + assert_eq!(names(h.state()), ["Second"]); + assert_eq!(h.state().ui.actions.selected, Some(0)); + assert_eq!(h.state().ui.actions.expanded.len(), 1); +} + +#[test] +fn action_dragged_onto_plus_adds_a_copy_after_it() { + let mut h = harness(); + let (from, to) = (center(&h, "First"), center(&h, "Create new action")); + drag(&mut h, from, to); + assert_eq!(names(h.state()).len(), 3); + assert_eq!(names(h.state())[0], "First"); + assert_eq!(names(h.state())[2], "Second"); + assert_eq!(steps(h.state(), 1), steps(h.state(), 0)); + assert!(h.state().session.actions.recording.is_none()); +} + +#[test] +fn step_dragged_onto_plus_duplicates_the_step_in_place() { + let mut h = harness(); + let (from, to) = (center(&h, "Fit on Screen"), center(&h, "Create new action")); + drag(&mut h, from, to); + assert_eq!(names(h.state()), ["First", "Second"]); + assert_eq!(steps(h.state(), 0), ["view.zoomOut", "view.fitOnScreen", "view.fitOnScreen", "view.actualPixels"]); +} + +#[test] +fn drag_released_over_empty_space_changes_nothing() { + let mut h = harness(); + let from = center(&h, "Fit on Screen"); + drag(&mut h, from, pos2(160.0, 300.0)); + assert_eq!(names(h.state()), ["First", "Second"]); + assert_eq!(steps(h.state(), 0).len(), 3); + assert_eq!(steps(h.state(), 1).len(), 1); +} + +#[test] +fn action_dropped_on_trash_while_recording_is_not_deleted() { + let mut h = harness(); + h.state_mut().run("actions.record", json!({"name": "Rec"})).unwrap(); + h.run_steps(3); + let (from, to) = (center(&h, "Second"), center(&h, "Delete")); + drag(&mut h, from, to); + assert!(names(h.state()).contains(&"Second".to_string())); + assert!(names(h.state()).contains(&"First".to_string())); +} diff --git a/docs/ui-parity.md b/docs/ui-parity.md index d605faf62a1..f9f0a99f4d5 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -274,6 +274,7 @@ Paragraph; the rest open as in-app floating windows. | Date | Change | Summary | |---|---|---| +| 2026-11-08 | minor | Actions panel: an action or step row dragged onto the trash is deleted, and one dragged onto Create new action is duplicated right after itself (#12373) | | 2026-11-08 | minor | Image › Adjustments › Photo Filter… keeps Preserve Luminosity from its last OK; filter, colour and density reopen at Warming Filter (85) and 25 %, measured in the reference application (#9879); no percentage changed | | 2026-11-07 | minor | Gradient stops dragged off the bar are removed, with a live preview and drag-back cancel, in every stop editor: Gradient Map and Layer Style gained it, the Gradient Editor, Properties and shape popover share the same threshold (#10742); row added (done); no percentage changed | | 2026-11-07 | minor | Foreground/background colours restored before the first frame (`Preferences.toolColors`, #8485), with separate pixel/mask pairs, HDR/alpha, exact CMYK ink picks and a final normal-exit flush; malformed values are ignored one by one, and first saves from older preferences merge against the default swatches so separate edits in two instances survive. No percentage changed |