* 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:
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"en": {
|
||||
"Delete Folders and Features…": "Delete Folders and Features…",
|
||||
"Suppress Selected Folders": "Suppress Selected Folders",
|
||||
"Unsuppress Selected Folders": "Unsuppress Selected Folders",
|
||||
"timeline.delete_folders_with_features_tip": "Delete the folders with every feature in them and their nested folders",
|
||||
"timeline.suppress_folders_tip": "Suppress or unsuppress every feature in the folders and their nested folders"
|
||||
},
|
||||
"de": {
|
||||
"Delete Folders and Features…": "Ordner mit Features löschen…",
|
||||
"Suppress Selected Folders": "Ausgewählte Ordner unterdrücken",
|
||||
"Unsuppress Selected Folders": "Unterdrückung der ausgewählten Ordner aufheben",
|
||||
"timeline.delete_folders_with_features_tip": "Löscht die Ordner mit allen Features darin und ihren Unterordnern",
|
||||
"timeline.suppress_folders_tip": "Unterdrückt alle Features in den Ordnern und ihren Unterordnern oder hebt die Unterdrückung auf"
|
||||
},
|
||||
"ar": {
|
||||
"Delete Folders and Features…": "حذف المجلدات مع ميزاتها…",
|
||||
"Suppress Selected Folders": "تعطيل المجلدات المحددة",
|
||||
"Unsuppress Selected Folders": "إلغاء تعطيل المجلدات المحددة",
|
||||
"timeline.delete_folders_with_features_tip": "حذف المجلدات مع كل الميزات التي فيها والمجلدات المتداخلة فيها",
|
||||
"timeline.suppress_folders_tip": "تعطيل كل الميزات في المجلدات والمجلدات المتداخلة فيها أو إلغاء تعطيلها"
|
||||
},
|
||||
"he": {
|
||||
"Delete Folders and Features…": "מחיקת תיקיות עם הפיצ'רים שבהן…",
|
||||
"Suppress Selected Folders": "השבתת התיקיות שנבחרו",
|
||||
"Unsuppress Selected Folders": "ביטול השבתת התיקיות שנבחרו",
|
||||
"timeline.delete_folders_with_features_tip": "מחיקת התיקיות עם כל הפיצ'רים שבהן והתיקיות המקוננות בהן",
|
||||
"timeline.suppress_folders_tip": "השבתה או ביטול השבתה של כל הפיצ'רים בתיקיות ובתיקיות המקוננות בהן"
|
||||
},
|
||||
"ja": {
|
||||
"Delete Folders and Features…": "フォルダーとフィーチャーを削除…",
|
||||
"Suppress Selected Folders": "選択したフォルダーを抑制",
|
||||
"Unsuppress Selected Folders": "選択したフォルダーの抑制を解除",
|
||||
"timeline.delete_folders_with_features_tip": "フォルダーを、中のすべてのフィーチャーと入れ子のフォルダーごと削除します",
|
||||
"timeline.suppress_folders_tip": "フォルダーと入れ子のフォルダー内のすべてのフィーチャーを抑制、または抑制を解除します"
|
||||
},
|
||||
"vi": {
|
||||
"Delete Folders and Features…": "Xóa thư mục cùng các tính năng…",
|
||||
"Suppress Selected Folders": "Bỏ kích hoạt các thư mục đã chọn",
|
||||
"Unsuppress Selected Folders": "Kích hoạt lại các thư mục đã chọn",
|
||||
"timeline.delete_folders_with_features_tip": "Xóa các thư mục cùng mọi tính năng trong đó và các thư mục lồng bên trong",
|
||||
"timeline.suppress_folders_tip": "Bỏ kích hoạt hoặc kích hoạt lại mọi tính năng trong các thư mục và các thư mục lồng bên trong"
|
||||
},
|
||||
"zh": {
|
||||
"Delete Folders and Features…": "删除文件夹及其特征…",
|
||||
"Suppress Selected Folders": "抑制所选文件夹",
|
||||
"Unsuppress Selected Folders": "取消抑制所选文件夹",
|
||||
"timeline.delete_folders_with_features_tip": "删除文件夹及其中的所有特征和嵌套文件夹",
|
||||
"timeline.suppress_folders_tip": "抑制或取消抑制文件夹及其嵌套文件夹中的所有特征"
|
||||
}
|
||||
}
|
||||
@@ -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]
|
||||
|
||||
@@ -73,8 +73,9 @@ pub struct DeleteCheck {
|
||||
/// What a delete does once its check is in.
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) enum AfterCheck {
|
||||
/// The timeline's Delete of these features (a `timeline.dependents` report for each).
|
||||
Timeline(Vec<u64>),
|
||||
/// The timeline's Delete of these features (a `timeline.dependents` report for each), and
|
||||
/// of the timeline folders that go with them.
|
||||
Timeline { features: Vec<u64>, groups: Vec<u64> },
|
||||
/// Delete with these `selection.delete` parameters (the report of its dry run).
|
||||
Selection(Value),
|
||||
}
|
||||
@@ -83,9 +84,12 @@ impl AfterCheck {
|
||||
/// Check again, for the design as it is now.
|
||||
fn restart(self, app: &mut SolveApp) {
|
||||
match self {
|
||||
AfterCheck::Timeline(ids) => {
|
||||
let ids: Vec<u64> = ids.into_iter().filter(|id| app.session.doc.feature(*id).is_some()).collect();
|
||||
if !ids.is_empty() {
|
||||
AfterCheck::Timeline { features, groups } => {
|
||||
let ids: Vec<u64> = features.into_iter().filter(|id| app.session.doc.feature(*id).is_some()).collect();
|
||||
let groups: Vec<u64> = groups.into_iter().filter(|id| app.session.doc.timeline_groups.iter().any(|g| g.id == *id)).collect();
|
||||
if !groups.is_empty() {
|
||||
crate::timeline::delete_folders(app, groups, ids);
|
||||
} else if !ids.is_empty() {
|
||||
crate::timeline::delete_features(app, ids);
|
||||
}
|
||||
}
|
||||
@@ -96,9 +100,9 @@ impl AfterCheck {
|
||||
/// Carry on with the check's replies.
|
||||
fn finish(self, app: &mut SolveApp, replies: Vec<Result<Value, String>>) {
|
||||
match self {
|
||||
AfterCheck::Timeline(ids) => {
|
||||
AfterCheck::Timeline { features, groups } => {
|
||||
let reports: Vec<Value> = replies.into_iter().map(Result::unwrap_or_default).collect();
|
||||
crate::timeline::delete_checked_features(app, ids, &reports);
|
||||
crate::timeline::delete_checked_features(app, features, groups, &reports);
|
||||
}
|
||||
AfterCheck::Selection(params) => {
|
||||
let report = replies.into_iter().next().unwrap_or_else(|| Err("the delete was not checked".into()));
|
||||
|
||||
@@ -345,6 +345,8 @@ crate::dialog_descriptor::dialog_descriptors! {
|
||||
/// Delete a feature that others depend on.
|
||||
ConfirmDelete {
|
||||
features: Vec<u64>,
|
||||
/// Timeline folders deleted with the features.
|
||||
groups: Vec<u64>,
|
||||
with: Vec<String>,
|
||||
fail: Vec<String>,
|
||||
},
|
||||
@@ -1132,11 +1134,11 @@ impl Dialog {
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn confirm_delete(feature: u64, with: Vec<String>, fail: Vec<String>) -> Dialog {
|
||||
Dialog::confirm_delete_many(vec![feature], with, fail)
|
||||
Dialog::confirm_delete_many(vec![feature], Vec::new(), with, fail)
|
||||
}
|
||||
|
||||
pub fn confirm_delete_many(features: Vec<u64>, with: Vec<String>, fail: Vec<String>) -> Dialog {
|
||||
Dialog::new(Kind::ConfirmDelete { features, with, fail }, vec![])
|
||||
pub fn confirm_delete_many(features: Vec<u64>, groups: Vec<u64>, with: Vec<String>, fail: Vec<String>) -> Dialog {
|
||||
Dialog::new(Kind::ConfirmDelete { features, groups, with, fail }, vec![])
|
||||
}
|
||||
|
||||
pub fn edit_param(s: &Session, name: &str) -> Dialog {
|
||||
@@ -4489,7 +4491,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
}
|
||||
Kind::EditParam { name, expr } => ("parameters.change", json!({"name": name, "expression": expr})),
|
||||
Kind::Rename { feature, name } => ("timeline.rename", json!({"feature": feature, "name": name})),
|
||||
Kind::ConfirmDelete { features, .. } => ("timeline.delete", json!({ "features": features })),
|
||||
Kind::ConfirmDelete { features, groups, .. } => ("timeline.delete", crate::timeline::delete_params(features, groups)),
|
||||
Kind::Sketch | Kind::Measure { .. } => return Ok(Vec::new()),
|
||||
Kind::Assembly(k) => return crate::dialogs_assembly::commands(app, k, &d.inputs),
|
||||
Kind::Sheet(k) => return crate::dialogs_sheet::commands(app, k, &d.inputs, &d.extra),
|
||||
|
||||
@@ -202,11 +202,19 @@ pub(crate) fn delete_feature(app: &mut SolveApp, id: u64) {
|
||||
/// while, #2678), then delete them or ask first.
|
||||
pub(crate) fn delete_features(app: &mut SolveApp, ids: Vec<u64>) {
|
||||
let checks = ids.iter().map(|id| ("timeline.dependents".to_string(), json!({ "feature": id }))).collect();
|
||||
app.check_delete(checks, crate::deferred::AfterCheck::Timeline(ids));
|
||||
app.check_delete(checks, crate::deferred::AfterCheck::Timeline { features: ids, groups: Vec::new() });
|
||||
}
|
||||
|
||||
/// [`delete_features`] once each feature's `timeline.dependents` report is in.
|
||||
pub(crate) fn delete_checked_features(app: &mut SolveApp, ids: Vec<u64>, reports: &[Value]) {
|
||||
/// Delete timeline folders with their features (`contents`, nested folders' included) after the
|
||||
/// same check as [`delete_features`] (#7219).
|
||||
pub(crate) fn delete_folders(app: &mut SolveApp, groups: Vec<u64>, contents: Vec<u64>) {
|
||||
let checks = contents.iter().map(|id| ("timeline.dependents".to_string(), json!({ "feature": id }))).collect();
|
||||
app.check_delete(checks, crate::deferred::AfterCheck::Timeline { features: contents, groups });
|
||||
}
|
||||
|
||||
/// [`delete_features`] once each feature's `timeline.dependents` report is in; `groups` are
|
||||
/// timeline folders deleted with them.
|
||||
pub(crate) fn delete_checked_features(app: &mut SolveApp, ids: Vec<u64>, groups: Vec<u64>, reports: &[Value]) {
|
||||
// Each report is about one feature alone, so it names the others being deleted too: those
|
||||
// go anyway and are left out of the confirmation.
|
||||
let deleting: Vec<&str> = ids.iter().filter_map(|id| app.session.doc.feature(*id)).map(|f| f.name.as_str()).collect();
|
||||
@@ -226,12 +234,17 @@ pub(crate) fn delete_checked_features(app: &mut SolveApp, ids: Vec<u64>, reports
|
||||
}
|
||||
}
|
||||
if with.is_empty() && fail.is_empty() {
|
||||
let _ = app.run_heavy("timeline.delete", json!({ "features": ids }));
|
||||
let _ = app.run_heavy("timeline.delete", delete_params(&ids, &groups));
|
||||
} else {
|
||||
app.dialog = Some(crate::dialogs::Dialog::confirm_delete_many(ids, with.into_iter().collect(), fail.into_iter().collect()));
|
||||
app.dialog = Some(crate::dialogs::Dialog::confirm_delete_many(ids, groups, with.into_iter().collect(), fail.into_iter().collect()));
|
||||
}
|
||||
}
|
||||
|
||||
/// `timeline.delete`'s parameters for these features and timeline folders.
|
||||
pub(crate) fn delete_params(features: &[u64], groups: &[u64]) -> Value {
|
||||
if groups.is_empty() { json!({ "features": features }) } else { json!({ "features": features, "groups": groups }) }
|
||||
}
|
||||
|
||||
/// The selected timeline features, in timeline order.
|
||||
pub(crate) fn selected_feature_ids(app: &SolveApp) -> Vec<u64> {
|
||||
app.session
|
||||
|
||||
@@ -652,6 +652,26 @@ fn selection_actions(app: &mut SolveApp, ui: &mut egui::Ui, groups: &[solidcraft
|
||||
app.tree.picked_timeline_groups.clear();
|
||||
ui.close();
|
||||
}
|
||||
// The folders' own features and those of nested folders, as `timeline.suppress` and
|
||||
// `timeline.delete` take them with `groups` (#7219).
|
||||
let contents = folder_features(app, &selected_groups);
|
||||
let all_suppressed = !contents.is_empty() && contents.iter().all(|id| app.session.doc.feature(*id).is_some_and(|f| f.suppressed));
|
||||
let label = if all_suppressed { "Unsuppress Selected Folders" } else { "Suppress Selected Folders" };
|
||||
if crate::context_menu::button_enabled(ui, label, "suppress", !contents.is_empty())
|
||||
.on_hover_text(crate::i18n::tr("timeline.suppress_folders_tip"))
|
||||
.clicked()
|
||||
{
|
||||
let _ = app.run_heavy("timeline.suppress", json!({"groups": selected_groups, "suppressed": !all_suppressed}));
|
||||
ui.close();
|
||||
}
|
||||
if crate::context_menu::button(ui, "Delete Folders and Features…", "delete")
|
||||
.on_hover_text(crate::i18n::tr("timeline.delete_folders_with_features_tip"))
|
||||
.clicked()
|
||||
{
|
||||
crate::timeline::delete_folders(app, selected_groups.clone(), contents);
|
||||
app.tree.picked_timeline_groups.clear();
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
if !features.is_empty() {
|
||||
ui.separator();
|
||||
@@ -693,6 +713,15 @@ pub fn reveal_feature(app: &mut SolveApp, feature: u64) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The features of these folders and of the folders nested in them, in timeline order.
|
||||
fn folder_features(app: &SolveApp, roots: &[u64]) -> Vec<u64> {
|
||||
let groups = &app.session.doc.timeline_groups;
|
||||
let inside = |feature: u64| {
|
||||
group_for(groups, feature).is_some_and(|group| roots.contains(&group) || roots.iter().any(|root| group_is_descendant(groups, group, *root)))
|
||||
};
|
||||
app.session.doc.features.iter().map(|feature| feature.id).filter(|feature| inside(*feature)).collect()
|
||||
}
|
||||
|
||||
fn group_is_descendant(groups: &[solidcraft_engine::doc::TimelineGroup], group: u64, ancestor: u64) -> bool {
|
||||
let mut current = groups.iter().find(|candidate| candidate.id == group).and_then(|candidate| candidate.parent);
|
||||
let mut steps = 0usize;
|
||||
@@ -843,6 +872,7 @@ fn timeline_group_name(
|
||||
rect: Rect,
|
||||
offset: f32,
|
||||
names: bool,
|
||||
faint: bool,
|
||||
t: &Tokens,
|
||||
) -> bool {
|
||||
let editing =
|
||||
@@ -856,7 +886,7 @@ fn timeline_group_name(
|
||||
egui::Align2::LEFT_CENTER,
|
||||
&group.name,
|
||||
egui::FontId::proportional(crate::theme::Tokens::get().font_body),
|
||||
t.text,
|
||||
if faint { t.text.gamma_multiply(0.42) } else { t.text },
|
||||
);
|
||||
return false;
|
||||
}
|
||||
@@ -926,9 +956,19 @@ fn vertical_group_row(
|
||||
let offset = if names { depth as f32 * 14.0 } else { 0.0 };
|
||||
let centre = pos2(rect.left() + 9.0 + offset, rect.center().y);
|
||||
crate::ui_kit::disclosure(ui.painter(), centre, open, t.text_dim);
|
||||
// A folder whose features are all suppressed looks like a suppressed feature.
|
||||
let contents = folder_features(app, &[group.id]);
|
||||
let suppressed = !contents.is_empty() && contents.iter().all(|id| app.session.doc.feature(*id).is_some_and(|f| f.suppressed));
|
||||
let mut painter = ui.painter().clone();
|
||||
if suppressed {
|
||||
painter.multiply_opacity(0.42);
|
||||
}
|
||||
let icon = Rect::from_center_size(pos2(rect.left() + 27.5 + offset, rect.center().y), vec2(17.0, 17.0));
|
||||
icons::paint_icon(ui.painter(), icon, "folder", f32::from(t.icon.a()) / 255.0);
|
||||
let renaming = timeline_group_name(app, ui, group, rect, offset, names, &t);
|
||||
icons::paint_icon(&painter, icon, "folder", f32::from(t.icon.a()) / 255.0);
|
||||
if suppressed {
|
||||
painter.line_segment([icon.left_bottom(), icon.right_top()], Stroke::new(1.5, t.text_dim));
|
||||
}
|
||||
let renaming = timeline_group_name(app, ui, group, rect, offset, names, suppressed, &t);
|
||||
crate::scenario::publish_handle(&format!("timeline-folder:{}", group.name), rect.center());
|
||||
let fold_rect = Rect::from_min_max(pos2(rect.left() + offset, rect.top()), pos2(rect.left() + offset + 18.0, rect.bottom()));
|
||||
crate::scenario::publish_handle(&format!("timeline-folder-fold:{}", group.name), fold_rect.center());
|
||||
@@ -2213,6 +2253,67 @@ mod tests {
|
||||
assert!(harness.app.session.doc.find_feature("Feature").is_some());
|
||||
}
|
||||
|
||||
/// Right-click a folder and pick a menu entry.
|
||||
fn folder_menu(harness: &mut Harness, folder: &str, entry: &str) {
|
||||
harness.step(&json!({"click": {"handle": format!("timeline-folder:{folder}")}, "button": "right"})).unwrap();
|
||||
let [x, y] = harness.widget(entry).unwrap_or_else(|| panic!("`{entry}` is in the folder's menu"));
|
||||
harness.step(&json!({"click": [x, y]})).unwrap();
|
||||
harness.frames(4);
|
||||
}
|
||||
|
||||
/// A folder's menu suppresses and unsuppresses every feature in it and in its nested folders,
|
||||
/// and deletes the folders with their features in one undo step (#7219).
|
||||
#[test]
|
||||
fn folder_menu_suppresses_and_deletes_the_folder_with_its_features() {
|
||||
let mut harness = Harness::new();
|
||||
harness.app.preferences.timeline_left = true;
|
||||
for (name, x) in [("Outside", 0), ("Inside", 20), ("Nested", 40)] {
|
||||
let params = json!({"length": 10, "width": 10, "height": 10, "corner": [x, 0, 0], "operation": "new_body", "name": name});
|
||||
harness.app.run("solid.box", params).unwrap();
|
||||
}
|
||||
let outer = harness.app.run("timeline.group", json!({"name": "Outer", "features": ["Inside"]})).unwrap()["group"].as_u64().unwrap();
|
||||
harness.app.run("timeline.group", json!({"name": "Inner", "features": ["Nested"], "parent": outer})).unwrap();
|
||||
harness.frames(4);
|
||||
let suppressed = |harness: &Harness| {
|
||||
harness.app.session.doc.features.iter().filter(|feature| feature.suppressed).map(|feature| feature.name.clone()).collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
folder_menu(&mut harness, "Outer", "Suppress Selected Folders");
|
||||
assert_eq!(suppressed(&harness), ["Inside", "Nested"]);
|
||||
folder_menu(&mut harness, "Outer", "Unsuppress Selected Folders");
|
||||
assert!(suppressed(&harness).is_empty(), "the menu offers to unsuppress a folder whose features all are");
|
||||
|
||||
folder_menu(&mut harness, "Outer", "Delete Folders and Features…");
|
||||
let names: Vec<_> = harness.app.session.doc.features.iter().map(|feature| feature.name.as_str()).collect();
|
||||
assert_eq!(names, ["Outside"]);
|
||||
assert!(harness.app.session.doc.timeline_groups.is_empty(), "the nested folder goes too");
|
||||
assert!(harness.app.dialog.is_none(), "nothing outside the folder needed them: no question");
|
||||
harness.app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(harness.app.session.doc.features.len(), 3);
|
||||
assert_eq!(harness.app.session.doc.timeline_groups.len(), 2, "one undo step");
|
||||
}
|
||||
|
||||
/// When a feature outside the folder needs one inside, the delete asks first, and its Delete
|
||||
/// takes the folder as well (#7219).
|
||||
#[test]
|
||||
fn deleting_a_folder_others_depend_on_asks_and_then_takes_the_folder() {
|
||||
let mut harness = Harness::new();
|
||||
harness.app.preferences.timeline_left = true;
|
||||
harness.app.run("solid.box", json!({"length": 10, "width": 10, "height": 10, "name": "Base"})).unwrap();
|
||||
harness.app.run("solid.fillet", json!({"edges": [[10, 5, 10]], "radius": 1, "name": "Round"})).unwrap();
|
||||
harness.app.run("timeline.group", json!({"name": "Stock", "features": ["Base"]})).unwrap();
|
||||
harness.frames(4);
|
||||
|
||||
folder_menu(&mut harness, "Stock", "Delete Folders and Features…");
|
||||
assert!(harness.app.dialog.is_some(), "Round needs Base: the delete asks first");
|
||||
assert!(harness.app.session.doc.find_feature("Base").is_some());
|
||||
let [x, y] = harness.widget("Delete").expect("the confirmation's Delete button");
|
||||
harness.step(&json!({"click": [x, y]})).unwrap();
|
||||
harness.frames(4);
|
||||
assert!(harness.app.session.doc.find_feature("Base").is_none());
|
||||
assert!(harness.app.session.doc.timeline_groups.is_empty(), "the confirmed delete takes the folder too");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collapsed_folder_stays_visible_while_its_contents_hide() {
|
||||
let mut harness = Harness::new();
|
||||
|
||||
@@ -204,6 +204,7 @@ features are computed.
|
||||
|
||||
- **In SolidCraft:** `browser.group`, `browser.ungroup`, `browser.rename_group`; `timeline.group`,
|
||||
`timeline.ungroup`, `timeline.rename_group`, `timeline.move_to_group`; the `group` parameter key;
|
||||
the `groups` parameter of `timeline.delete` and `timeline.suppress` (a group with all its features);
|
||||
the `browser_groups` and `timeline_groups` design-file keys.
|
||||
- **Don't use:** feature folder, folder (for a group).
|
||||
- **Elsewhere:** folder, group.
|
||||
|
||||
Reference in New Issue
Block a user