mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge pull request #12402 from TrevorBrown-dev/fix/actions-drag-trash-new-12373
Actions panel: a row dragged onto the trash is deleted, onto Create new action duplicated
This commit is contained in:
4 files changed
+228
-11
No files matched your search
@@ -1703,7 +1703,12 @@ fn duplicate_selection(app: &mut PhotocraftApp) -> Result<Value, String> {
|
||||
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<usize>) -> Result<Value, String> {
|
||||
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}))?;
|
||||
@@ -1715,6 +1720,10 @@ fn duplicate_selection(app: &mut PhotocraftApp) -> Result<Value, String> {
|
||||
if index <= app.ui.actions.expanded.len() {
|
||||
app.ui.actions.expanded.insert(index, expanded);
|
||||
}
|
||||
// A name field open on an action at or after the copy moves down with that action.
|
||||
if let Some(r) = app.ui.actions.renaming.as_mut().filter(|r| r.index >= index) {
|
||||
r.index += 1;
|
||||
}
|
||||
} else {
|
||||
app.ui.actions.expanded.resize(count, false);
|
||||
if let Some(expanded) = app.ui.actions.expanded.get_mut(index) {
|
||||
@@ -1727,19 +1736,65 @@ fn duplicate_selection(app: &mut PhotocraftApp) -> Result<Value, String> {
|
||||
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<usize>) -> 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() {
|
||||
if action < ui.expanded.len() {
|
||||
ui.expanded.remove(action);
|
||||
}
|
||||
// A name field open on the deleted action closes; one on a later action moves up with it.
|
||||
match ui.renaming.as_ref().map(|r| r.index) {
|
||||
Some(i) if i == action => ui.renaming = None,
|
||||
Some(i) if i > action => {
|
||||
if let Some(r) = ui.renaming.as_mut() {
|
||||
r.index = i - 1;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// Outline a footer button a dragged row would be dropped on (an outline only, so the icon
|
||||
/// stays visible).
|
||||
fn drop_target_highlight(ui: &egui::Ui, response: &egui::Response, active: bool, t: &Tokens) {
|
||||
if active && response.contains_pointer() {
|
||||
ui.painter().rect_stroke(response.rect, t.radius_sm, Stroke::new(1.5, t.accent), egui::StrokeKind::Inside);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2153,16 +2208,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::<DragRow>(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::<DragRow>()
|
||||
&& 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::<DragRow>() {
|
||||
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 +2366,6 @@ mod stop_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod playback_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod drag_drop_tests;
|
||||
@@ -0,0 +1,139 @@
|
||||
//! #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<String> {
|
||||
app.session.actions.list.iter().map(|a| a.name.clone()).collect()
|
||||
}
|
||||
|
||||
fn steps(app: &PhotocraftApp, action: usize) -> Vec<String> {
|
||||
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()));
|
||||
}
|
||||
|
||||
fn rename_open_on(app: &mut PhotocraftApp, index: usize, text: &str) {
|
||||
app.ui.actions.renaming = Some(RenameAction { index, text: text.into(), focused: true });
|
||||
}
|
||||
|
||||
fn renaming(app: &PhotocraftApp) -> Option<(usize, String)> {
|
||||
app.ui.actions.renaming.as_ref().map(|r| (r.index, r.text.clone()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_open_name_field_stays_on_its_action_when_another_is_deleted_or_copied() {
|
||||
let mut h = harness();
|
||||
let app = h.state_mut();
|
||||
// Deleting the action above moves the field up with its action.
|
||||
rename_open_on(app, 1, "Second renamed");
|
||||
assert!(delete_row(app, 0, None));
|
||||
assert_eq!(renaming(app), Some((0, "Second renamed".into())));
|
||||
// Deleting the action being renamed closes the field.
|
||||
assert!(delete_row(app, 0, None));
|
||||
assert_eq!(renaming(app), None);
|
||||
|
||||
let mut h = harness();
|
||||
let app = h.state_mut();
|
||||
// A copy inserted above moves the field down with its action; one below leaves it.
|
||||
rename_open_on(app, 1, "Second renamed");
|
||||
duplicate_row(app, 0, None).unwrap();
|
||||
assert_eq!(renaming(app), Some((2, "Second renamed".into())));
|
||||
duplicate_row(app, 2, None).unwrap();
|
||||
assert_eq!(renaming(app), Some((2, "Second renamed".into())));
|
||||
// Deleting or copying a step leaves it alone.
|
||||
assert!(delete_row(app, 0, Some(0)));
|
||||
duplicate_row(app, 0, Some(0)).unwrap();
|
||||
assert_eq!(renaming(app), Some((2, "Second renamed".into())));
|
||||
}
|
||||
@@ -176,6 +176,7 @@ heading instead targets the whole action. Step deletion also works during record
|
||||
and does not undo the document edit. The control equivalent is
|
||||
`actions.delete {"action": "Name", "step": 0}` (zero-based). Omitting `step` deletes
|
||||
the whole action, which still requires recording to be stopped.
|
||||
A step or action row dragged onto the trash is deleted without a confirmation, and one dragged onto the plus button is duplicated right after itself (`actions.duplicate`), as in Photoshop.
|
||||
|
||||
Desktop actions also record and replay View › Fit on Screen (`view.fitOnScreen`),
|
||||
100% (`view.actualPixels`), Zoom In and Zoom Out through their menu commands or shortcuts.
|
||||
|
||||
@@ -276,6 +276,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-10-27 | minor | Warp mode edits Photoshop's Cylinder warp (#4112): the Warp menu lists it, its five handles set its seven values as in the reference, and a smart object's stored cylinder opens as one. Scores unchanged. |
|
||||
| 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 |
|
||||
|
||||
Reference in new issue
Block a user