Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Modify ▸ Delete with nothing selected asks for a pick instead of a parameter error (#9079) (#9114)

leValdemar1924ce89e0fc44
diff --git a/assets/locales/pending/delete-select-first.json b/assets/locales/pending/delete-select-first.json
new file mode 100644
index 0000000000..c52abbc5b5
--- /dev/null
+++ b/assets/locales/pending/delete-select-first.json
@@ -0,0 +1,10 @@
+{
+ "en": { "ui.delete_select_first": "Select what to delete first: features, bodies, components or sketch geometry" },
+ "ar": { "ui.delete_select_first": "حدّد أولاً ما تريد حذفه: الميزات أو الأجسام أو المكونات أو هندسة الرسم" },
+ "de": { "ui.delete_select_first": "Wählen Sie zuerst aus, was gelöscht werden soll: Features, Körper, Komponenten oder Skizzengeometrie" },
+ "he": { "ui.delete_select_first": "בחרו קודם מה למחוק: תכונות, גופים, רכיבים או גאומטריית סקיצה" },
+ "ja": { "ui.delete_select_first": "先に削除するものを選択してください: フィーチャ、ボディ、コンポーネント、スケッチ ジオメトリ" },
+ "ko": { "ui.delete_select_first": "먼저 삭제할 항목을 선택하세요: 피처, 바디, 컴포넌트 또는 스케치 형상" },
+ "vi": { "ui.delete_select_first": "Hãy chọn trước những gì cần xóa: tính năng, khối, thành phần hoặc hình học phác thảo" },
+ "zh": { "ui.delete_select_first": "请先选择要删除的内容:特征、实体、组件或草图几何" }
+}
diff --git a/crates/ui-egui/src/delete.rs b/crates/ui-egui/src/delete.rs
index ac35f4109e..6b626fc9bb 100644
--- a/crates/ui-egui/src/delete.rs
+++ b/crates/ui-egui/src/delete.rs
@@ -71,6 +71,11 @@ pub fn delete_selection(app: &mut SolveApp) {
request(app, params);
}
+/// Whether Delete has nothing to act on: nothing selected, and no joint open in Edit Joint.
+pub fn nothing_to_delete(app: &SolveApp) -> bool {
+ is_empty(&selection_params(app)) && edited_joint(app).is_none()
+}
+
/// The joint the open Edit Joint dialog edits.
fn edited_joint(app: &SolveApp) -> Option<u64> {
match app.dialog.as_ref().map(|d| &d.kind) {
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index a73479ff8c..f330b40108 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -1533,6 +1533,16 @@ impl SolveApp {
self.repeat_last();
return;
}
+ // Modify ▸ Delete deletes what is selected, as the Delete key does (#9079); with nothing
+ // selected it says what to pick instead of running with no features.
+ if id == "timeline.delete" {
+ if delete::nothing_to_delete(self) && self.tree.picked_timeline_groups.is_empty() {
+ self.set_status(self.tr("ui.delete_select_first"), false);
+ } else if !timeline_left::delete_selected_folders(self) {
+ delete::delete_selection(self);
+ }
+ return;
+ }
// Front … Isometric (Ctrl+1…7 by default) turn the view as the view cube's faces do. The
// flat pattern is a 2D page: it has no other side to turn to.
if solidcraft_engine::standard_view(id).is_some() {
diff --git a/crates/ui-egui/src/menu_tests.rs b/crates/ui-egui/src/menu_tests.rs
index f52ff5e95a..50c819cf46 100644
--- a/crates/ui-egui/src/menu_tests.rs
+++ b/crates/ui-egui/src/menu_tests.rs
@@ -673,6 +673,26 @@ fn delete_key_handles_every_kind_and_asks_about_dependents() {
assert_eq!(app.session.doc.features.len(), n);
}
+/// #9079: Modify ▸ Delete with nothing selected says what to pick, not the command's parameter
+/// error, and changes nothing; with something selected it deletes it, as the Delete key does.
+#[test]
+fn modify_delete_with_nothing_selected_asks_for_a_pick() {
+ let mut app = SolveApp::new(Session::default(), Services::default());
+ app.run("solid.box", json!({"length": 10, "width": 10, "height": 10, "body_name": "Box"})).unwrap();
+ app.run("construct.plane.offset", json!({"base": "XY", "offset": 10})).unwrap();
+ let n = app.session.doc.features.len();
+ app.run("select.clear", json!({})).unwrap();
+ app.start("timeline.delete");
+ let (message, _, error) = app.status.clone().expect("a hint");
+ assert!(!error && message == app.tr("ui.delete_select_first"), "{message:?} error: {error}");
+ assert!(!message.contains('`'), "no parameter names: {message}");
+ assert_eq!(app.session.doc.features.len(), n, "nothing deleted");
+ app.run("select.set", json!({"items": [{"type": "plane", "name": "Plane1"}]})).unwrap();
+ app.start("timeline.delete");
+ assert!(app.session.doc.find_feature("Plane1").is_none(), "the selection goes");
+ assert_eq!(app.session.doc.features.len(), n - 1);
+}
+
#[test]
fn browser_feature_menu_deletes_its_target_and_supports_undo() {
let mut app = SolveApp::new(Session::default(), Services::default());