Delete in Edit Joint deletes that joint, and a refused joint delete says why (#3749) (#3776)

* claim: #3749

* Edit Joint: deleting the joint being edited closes the dialog and deletes it (#3749)

A joint delete was dropped without a word while any dialog was open, and
Edit Joint is a dialog. Deleting only the joint Edit Joint edits now
cancels the dialog first (as its Cancel does) and goes through the usual
selection.delete dry run; Delete with nothing else selected in Edit Joint
targets that joint. Every other refusal (another dialog, a tool, a
computing history, a loading file) now says why in the status bar.
This commit is contained in:
raykholo
2026-10-21 00:49:50 +00:00
committed by GitHub
parent 686576e368
commit 5b5b051e02
2 changed files with 76 additions and 5 deletions
+45 -5
View File
@@ -48,17 +48,57 @@ pub fn delete_selection(app: &mut SolveApp) {
if crate::sketch3d::delete_selected(app) || crate::sketch_tools::delete_glyph(app) {
return;
}
request(app, selection_params(app));
let mut params = selection_params(app);
// In Edit Joint with nothing else selected, Delete means the joint being edited (#3749).
if is_empty(&params)
&& let Some(id) = edited_joint(app)
{
params["joints"] = json!([id]);
}
request(app, params);
}
/// The joint the open Edit Joint dialog edits.
fn edited_joint(app: &SolveApp) -> Option<u64> {
match app.dialog.as_ref().map(|d| &d.kind) {
Some(crate::dialogs::Kind::Assembly(crate::dialogs_assembly::Asm::Joint(f))) => f.editing,
_ => None,
}
}
/// Why a joint cannot be deleted now (the history it changes is busy), if it cannot.
fn joint_delete_blocked(app: &SolveApp) -> Option<&'static str> {
if app.dialog.is_some() {
Some("Close the open dialog before deleting a joint")
} else if app.tool.is_some() {
Some("Finish the active tool before deleting a joint")
} else if app.computing_since().is_some() {
Some("Wait for the design to finish computing before deleting a joint")
} else if app.file_load.busy() {
Some("Wait for the file to finish loading before deleting a joint")
} else {
None
}
}
/// Delete `params` (as `selection.delete` takes them): at once, or after a confirmation when
/// other features go with it or would fail. The dry run that finds out evaluates the history
/// after what is deleted, so it may compute off the window thread (#2678).
pub fn request(app: &mut SolveApp, params: Value) {
if params.get("joints").and_then(Value::as_array).is_some_and(|a| !a.is_empty())
&& (app.dialog.is_some() || app.tool.is_some() || app.computing_since().is_some() || app.file_load.busy())
{
return;
let joints: Vec<u64> = params.get("joints").and_then(Value::as_array).into_iter().flatten().filter_map(Value::as_u64).collect();
if !joints.is_empty() {
// Deleting just the joint Edit Joint edits closes the dialog first, as its Cancel does.
let only_edited = edited_joint(app).is_some_and(|id| joints == [id])
&& ["items", "occurrences", "components", "canvases"]
.iter()
.all(|k| params.get(*k).and_then(Value::as_array).is_none_or(|a| a.is_empty()));
if only_edited && app.applying.is_none() && app.tool.is_none() && app.computing_since().is_none() && !app.file_load.busy() {
crate::dialogs::cancel(app);
}
if let Some(why) = joint_delete_blocked(app) {
app.set_status(why, true);
return;
}
}
if is_empty(&params) {
return;
+31
View File
@@ -274,6 +274,7 @@ mod delete {
assert_eq!(h.app.tree.picked_joints, [hinge]);
crate::delete::delete_selection(&mut h.app);
assert_eq!(h.app.session.doc.assembly.joints.len(), 2, "a dialog must not delete a joint behind it");
assert!(h.app.status.as_ref().is_some_and(|s| s.2 && s.0.contains("dialog")), "the refusal says why");
h.step(&json!({"key": "Escape"})).unwrap();
let hinge = joint(&h, "Hinge");
h.app.tree.picked_joints.clear();
@@ -287,6 +288,36 @@ mod delete {
assert_eq!(features(&h), before);
}
#[test]
fn delete_while_editing_that_joint_closes_edit_joint_and_deletes_it() {
let mut h = assembly();
let before = features(&h);
let hinge = joint(&h, "Hinge");
h.step(&json!({"click": {"handle": "row:Hinge"}, "double": true})).unwrap();
h.frames(3);
let editing = |h: &Harness| match h.app.dialog.as_ref().map(|d| &d.kind) {
Some(crate::dialogs::Kind::Assembly(crate::dialogs_assembly::Asm::Joint(f))) => f.editing,
_ => None,
};
assert_eq!(editing(&h), Some(hinge), "the double click opens Edit Joint");
h.step(&json!({"key": "Delete"})).unwrap();
h.frames(3);
assert!(h.app.dialog.is_none(), "Delete closes the Edit Joint it deletes the joint of");
assert!(h.app.session.doc.assembly.joints.iter().all(|j| j.id != hinge));
assert_eq!(h.app.session.doc.assembly.joints.len(), 1);
assert_eq!(features(&h), before);
h.app.run("edit.undo", json!({})).unwrap();
assert_eq!(h.app.session.doc.assembly.joints.len(), 2);
assert_eq!(features(&h), before);
// The Browser menu's Delete on the same joint goes the same way.
h.app.dialog = crate::dialogs_assembly::edit_joint(&h.app, hinge);
let items = crate::context_menu::items(&h.app, &crate::context_menu::Target::Joint { id: hinge });
let item = items.iter().find(|i| i.label == "Delete").unwrap().clone();
crate::context_menu::run_item(&mut h.app, &item, egui::pos2(0., 0.));
assert!(h.app.dialog.is_none());
assert_eq!(h.app.session.doc.assembly.joints.len(), 1);
}
#[test]
fn a_ctrl_joint_pick_does_not_leave_a_folder_as_the_delete_target() {
let mut h = assembly();