* claim: #7219 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * History: delete a folder with its features, and suppress a whole folder (#7219) `timeline.delete` and `timeline.suppress` take `groups: [timeline folder ids]`: every feature in those folders and their nested folders, in one undo step. A delete takes the folders themselves too; `timeline.ungroup` still keeps the features. The History on the left offers Suppress/Unsuppress Selected Folders and Delete Folders and Features… (asking first, like Delete Selected Features…, when something outside needs them); a folder whose features are all suppressed is drawn faint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * History folder actions: Arabic, Hebrew and Vietnamese strings (complete catalogs) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,7 +25,7 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
.at("SOLID", "MODIFY")
|
||||
.icon("delete")
|
||||
.key("Delete")
|
||||
.params("feature: id|name | features: [id|name] (one undo step; a sketch takes its dependent features with it) → deleted: [ids]; failing?: [{feature, error}] (later features that worked and now fail)"),
|
||||
.params("feature: id|name | features: [id|name] | groups: [timeline folder ids] (a folder goes with all its features and nested folders; one undo step; a sketch takes its dependent features with it) → deleted: [ids]; groups?: [folder ids deleted]; failing?: [{feature, error}] (later features that worked and now fail)"),
|
||||
CommandSpec::new("timeline.rename", "Rename", rename).icon("rename").params("feature: id|name, name (references to it follow)"),
|
||||
CommandSpec::new("timeline.group", "New Feature Folder", group)
|
||||
.icon("folder")
|
||||
@@ -55,8 +55,9 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
.noundo()
|
||||
.params("feature: id|name → features deleted with it, and features that would fail without it"),
|
||||
CommandSpec::new("timeline.suppress", "Suppress Feature", suppress).icon("suppress").params(
|
||||
"feature: id|name | features: [id|name] (one undo step), suppressed?: bool (default toggles: several features are all \
|
||||
suppressed unless all of them already are, then all are unsuppressed) → feature: id (or features: [ids]), suppressed",
|
||||
"feature: id|name | features: [id|name] | groups: [timeline folder ids] (every feature in those folders and their nested \
|
||||
folders; one undo step), suppressed?: bool (default toggles: several features are all \
|
||||
suppressed unless all of them already are, then all are unsuppressed) → feature: id (or features: [ids]; groups: [ids] when given), suppressed",
|
||||
),
|
||||
CommandSpec::new("timeline.edit", "Edit Feature", edit_feature).icon("edit").params(
|
||||
"feature: id|name, set: {fields to change, merged into the feature's definition as timeline.inspect returns it, \
|
||||
@@ -162,9 +163,13 @@ fn delete(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
_ => String::new(),
|
||||
});
|
||||
}
|
||||
if keys.is_empty() {
|
||||
return Err(bad(cmd, "`features` must list features"));
|
||||
let groups = group_ids(s, p, false, cmd)?;
|
||||
if keys.is_empty() && groups.is_empty() {
|
||||
return Err(bad(cmd, "`features` must list features, or `groups` timeline folders"));
|
||||
}
|
||||
// A folder goes with its features and nested folders, its features in timeline order.
|
||||
let (folders, contents) = group_tree(&s.doc, &groups);
|
||||
keys.extend(s.doc.features.iter().filter(|f| contents.contains(&f.id)).map(|f| f.id.to_string()));
|
||||
// Features that work now; any of them failing after the delete is reported (a later
|
||||
// feature that names a deleted body, #267).
|
||||
let worked: std::collections::BTreeSet<u64> = s.model.results.iter().filter(|r| r.error.is_none() && !r.skipped).map(|r| r.id).collect();
|
||||
@@ -178,6 +183,9 @@ fn delete(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
gone.extend(s.doc_mut().delete_feature(id)?);
|
||||
}
|
||||
if !folders.is_empty() {
|
||||
s.doc_mut().timeline_groups.retain(|group| !folders.contains(&group.id));
|
||||
}
|
||||
if s.active_sketch.is_some_and(|a| gone.contains(&a)) {
|
||||
s.active_sketch = None;
|
||||
}
|
||||
@@ -194,10 +202,14 @@ fn delete(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
.filter(|r| worked.contains(&r.id))
|
||||
.filter_map(|r| r.error.as_ref().map(|e| json!({"feature": r.name, "error": e})))
|
||||
.collect();
|
||||
if failing.is_empty() {
|
||||
return Ok(json!({"deleted": gone}));
|
||||
let mut out = json!({"deleted": gone});
|
||||
if !folders.is_empty() {
|
||||
out["groups"] = json!(folders);
|
||||
}
|
||||
Ok(json!({"deleted": gone, "failing": failing}))
|
||||
if !failing.is_empty() {
|
||||
out["failing"] = json!(failing);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
fn rename(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
@@ -312,6 +324,11 @@ fn group_move_would_cycle(s: &Session, target: u64, sources: &[u64]) -> bool {
|
||||
}
|
||||
|
||||
fn group_feature_ids(doc: &solidcraft_doc::Document, roots: &[u64]) -> std::collections::BTreeSet<u64> {
|
||||
group_tree(doc, roots).1
|
||||
}
|
||||
|
||||
/// The timeline folders `roots` and every folder nested in them, and the features they hold.
|
||||
fn group_tree(doc: &solidcraft_doc::Document, roots: &[u64]) -> (std::collections::BTreeSet<u64>, std::collections::BTreeSet<u64>) {
|
||||
let by_id: std::collections::BTreeMap<u64, &solidcraft_doc::TimelineGroup> = doc.timeline_groups.iter().map(|group| (group.id, group)).collect();
|
||||
let mut children = std::collections::BTreeMap::<u64, Vec<u64>>::new();
|
||||
for group in &doc.timeline_groups {
|
||||
@@ -331,7 +348,7 @@ fn group_feature_ids(doc: &solidcraft_doc::Document, roots: &[u64]) -> std::coll
|
||||
pending.extend(children.get(&id).into_iter().flatten().copied());
|
||||
}
|
||||
}
|
||||
features
|
||||
(visited, features)
|
||||
}
|
||||
|
||||
fn sort_group_features(doc: &mut solidcraft_doc::Document) {
|
||||
@@ -620,7 +637,15 @@ fn counted_names_from(s: &Session, ids: &[u64]) -> Vec<(u64, Vec<String>)> {
|
||||
|
||||
fn suppress(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "timeline.suppress";
|
||||
let ids = feature_ids(s, p, cmd)?;
|
||||
let groups = group_ids(s, p, false, cmd)?;
|
||||
let named = |key: &str| p.get(key).is_some_and(|v| !v.is_null());
|
||||
let mut ids = if groups.is_empty() || named("feature") || named("features") { feature_ids(s, p, cmd)? } else { Vec::new() };
|
||||
let contents = group_feature_ids(&s.doc, &groups);
|
||||
let more: Vec<u64> = s.doc.features.iter().map(|f| f.id).filter(|id| contents.contains(id) && !ids.contains(id)).collect();
|
||||
ids.extend(more);
|
||||
if ids.is_empty() {
|
||||
return Err(bad(cmd, "the timeline folders hold no features"));
|
||||
}
|
||||
let want = match bool_(p, "suppressed") {
|
||||
Some(b) => b,
|
||||
None if p.get("suppressed").is_some_and(|v| !v.is_null()) => return Err(bad(cmd, "`suppressed` must be true or false")),
|
||||
@@ -640,8 +665,9 @@ fn suppress(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
f.suppressed = want;
|
||||
}
|
||||
match ids.as_slice() {
|
||||
[id] if p.get("features").is_none_or(Value::is_null) => Ok(json!({"feature": id, "suppressed": want})),
|
||||
_ => Ok(json!({"features": ids, "suppressed": want})),
|
||||
[id] if groups.is_empty() && p.get("features").is_none_or(Value::is_null) => Ok(json!({"feature": id, "suppressed": want})),
|
||||
_ if groups.is_empty() => Ok(json!({"features": ids, "suppressed": want})),
|
||||
_ => Ok(json!({"features": ids, "groups": groups, "suppressed": want})),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -680,6 +680,108 @@ fn timeline_folders_can_nest_and_reject_cycles() {
|
||||
assert_eq!(s.doc.timeline_groups.iter().find(|group| group.id == child).unwrap().parent, None, "deleting a folder promotes its children");
|
||||
}
|
||||
|
||||
/// Four separate boxes, `First`…`Fourth`, for the timeline folder tests.
|
||||
fn four_boxes() -> Session {
|
||||
let mut s = Session::default();
|
||||
for (i, name) in ["First", "Second", "Third", "Fourth"].into_iter().enumerate() {
|
||||
let corner = [20 * i, 0, 0];
|
||||
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": corner, "operation": "new_body", "name": name}));
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
fn feature_names(s: &Session) -> Vec<String> {
|
||||
s.doc.features.iter().map(|feature| feature.name.clone()).collect()
|
||||
}
|
||||
|
||||
/// `timeline.delete {groups}` deletes a folder with its features and nested folders in one undo
|
||||
/// step; other folders and features stay, and `timeline.ungroup` still keeps the features (#7219).
|
||||
#[test]
|
||||
fn timeline_delete_takes_a_folder_with_its_features_and_nested_folders() {
|
||||
let mut s = four_boxes();
|
||||
let outer = run(&mut s, "timeline.group", json!({"name": "Outer", "features": ["Second"]}))["group"].as_u64().unwrap();
|
||||
let inner = run(&mut s, "timeline.group", json!({"name": "Inner", "features": ["Third"], "parent": outer}))["group"].as_u64().unwrap();
|
||||
let keep = run(&mut s, "timeline.group", json!({"name": "Keep", "features": ["Fourth"]}))["group"].as_u64().unwrap();
|
||||
let before = s.doc.clone();
|
||||
|
||||
let out = run(&mut s, "timeline.delete", json!({"groups": [outer]}));
|
||||
assert_eq!(feature_names(&s), ["First", "Fourth"]);
|
||||
assert_eq!(out["groups"], json!([outer, inner]), "{out}");
|
||||
assert_eq!(s.doc.timeline_groups.iter().map(|group| group.id).collect::<Vec<_>>(), [keep], "the nested folder goes too");
|
||||
assert_eq!(s.model.state().bodies.len(), 2);
|
||||
let reopened = solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap();
|
||||
assert_eq!(reopened.timeline_groups, s.doc.timeline_groups);
|
||||
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert_eq!(s.doc.features, before.features, "one undo step brings the features back");
|
||||
assert_eq!(s.doc.timeline_groups, before.timeline_groups, "and the folders, nested as they were");
|
||||
run(&mut s, "edit.redo", json!({}));
|
||||
assert_eq!(feature_names(&s), ["First", "Fourth"]);
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
|
||||
// A folder and a feature outside it in one delete; an empty folder goes on its own.
|
||||
run(&mut s, "timeline.delete", json!({"groups": [inner], "features": ["First"]}));
|
||||
assert_eq!(feature_names(&s), ["Second", "Fourth"]);
|
||||
assert_eq!(s.doc.timeline_groups.iter().map(|group| group.name.as_str()).collect::<Vec<_>>(), ["Outer", "Keep"]);
|
||||
let empty = run(&mut s, "timeline.group", json!({"name": "Empty"}))["group"].as_u64().unwrap();
|
||||
assert_eq!(run(&mut s, "timeline.delete", json!({"groups": [empty]}))["deleted"], json!([]));
|
||||
assert!(!s.doc.timeline_groups.iter().any(|group| group.id == empty));
|
||||
|
||||
let before = s.doc.clone();
|
||||
for bad in [json!({"groups": [999_999]}), json!({"groups": ["Outer"]}), json!({"groups": 3}), json!({"groups": []})] {
|
||||
assert!(s.execute("timeline.delete", &bad).is_err(), "{bad}");
|
||||
assert_eq!(s.doc, before, "{bad}: a refused delete changes nothing");
|
||||
}
|
||||
}
|
||||
|
||||
/// `timeline.suppress {groups}` suppresses every feature of a folder and its nested folders in
|
||||
/// one undo step, toggles like several features do, and works with the marker inside the
|
||||
/// folder (#7219).
|
||||
#[test]
|
||||
fn timeline_suppress_takes_a_folder_with_its_nested_folders() {
|
||||
let mut s = four_boxes();
|
||||
let outer = run(&mut s, "timeline.group", json!({"name": "Outer", "features": ["Second"]}))["group"].as_u64().unwrap();
|
||||
run(&mut s, "timeline.group", json!({"name": "Inner", "features": ["Third"], "parent": outer}));
|
||||
let suppressed = |s: &Session| s.doc.features.iter().filter(|feature| feature.suppressed).map(|feature| feature.name.clone()).collect::<Vec<_>>();
|
||||
|
||||
let out = run(&mut s, "timeline.suppress", json!({"groups": [outer]}));
|
||||
assert_eq!(out["suppressed"], true);
|
||||
assert_eq!(out["groups"], json!([outer]));
|
||||
assert_eq!(suppressed(&s), ["Second", "Third"]);
|
||||
assert_eq!(s.model.state().bodies.len(), 2);
|
||||
let reopened = solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap();
|
||||
assert_eq!(reopened.features, s.doc.features);
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert!(suppressed(&s).is_empty(), "one undo step");
|
||||
run(&mut s, "edit.redo", json!({}));
|
||||
assert_eq!(suppressed(&s), ["Second", "Third"]);
|
||||
|
||||
// Toggle: all suppressed, so all come back; with one of them active, all are suppressed.
|
||||
run(&mut s, "timeline.suppress", json!({"groups": [outer]}));
|
||||
assert!(suppressed(&s).is_empty());
|
||||
run(&mut s, "timeline.suppress", json!({"feature": "Third"}));
|
||||
run(&mut s, "timeline.suppress", json!({"groups": [outer]}));
|
||||
assert_eq!(suppressed(&s), ["Second", "Third"]);
|
||||
run(&mut s, "timeline.suppress", json!({"groups": [outer], "suppressed": false, "features": ["Fourth"]}));
|
||||
assert!(suppressed(&s).is_empty(), "an explicit state, with a feature outside the folder as well");
|
||||
|
||||
// The marker between the folder's features: the folder is suppressed all the same, and the
|
||||
// marker stays where it was.
|
||||
run(&mut s, "timeline.roll_to", json!({"feature": "Second"}));
|
||||
assert_eq!(s.doc.marker, Some(2));
|
||||
run(&mut s, "timeline.suppress", json!({"groups": [outer], "suppressed": true}));
|
||||
assert_eq!(suppressed(&s), ["Second", "Third"]);
|
||||
assert_eq!(s.doc.marker, Some(2));
|
||||
assert_eq!(s.model.state().bodies.len(), 1, "only First is before the marker and not suppressed");
|
||||
|
||||
let empty = run(&mut s, "timeline.group", json!({"name": "Empty"}))["group"].as_u64().unwrap();
|
||||
let before = s.doc.clone();
|
||||
for bad in [json!({"groups": [empty]}), json!({"groups": [999_999]}), json!({"groups": [outer], "suppressed": "yes"})] {
|
||||
assert!(s.execute("timeline.suppress", &bad).is_err(), "{bad}");
|
||||
assert_eq!(s.doc, before, "{bad}: a refused suppress changes nothing");
|
||||
}
|
||||
}
|
||||
|
||||
/// A field the feature's definition doesn't have is refused with the fields it does have,
|
||||
/// instead of reporting success and changing nothing (#1491).
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user