Per-component History hiding (#10393) (#10578)

* claim: #10393

* Per-component History hiding: flag, commands, Browser menu, bar toggle (#10393)

* Carry the new History-hiding strings in the complete catalogs (#10393)

---------

Co-authored-by: Dahak Builds <dahakbuilds@users.noreply.github.com>
This commit is contained in:
Dahak Builds
2026-11-01 11:42:33 +00:00
committed by GitHub
parent 59a40aabc0
commit 7b3d84fb33
9 changed files with 234 additions and 6 deletions
@@ -0,0 +1,50 @@
{
"en": {
"cmd.component_hide_history": "Hide Component History",
"cmd.component_show_history": "Show Component History",
"ui.hide_component_history": "Hide its History",
"ui.show_component_history": "Show its History",
"ui.history_show_hidden": "Show Hidden Components",
"ui.history_hide_hidden": "Hide Hidden Components"
},
"ar": {
"cmd.component_hide_history": "إخفاء سجل المكوّن",
"cmd.component_show_history": "إظهار سجل المكوّن",
"ui.hide_component_history": "إخفاء سجله",
"ui.show_component_history": "إظهار سجله",
"ui.history_show_hidden": "إظهار المكونات المخفية",
"ui.history_hide_hidden": "إخفاء المكونات المخفية"
},
"he": {
"cmd.component_hide_history": "הסתר היסטוריית רכיב",
"cmd.component_show_history": "הצג היסטוריית רכיב",
"ui.hide_component_history": "הסתר את ההיסטוריה שלו",
"ui.show_component_history": "הצג את ההיסטוריה שלו",
"ui.history_show_hidden": "הצג רכיבים מוסתרים",
"ui.history_hide_hidden": "הסתר רכיבים מוסתרים"
},
"ja": {
"cmd.component_hide_history": "コンポーネントの履歴を非表示",
"cmd.component_show_history": "コンポーネントの履歴を表示",
"ui.hide_component_history": "このコンポーネントの履歴を非表示",
"ui.show_component_history": "このコンポーネントの履歴を表示",
"ui.history_show_hidden": "非表示のコンポーネントを表示",
"ui.history_hide_hidden": "非表示のコンポーネントを隠す"
},
"vi": {
"cmd.component_hide_history": "Ẩn lịch sử thành phần",
"cmd.component_show_history": "Hiện lịch sử thành phần",
"ui.hide_component_history": "Ẩn lịch sử của nó",
"ui.show_component_history": "Hiện lịch sử của nó",
"ui.history_show_hidden": "Hiện các thành phần bị ẩn",
"ui.history_hide_hidden": "Ẩn các thành phần bị ẩn"
},
"zh": {
"cmd.component_hide_history": "隐藏组件历史记录",
"cmd.component_show_history": "显示组件历史记录",
"ui.hide_component_history": "隐藏其历史记录",
"ui.show_component_history": "显示其历史记录",
"ui.history_show_hidden": "显示隐藏的组件",
"ui.history_hide_hidden": "隐藏已隐藏的组件"
}
}
+13
View File
@@ -419,6 +419,19 @@ impl Document {
false
}
/// Is `c` (or one of its ancestors) marked out of the History bar (#10393)? The root (0)
/// never is: its own features always show.
pub fn component_history_hidden(&self, mut c: u64) -> bool {
for _ in 0..1000 {
match self.components.iter().find(|x| x.id == c) {
Some(x) if x.history_hidden => return true,
Some(x) if x.parent != 0 => c = x.parent,
_ => return false,
}
}
false
}
/// Would putting a placement of `component` into `parent` put it inside itself: is `parent`
/// the component, or inside it, created in it or placed in it at any depth? Placements can sit
/// apart from where their component was created ([`Self::component_within`] follows only
+5
View File
@@ -2083,6 +2083,11 @@ pub struct Component {
/// Free text properties of the definition (material grade, finish, supplier…), by name.
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub properties: std::collections::BTreeMap<String, String>,
/// Keeps this component's features (and its children's) out of the History bar (#10393).
/// The features still rebuild and the component still shows in the Browser; imported copies
/// whose features only exist to rebuild the copy can carry this flag.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub history_hidden: bool,
}
/// One loft section: profiles of a sketch.
@@ -0,0 +1,5 @@
//! A component marked out of the History bar saves `history_hidden: true` on its component
//! entry, so its features (and its children's) stay out of the History bar while still
//! rebuilding. Older designs carry no such flag and every component shows its features, which
//! is exactly the flag's default; the last release refuses this newer format and asks for an
//! update instead of silently dropping the flag on the next save.
+28
View File
@@ -47,6 +47,10 @@ mod sketches_to_parts;
#[path = "component_transfer.rs"]
mod transfer;
#[cfg(test)]
#[path = "component_history_tests.rs"]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod history_tests;
#[cfg(test)]
#[path = "occurrence_tests.rs"]
#[allow(clippy::unwrap_used, clippy::expect_used)]
@@ -56,6 +60,12 @@ pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("component.cycle_color", "Cycle Component Color", cycle_color)
.icon("colored_components").doc_only()
.params("component: id or name; saves the next identification colour and enables Component Colors; shared by every instance, separate from appearances"),
CommandSpec::new("component.hide_history", "Hide Component History", hide_history)
.icon("eye").doc_only()
.params("component: id or name; keeps the component's features in the design but leaves them out of the History bar (#10393)"),
CommandSpec::new("component.show_history", "Show Component History", show_history)
.icon("eye").doc_only()
.params("component: id or name; puts a component's features back in the History bar after Hide Component History (#10393)"),
CommandSpec::new("component.create", "New Component", new_component)
.at("SOLID", "ASSEMBLE")
.icon("component")
@@ -807,3 +817,21 @@ fn cycle_color(s: &mut Session, p: &Value) -> Result<Value> {
s.colored_components = Some(());
Ok(json!({"component": id, "color": next}))
}
/// Mark a component's features out of the History bar, or back in (#10393). The features still
/// rebuild; only the History bar leaves them out.
fn set_history_hidden(s: &mut Session, p: &Value, hidden: bool) -> Result<Value> {
let cmd = if hidden { "component.hide_history" } else { "component.show_history" };
let id = component(s, p, "component", cmd)?;
let c = s.doc_mut().components.iter_mut().find(|c| c.id == id).ok_or_else(|| bad(cmd, "choose a component below the design root"))?;
c.history_hidden = hidden;
Ok(json!({"component": id, "history_hidden": hidden}))
}
fn hide_history(s: &mut Session, p: &Value) -> Result<Value> {
set_history_hidden(s, p, true)
}
fn show_history(s: &mut Session, p: &Value) -> Result<Value> {
set_history_hidden(s, p, false)
}
@@ -0,0 +1,34 @@
// Per-component History hiding (#10393) through the same commands the Browser menu runs.
use crate::Session;
use serde_json::json;
#[test]
fn hide_and_show_history_mark_the_component_flag_and_undo() {
let mut s = Session::default();
s.execute("component.create", &json!({ "name": "Copy" })).unwrap();
s.execute("component.activate", &json!({ "component": "root" })).unwrap();
assert_eq!(s.execute("component.hide_history", &json!({ "component": "Copy" })).unwrap()["history_hidden"], json!(true));
assert!(s.doc.components.iter().find(|c| c.name == "Copy").unwrap().history_hidden);
assert_eq!(s.execute("component.show_history", &json!({ "component": "Copy" })).unwrap()["history_hidden"], json!(false));
assert!(!s.doc.components.iter().find(|c| c.name == "Copy").unwrap().history_hidden);
// Undo of the show puts the flag back; undo of the hide takes it away.
s.execute("edit.undo", &json!({})).unwrap();
assert!(s.doc.components.iter().find(|c| c.name == "Copy").unwrap().history_hidden);
s.execute("edit.undo", &json!({})).unwrap();
assert!(!s.doc.components.iter().find(|c| c.name == "Copy").unwrap().history_hidden);
}
#[test]
fn hide_history_needs_a_real_component_and_survives_a_save_round_trip() {
let mut s = Session::default();
s.execute("component.create", &json!({ "name": "Copy" })).unwrap();
assert!(s.execute("component.hide_history", &json!({ "component": "root" })).is_err());
s.execute("component.hide_history", &json!({ "component": "Copy" })).unwrap();
// The flag rides in the design JSON and comes back on read.
let json = s.doc.to_json();
let read = solidcraft_doc::Document::from_json(&json).unwrap();
assert!(read.components.iter().find(|c| c.name == "Copy").unwrap().history_hidden);
// A design without the flag reads as shown, as always.
let plain = solidcraft_doc::Document::from_json(&Session::default().doc.to_json()).unwrap();
assert!(!plain.components.iter().any(|c| c.history_hidden));
}
+3
View File
@@ -143,6 +143,9 @@ pub struct TreeState {
/// Find in Timeline: the feature the history scrolls to the next time it draws its items, in
/// the bottom strip or in the history on the left (#5850).
pub timeline_reveal: Option<u64>,
/// Show components marked out of the History bar anyway (#10393). Held by the session, like
/// the bar's Show All toggle; the History controls' menu carries the switch.
pub history_show_hidden: bool,
/// The feature of the face or edge last picked in the view, so a new pick scrolls the
/// history to it once.
pub view_pick: Option<u64>,
+13
View File
@@ -1089,6 +1089,18 @@ fn component_items(app: &SolveApp, id: u64) -> Vec<Item> {
v.push(act("ui.showAll", "Show All Bodies", "eye"));
v.push(act("ui.isolate", "Isolate", "body").with(json!({ "bodies": names })).on(!bodies.is_empty() && id != 0));
v.push(act("ui.newGroup", "New Group", "folder").with(json!({ "component": id })));
if id != 0 {
// Keep the component in the design but leave its features out of the History bar (#10393).
let hidden = doc.component_history_hidden(id);
v.push(
cmd(
app,
if hidden { "component.show_history" } else { "component.hide_history" },
if hidden { "Show its History" } else { "Hide its History" },
)
.with(json!({ "component": id })),
);
}
v.push(Item::sep());
v.push(cmd(app, "browser.expand_all", "Expand All").with(json!({ "component": id })));
v.push(cmd(app, "browser.collapse_all", "Collapse All").with(json!({ "component": id })));
@@ -1686,6 +1698,7 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {
app.set_status(e, true);
}
}
"ui.historyShowHidden" => app.tree.history_show_hidden = p["show"].as_bool().unwrap_or(false),
"ui.workspace" | "ui.workspace.design" | "ui.workspace.render" => {
if let Some(workspace) = p.get("workspace").and_then(Value::as_str)
&& let Err(e) = crate::render_workspace::enter(app, workspace == "render")
+83 -6
View File
@@ -43,11 +43,18 @@ pub(crate) fn transport_response(app: &mut SolveApp, control: crate::ui_kit::His
}
}
/// The History controls' menu: shows or hides the Play button.
/// The History controls' menu: shows or hides the Play button, and — when the design marks any
/// component out of the bar — shows or hides those components' entries (#10393).
pub(crate) fn transport_items(app: &SolveApp) -> Vec<crate::context_menu::Item> {
let show = !app.preferences.history_play_button;
let label = crate::i18n::tr(if show { "ui.history_play_button_show" } else { "ui.history_play_button_hide" });
vec![crate::context_menu::Item::action("ui.historyPlayButton", label, "timeline_play").with(json!({ "show": show }))]
let mut items = vec![crate::context_menu::Item::action("ui.historyPlayButton", label, "timeline_play").with(json!({ "show": show }))];
if app.session.doc.components.iter().any(|c| c.history_hidden) {
let show_hidden = !app.tree.history_show_hidden;
let label = crate::i18n::tr(if show_hidden { "ui.history_show_hidden" } else { "ui.history_hide_hidden" });
items.push(crate::context_menu::Item::action("ui.historyShowHidden", label, "eye").with(json!({ "show": show_hidden })));
}
items
}
/// The feature that made a face, edge or vertex of `body` (its world name): a face's own creator,
@@ -232,9 +239,16 @@ pub(crate) fn timeline_component(app: &SolveApp, show_all: bool) -> Option<u64>
}
/// Indices into the design's features that the timeline shows for `component` (all of them for
/// `None`): the features of that component and of the components inside it.
pub(crate) fn shown_feature_indices(doc: &solidcraft_engine::doc::Document, component: Option<u64>) -> Vec<usize> {
doc.features.iter().enumerate().filter(|(_, f)| component.is_none_or(|c| doc.component_within(f.component, c))).map(|(i, _)| i).collect()
/// `None`): the features of that component and of the components inside it, leaving out the
/// components marked out of the History bar unless `show_hidden` asks for them (#10393).
pub(crate) fn shown_feature_indices(doc: &solidcraft_engine::doc::Document, component: Option<u64>, show_hidden: bool) -> Vec<usize> {
doc.features
.iter()
.enumerate()
.filter(|(_, f)| component.is_none_or(|c| doc.component_within(f.component, c)))
.filter(|(_, f)| show_hidden || !doc.component_history_hidden(f.component))
.map(|(i, _)| i)
.collect()
}
/// The design's feature position for a slot among the shown features: before the shown feature
@@ -841,7 +855,7 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {
let show_all = ui.data(|d| d.get_temp::<bool>(show_all_id)).unwrap_or(false);
let only = timeline_component(app, show_all);
let filtering = only.is_some() || show_all;
let shown = shown_feature_indices(&app.session.doc, only);
let shown = shown_feature_indices(&app.session.doc, only, app.tree.history_show_hidden);
if filtering || app.session.doc.features.iter().any(|f| f.component != 0) {
// A toggle ahead of the features: this part only, or the whole design.
let label = match only {
@@ -1221,6 +1235,69 @@ mod tests {
}
}
#[test]
fn history_hiding_a_component_leaves_its_features_out_of_the_bar() {
use crate::context_menu::{self, Target};
use crate::scenario::handle_at;
let mut h = Harness::new();
h.app.home.open = false;
h.app.run("component.create", json!({ "name": "Copy" })).unwrap();
h.app.run("solid.box", json!({ "length": 10, "width": 10, "height": 10, "name": "CopyBox" })).unwrap();
h.app.run("component.activate", json!({ "component": "root" })).unwrap();
h.app.run("component.create", json!({ "name": "Part" })).unwrap();
h.app.run("solid.box", json!({ "length": 5, "width": 5, "height": 5, "name": "PartBox" })).unwrap();
h.app.run("component.activate", json!({ "component": "root" })).unwrap();
h.frames(4);
assert!(handle_at("timeline:CopyBox").is_some() && handle_at("timeline:PartBox").is_some(), "both parts' features start in the bar");
// The Browser menu offers to hide the copy's History, and running it leaves its entries out.
let copy = h.app.session.doc.components.iter().find(|c| c.name == "Copy").unwrap().id;
let menu = context_menu::items(&h.app, &Target::Component { id: copy });
let hide = menu.iter().find(|i| i.id == "component.hide_history").expect("the component menu offers Hide its History");
context_menu::run_item(&mut h.app, hide, egui::Pos2::ZERO);
h.frames(4);
assert!(handle_at("timeline:CopyBox").is_none(), "the hidden copy leaves the bar");
assert!(handle_at("timeline:PartBox").is_some(), "the rest of the design stays");
// The History controls' menu shows them anyway, and hides them again (#10393).
fn toggle(h: &Harness) -> context_menu::Item {
let items = context_menu::items(&h.app, &Target::HistoryControls);
items.into_iter().find(|i| i.id == "ui.historyShowHidden").expect("the bar offers to show hidden entries").clone()
}
let item = toggle(&h);
context_menu::run_item(&mut h.app, &item, egui::Pos2::ZERO);
h.frames(4);
assert!(handle_at("timeline:CopyBox").is_some(), "the toggle brings the hidden entries back");
let item = toggle(&h);
context_menu::run_item(&mut h.app, &item, egui::Pos2::ZERO);
h.frames(4);
assert!(handle_at("timeline:CopyBox").is_none(), "and hides them again");
// The component menu now offers to show its History back.
let menu = context_menu::items(&h.app, &Target::Component { id: copy });
assert!(menu.iter().any(|i| i.id == "component.show_history"), "the menu flips to Show its History");
}
#[test]
fn shown_feature_indices_leave_out_hidden_components_and_their_children() {
let mut h = Harness::new();
h.app.run("component.create", json!({ "name": "Copy" })).unwrap();
h.app.run("solid.box", json!({ "length": 1, "width": 1, "height": 1, "name": "CopyBox" })).unwrap();
h.app.run("component.create", json!({ "name": "Inner" })).unwrap();
h.app.run("solid.box", json!({ "length": 1, "width": 1, "height": 1, "name": "InnerBox" })).unwrap();
h.app.run("component.activate", json!({ "component": "root" })).unwrap();
h.app.run("component.create", json!({ "name": "Part" })).unwrap();
h.app.run("solid.box", json!({ "length": 1, "width": 1, "height": 1, "name": "PartBox" })).unwrap();
h.app.run("component.activate", json!({ "component": "root" })).unwrap();
h.app.run("component.hide_history", json!({ "component": "Copy" })).unwrap();
let doc = &h.app.session.doc;
let shown = |show_hidden: bool| super::shown_feature_indices(doc, None, show_hidden);
let names = |idx: Vec<usize>| idx.iter().map(|i| doc.features[*i].name.clone()).collect::<Vec<_>>();
assert_eq!(names(shown(false)), ["PartBox"], "a hidden component takes its own and its children's rows out");
assert_eq!(names(shown(true)), ["CopyBox", "InnerBox", "PartBox"], "show-hidden lists everything again");
// The same filter applies when the bar narrows to one component.
let copy = doc.components.iter().find(|c| c.name == "Copy").unwrap().id;
assert!(super::shown_feature_indices(doc, Some(copy), false).is_empty(), "the component filter shows nothing of a hidden component");
assert_eq!(super::shown_feature_indices(doc, Some(copy), true).len(), 2, "Copy owns CopyBox and InnerBox");
}
#[test]
fn history_status_translates_prefixes_and_both_diagnostics() {
let diagnostic = "there is no body to cut or intersect in component 'Mount'; the tool may overlap 'Plate' in component 'Base' — activate that component or pick the body as a target";