From d9421bf2ca1993f3471996d65bab0dfaa2c11607 Mon Sep 17 00:00:00 2001 From: JK3D <166923105+JoKa3D@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:29:23 +0000 Subject: [PATCH] Browser: an option to start folders closed and open rows only on request (#8768) (#8771) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * claim: #8768 * feat: Browser folders start closed and find a body only when asked, behind a preference Preferences › Layout › Browser rows start closed (`browser_rows_start_closed`, off by default) starts the Browser's folders closed, and placements too whatever "Components start open" (#9274) says. Rows then open with their arrow, Expand All or Find in Browser, which opens just the rows down to its body and closes again the ones the last find opened. A body picked in the 3D view leaves the Browser as it is, and only the body Find in Browser found has the rows above it marked, so a large assembly's placements are not named again after each edit. With the preference off, folders start open, placements start as "Components start open" says, and a pick in the 3D view opens the Browser down to its body, as on main. Find in Browser looks the body's placement up once and opens its rows before drawing, instead of each row testing the revealed path while it is drawn. * Browser tests: read the row order from the Browser's content frame Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: bherbruck Co-authored-by: Claude Opus 5.5 --- .../pending/browser-find-on-demand.json | 34 ++ crates/ui-egui/src/browser.rs | 296 +++++++++++------- crates/ui-egui/src/browser/features.rs | 127 ++++++-- crates/ui-egui/src/browser/point_clouds.rs | 8 +- crates/ui-egui/src/browser_model.rs | 6 + crates/ui-egui/src/browser_model_tests.rs | 108 +++++++ crates/ui-egui/src/context_menu.rs | 3 +- crates/ui-egui/src/dialogs_assembly.rs | 5 +- crates/ui-egui/src/documents.rs | 1 + crates/ui-egui/src/occurrence_ui_tests.rs | 33 ++ crates/ui-egui/src/prefs.rs | 9 + crates/ui-egui/src/prefs/interface.rs | 8 + crates/ui-egui/src/render_workspace.rs | 2 + crates/ui-egui/src/timeline.rs | 19 +- docs/book/src/guide/ui-tour.md | 6 +- docs/picked-face-navigation.md | 2 + 16 files changed, 520 insertions(+), 147 deletions(-) create mode 100644 assets/locales/pending/browser-find-on-demand.json diff --git a/assets/locales/pending/browser-find-on-demand.json b/assets/locales/pending/browser-find-on-demand.json new file mode 100644 index 000000000..d0b322813 --- /dev/null +++ b/assets/locales/pending/browser-find-on-demand.json @@ -0,0 +1,34 @@ +{ + "en": { + "prefs.browser_rows_start_closed": "Browser rows start closed", + "prefs.browser_rows_start_closed_note": "Placements and folders in the Browser start closed, so a design with many components shows its top-level rows. Each opens with its arrow, Expand All or Find in Browser, which opens just the rows down to its body and closes again the ones the last find opened. A body picked in the 3D view leaves the Browser as it is. When off, folders start open, placements start as Components start open says, and a pick in the 3D view opens the Browser down to its body, as before." + }, + "ar": { + "prefs.browser_rows_start_closed": "صفوف المستعرض تبدأ مغلقة", + "prefs.browser_rows_start_closed_note": "تبدأ المواضع والمجلدات في المستعرض مغلقة، فيعرض التصميم الذي يضم مكونات كثيرة صفوفه العليا. يُفتح كل صف بسهمه أو بـ«توسيع الكل» أو بـ«البحث في المستعرض» الذي يفتح الصفوف المؤدية إلى الجسم فقط، ويغلق من جديد الصفوف التي فتحها البحث السابق. اختيار جسم في العرض ثلاثي الأبعاد يترك المستعرض كما هو. عند إيقافه تبدأ المجلدات مفتوحة، وتبدأ المواضع كما يحدّد خيار «المكوّنات مفتوحة من البداية»، ويفتح الاختيار في العرض ثلاثي الأبعاد المستعرضَ حتى صف الجسم، كما كان من قبل." + }, + "de": { + "prefs.browser_rows_start_closed": "Browser-Zeilen beginnen geschlossen", + "prefs.browser_rows_start_closed_note": "Platzierungen und Ordner im Browser beginnen geschlossen, sodass ein Entwurf mit vielen Komponenten seine obersten Zeilen zeigt. Jede öffnet sich mit ihrem Pfeil, „Alle ausklappen“ oder „Im Browser suchen“, das nur die Zeilen bis zu seinem Körper öffnet und die von der letzten Suche geöffneten wieder schließt. Ein in der 3D-Ansicht gewählter Körper lässt den Browser, wie er ist. Ist es aus, beginnen die Ordner geöffnet, Platzierungen so, wie „Komponenten zu Beginn aufgeklappt“ es festlegt, und eine Auswahl in der 3D-Ansicht öffnet den Browser bis zu ihrem Körper, wie bisher." + }, + "he": { + "prefs.browser_rows_start_closed": "שורות עץ התכן מוצגות סגורות", + "prefs.browser_rows_start_closed_note": "מיקומים ותיקיות בעץ התכן מוצגים סגורים, כך שתכן עם רכיבים רבים מציג את השורות העליונות שלו. כל שורה נפתחת בחץ שלה, ב„הרחבת הכול” או ב„איתור בעץ התכן”, שפותח רק את השורות שמובילות לגוף שלו וסוגר שוב את אלה שהאיתור הקודם פתח. גוף שנבחר בתצוגה התלת־ממדית משאיר את עץ התכן כפי שהוא. כשהאפשרות כבויה התיקיות מוצגות פתוחות, המיקומים מוצגים כפי שקובעת האפשרות „רכיבים פתוחים מההתחלה”, ובחירה בתצוגה התלת־ממדית פותחת את עץ התכן עד לגוף שלה, כמו קודם." + }, + "ja": { + "prefs.browser_rows_start_closed": "ブラウザーの行を閉じた状態で始める", + "prefs.browser_rows_start_closed_note": "ブラウザーの配置とフォルダーを閉じた状態で表示するため、多数のコンポーネントを含むデザインでは最上位の行だけが表示されます。各行は矢印、「すべて展開」または「ブラウザで検索」で開きます。「ブラウザで検索」はボディまでの行だけを開き、前回の検索で開いた行を再び閉じます。3Dビューでボディを選んでもブラウザーはそのままです。オフのときはフォルダーが開いた状態で始まり、配置は「コンポーネントを最初から展開」の設定に従い、3Dビューで選ぶとブラウザーがそのボディまで開きます(以前と同じ)。" + }, + "ko": { + "prefs.browser_rows_start_closed": "브라우저 행을 접힌 상태로 시작", + "prefs.browser_rows_start_closed_note": "브라우저의 배치와 폴더가 접힌 상태로 시작하므로, 컴포넌트가 많은 디자인은 최상위 행만 보여 줍니다. 각 행은 화살표, '모두 펼치기' 또는 '브라우저에서 찾기'로 엽니다. '브라우저에서 찾기'는 바디까지의 행만 열고, 지난번 찾기로 연 행은 다시 접습니다. 3D 뷰에서 바디를 골라도 브라우저는 그대로입니다. 끄면 폴더가 펼친 상태로 시작하고, 배치는 '구성요소를 펼친 상태로 시작' 설정을 따르며, 3D 뷰에서 고르면 브라우저가 그 바디까지 열립니다(이전과 같음)." + }, + "vi": { + "prefs.browser_rows_start_closed": "Các dòng trong cây thư mục đóng sẵn", + "prefs.browser_rows_start_closed_note": "Vị trí đặt và thư mục trong cây thư mục bắt đầu ở trạng thái đóng, nên thiết kế có nhiều thành phần chỉ hiện các dòng cấp trên cùng. Mỗi dòng mở bằng mũi tên của nó, “Mở rộng tất cả” hoặc “Tìm trong cây đối tượng”, lệnh này chỉ mở các dòng dẫn tới thân khối và đóng lại các dòng mà lần tìm trước đã mở. Chọn một thân khối trong khung nhìn 3D không làm thay đổi cây thư mục. Khi tắt, các thư mục mở sẵn, vị trí đặt theo tùy chọn “Thành phần mở sẵn”, và việc chọn trong khung nhìn 3D mở cây thư mục tới thân khối đó, như trước đây." + }, + "zh": { + "prefs.browser_rows_start_closed": "浏览器中的行默认折叠", + "prefs.browser_rows_start_closed_note": "浏览器中的放置和文件夹默认折叠,因此包含大量组件的设计只显示顶层行。每一行可通过其箭头、“全部展开”或“在浏览器中查找”打开;“在浏览器中查找”只展开通往该实体的行,并重新折叠上次查找展开的行。在 3D 视图中选取实体不会改变浏览器。关闭时文件夹默认展开,放置按“组件初始展开”的设置显示,在 3D 视图中选取会使浏览器展开到该实体,与以前相同。" + } +} diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs index eb8c664a4..c84c1c87d 100644 --- a/crates/ui-egui/src/browser.rs +++ b/crates/ui-egui/src/browser.rs @@ -32,49 +32,104 @@ pub(crate) fn reveal_feature(app: &mut SolveApp, id: u64, body: &str) { features::reveal(app, id, body); } -/// Find in Browser for a body: open every row that holds it (the document, the placements down -/// to it, its Bodies folder and any group around it) and scroll its row into view. The rows -/// are opened here, not while drawing, because a collapsed ancestor never draws its children. +/// Whether folders start open: unless Preferences › Layout › Browser rows start closed is on, +/// when they, and placements whatever "Components start open" says ([`placement_open`]), open +/// with their arrow, Find in Browser or Expand All (#8768). The design's own row always starts +/// open. +pub(crate) fn rows_start_open(app: &SolveApp) -> bool { + !app.preferences.browser_rows_start_closed +} + +/// Whether the Browser follows the 3D view: a body picked there opens the Browser down to its row +/// (#3005), and the rows above what is selected or under the pointer are marked (#3009). It does +/// while the rows start open; while they start closed, only Find in Browser opens them. +fn follows_view(app: &SolveApp) -> bool { + rows_start_open(app) +} + +/// Find in Browser for a body: show the Browser and find the body there ([`find_in_tree`]). pub(crate) fn reveal_body(app: &mut SolveApp, body: &str) { sync_reveals(app); app.ui.show_browser = true; app.preferences.timeline_left_browser_collapsed = false; + find_in_tree(app, body); +} + +/// What the last Find in Browser found. +struct Found { + /// The body, by its name in the world. + body: String, + /// The placement it is in (empty for a body of the design itself). + path: Vec, + /// The selection the find left: the path lights the rows above the body until it changes. + selection: Vec, +} + +/// Open the rows that hold a body and no others: the document, the placements down to it, its +/// Bodies folder and any group around it. While the rows start closed, the rows the last find +/// opened close again, unless they were opened or closed by hand since or are on this path. The +/// body's row is scrolled into view, and the path lights the rows leading to it. The path is +/// looked up once, here: the rows are opened before drawing, because a closed row never draws +/// what is inside it. +fn find_in_tree(app: &mut SolveApp, body: &str) { app.tree.reveal_feature = None; app.tree.reveal = Some(body.to_string()); remember_reveal_source(app, body); - let state = app.session.model.state(); - let Some(source) = crate::open_meshing::session_world(&app.session).body(body).map(|selected| selected.definition_name().to_string()) else { - return; - }; - let Some(component) = state.body(&source).map(|definition| definition.component) else { return }; - // Every component's first placement keeps the definition's name, so the owner must match too. - let Some((_, path, _)) = app - .session - .doc - .placements() - .into_iter() - .find(|(owner, path, _)| *owner == component && app.session.doc.world_body_name(&state, &source, *owner, path) == body) - else { - return; - }; - app.tree.collapsed.remove("c0"); - for depth in 1..=path.len() { - app.tree.open_row(&occurrence_key(&path[..depth])); - } + let Some((component, source, path)) = body_placement(app, body) else { return }; + let start_open = rows_start_open(app); + // A body of the design itself is in no placement: its folder is the design's (`c0`). let scope = if path.is_empty() { format!("c{component}") } else { occurrence_key(&path) }; - app.tree.open_row(&scope); - app.tree.collapsed.remove(&format!("{scope}/bodies")); - open_group_chain(app, &scope, component, "bodies", &source); + let mut rows = vec![("c0".to_string(), true)]; + rows.extend((1..=path.len()).map(|depth| (occurrence_key(&path[..depth]), start_open))); + rows.push((format!("{scope}/bodies"), start_open)); + rows.extend(group_chain(app, component, "bodies", &source).into_iter().map(|id| (format!("{scope}/g{id}"), start_open))); + // Rows that start open stay open after a find, as they always have: only rows that start + // closed close again at the next one. + if start_open { + app.tree.found_rows.clear(); + } + let mut opened = Vec::new(); + for (key, default) in std::mem::take(&mut app.tree.found_rows) { + if rows.iter().any(|(row, _)| *row == key) { + opened.push((key, default)); + } else { + set_open(app, &key, default, false); + } + } + for (key, default) in rows { + if set_open(app, &key, default, true) && !start_open { + opened.push((key, default)); + } + } + app.tree.found_rows = opened; + app.tree.found = Some(Found { body: body.to_string(), path, selection: app.session.selection.clone() }); } -/// Open the group holding an item, and the groups holding that one. -fn open_group_chain(app: &mut SolveApp, scope: &str, component: u64, folder: &str, key: &str) { - let mut at = app.session.doc.group_of_item(component, folder, key).map(|g| g.id); - for _ in 0..=solidcraft_engine::doc::MAX_GROUP_NESTING { - let Some(id) = at else { return }; - app.tree.collapsed.remove(&if scope.is_empty() { format!("g{id}") } else { format!("{scope}/g{id}") }); - at = app.session.doc.browser_group(id).and_then(|g| g.parent); - } +/// Another design is shown: the rows the last Find in Browser opened were that design's, and the +/// next Find leaves this one's rows as they are. +pub(crate) fn forget_found(app: &mut SolveApp) { + app.tree.found_rows.clear(); + app.tree.found = None; +} + +/// The placement a body (by its world name) is in: its component, its name in that component and +/// the placement's path. One look through the placements. +fn body_placement(app: &SolveApp, body: &str) -> Option<(u64, String, Vec)> { + let source = crate::open_meshing::session_world(&app.session).body(body).map(|selected| selected.definition_name().to_string())?; + let component = app.session.model.state().body(&source).map(|definition| definition.component)?; + let path = placement_named(app, &source, component, body)?; + Some((component, source, path)) +} + +/// The path of the placement of `component` in which its body `source` has the world name +/// `body`. Every component's first placement keeps the definition's name, so the owner must +/// match too. The design is indexed once for the look, so a component placed many times costs +/// its placements, not its placements times the design. +pub(crate) fn placement_named(app: &SolveApp, source: &str, component: u64, body: &str) -> Option> { + let state = app.session.model.state(); + let doc = &app.session.doc; + let names = solidcraft_engine::doc::WorldNames::new(doc, &state); + doc.placements().into_iter().find(|(owner, path, _)| *owner == component && names.name(source, component, path) == body).map(|(_, path, _)| path) } pub(crate) fn reveal_in_history(app: &mut SolveApp, id: u64) { @@ -113,18 +168,24 @@ pub fn drawn_occurrences() -> Vec { pub struct TreeState { /// Geometry and assembly queries, independent of the camera, selection and row visibility. model: Option, - /// Folders closed by the user (keys like `c0/bodies`). + /// Rows closed by the user (keys like `c0/bodies`): read for rows that start open. pub collapsed: BTreeSet, - /// Folders opened by the user (folders that start closed). + /// Rows opened by the user: read for rows that start closed. A row opened or closed by hand + /// is written to both sets ([`set_open`]), so it keeps its state whichever way it starts. pub expanded: BTreeSet, /// Scroll to this body's row (by the name it has in the world, which tells the placements - /// of a part apart) and open the components, placements and folders above it: Find in - /// Browser, and a body picked in the viewport (#3005). + /// of a part apart): Find in Browser, and a body picked in the viewport while the Browser + /// follows the 3D view (#3005). [`find_in_tree`] opens the rows above it. pub reveal: Option, /// Enough provenance to distinguish temporary rollback/suppression from target removal. reveal_source: Option, /// Runtime owner of the active pending requests, including requests with numeric IDs. reveal_session: Option, + /// The rows the last Find in Browser opened (key, starts open), for the next one to close + /// again. A row opened or closed by hand since leaves the list. + found_rows: Vec<(String, bool)>, + /// What the last Find in Browser found, until the selection changes. + found: Option, /// A native feature to reveal in its placed component's Features folder (Find in Timeline). pub(super) reveal_feature: Option, /// The Move/Copy panel of an occurrence. @@ -616,6 +677,15 @@ pub fn selection_group(app: &SolveApp, target: &Target) -> Option { (sel.len() > 1).then(|| json!({ "component": comp, "folder": folder, "items": sel })) } +/// The group holding an item in a component's folder, then the groups holding that one, out to the +/// folder. +fn group_chain(app: &SolveApp, component: u64, folder: &str, key: &str) -> Vec { + let doc = &app.session.doc; + std::iter::successors(doc.group_of_item(component, folder, key).map(|g| g.id), |id| doc.browser_group(*id).and_then(|g| g.parent)) + .take(solidcraft_engine::doc::MAX_GROUP_NESTING + 1) + .collect() +} + /// Group actions from the menus. pub fn group_action(app: &mut SolveApp, action: &str, p: &Value) { match action { @@ -627,11 +697,13 @@ pub fn group_action(app: &mut SolveApp, action: &str, p: &Value) { if let Ok(r) = app.run("browser.group", json!({ "component": comp, "folder": folder, "items": items, "parent": parent })) && let Some(g) = r.get("group").and_then(Value::as_u64) { + // The new group shows open, in its open folder and group. + let start_open = rows_start_open(app); if let Some(parent) = parent { - app.tree.collapsed.remove(&format!("c{comp}/g{parent}")); + set_open(app, &format!("c{comp}/g{parent}"), start_open, true); } - app.tree.collapsed.remove(&format!("c{comp}/{folder}")); - app.tree.collapsed.remove(&format!("c{comp}/g{g}")); + set_open(app, &format!("c{comp}/{folder}"), start_open, true); + set_open(app, &format!("c{comp}/g{g}"), start_open, true); } } "ui.ungroup" => { @@ -766,16 +838,15 @@ pub(crate) fn picked_body(sel: &Sel) -> Option<&str> { } } -/// A pick in the viewport: the Browser, when shown, opens down to the picked body's row and -/// scrolls to it (#3005). The body of the last item picked. +/// A pick in the viewport, while the Browser is shown and follows the 3D view ([`follows_view`]): +/// the Browser finds the body of the last item picked, as Find in Browser does (#3005). pub(crate) fn reveal_pick(app: &mut SolveApp) { sync_reveals(app); - if app.ui.show_browser - && let Some(body) = app.session.selection.last().and_then(picked_body) + if follows_view(app) + && app.ui.show_browser + && let Some(body) = app.session.selection.last().and_then(picked_body).map(str::to_string) { - let body = body.to_owned(); - remember_reveal_source(app, &body); - app.tree.reveal = Some(body); + find_in_tree(app, &body); } } @@ -787,13 +858,13 @@ fn remember_reveal_source(app: &mut SolveApp, body: &str) { }); } -/// The placement path of the body being revealed, resolved once per model: a row opens when -/// the body's path runs through it, instead of every row expanding its subtree to test -/// containment (#7502). `None` when nothing is revealed or the body is a top-level design body. -fn reveal_path(app: &mut SolveApp) -> Option> { - let body = body_reveal(app)?.to_owned(); - prepare_model(app); - app.tree.model.as_mut()?.body_path(&app.session, &body) +/// Opens the design row and every placement down to `path` (Find in Timeline). +pub(crate) fn open_path(app: &mut SolveApp, path: &[u64]) { + set_open(app, "c0", true, true); + let start_open = rows_start_open(app); + for depth in 1..=path.len() { + set_open(app, &occurrence_key(&path[..depth]), start_open, true); + } } /// A placement's own row (`o:1/2`), not a folder under it (`o:1/2/bodies`). @@ -802,9 +873,10 @@ pub(crate) fn is_placement_key(key: &str) -> bool { } /// Whether a placement's row is open. Placements start closed, so a large assembly opens as a -/// short list (#9274); the "Components start open" preference keeps them open as before. +/// short list (#9274); the "Components start open" preference keeps them open as before, unless +/// the Browser's rows start closed ([`rows_start_open`]). pub(crate) fn placement_open(app: &SolveApp, key: &str) -> bool { - !app.tree.collapsed.contains(key) && (app.preferences.browser_components_open || app.tree.expanded.contains(key)) + !app.tree.collapsed.contains(key) && ((app.preferences.browser_components_open && rows_start_open(app)) || app.tree.expanded.contains(key)) } pub(crate) fn is_open(app: &SolveApp, key: &str, default: bool) -> bool { @@ -814,40 +886,32 @@ pub(crate) fn is_open(app: &SolveApp, key: &str, default: bool) -> bool { if default { !app.tree.collapsed.contains(key) } else { app.tree.expanded.contains(key) } } -pub(crate) fn toggle(app: &mut SolveApp, key: &str, default: bool) { - if is_placement_key(key) { - if placement_open(app, key) { - app.tree.close_row(key); - } else { - app.tree.open_row(key); - } - } else if default { - if !app.tree.collapsed.remove(key) { - app.tree.collapsed.insert(key.to_string()); - } - } else if !app.tree.expanded.remove(key) { +/// Open or close a row, whichever way it starts; whether that changed it. +fn set_open(app: &mut SolveApp, key: &str, default: bool, open: bool) -> bool { + let was = is_open(app, key, default); + if open { + app.tree.collapsed.remove(key); app.tree.expanded.insert(key.to_string()); + } else { + app.tree.collapsed.insert(key.to_string()); + app.tree.expanded.remove(key); } + was != open } -/// Apply Expand All / Collapse All: open-by-default keys live in `collapsed` when closed; -/// closed-by-default keys live in `expanded` when open. Placements, whichever way they start, -/// are noted in both. +/// A row opened or closed by hand: the next Find in Browser leaves it as it is. +pub(crate) fn toggle(app: &mut SolveApp, key: &str, default: bool) { + app.tree.found_rows.retain(|(row, _)| row != key); + let open = is_open(app, key, default); + set_open(app, key, default, !open); +} + +/// Apply Expand All / Collapse All to the rows the command listed, whichever way each starts. +/// They count as folded by hand: the next Find in Browser leaves them as they are. pub fn apply_fold(app: &mut SolveApp, open: bool, open_by_default: &[String], closed_by_default: &[String]) { - if open { - for key in open_by_default { - app.tree.open_row(key); - } - for key in closed_by_default { - app.tree.expanded.insert(key.clone()); - } - } else { - for key in open_by_default { - app.tree.close_row(key); - } - for key in closed_by_default { - app.tree.expanded.remove(key); - } + app.tree.found_rows.retain(|(row, _)| !open_by_default.contains(row) && !closed_by_default.contains(row)); + for key in open_by_default.iter().chain(closed_by_default) { + set_open(app, key, false, open); } } @@ -940,15 +1004,25 @@ impl Lit { Some(Hit::ConstructionPoint { name }) => Some(Thing::Point(name.clone())), None => None, }; + // Unless the Browser follows the 3D view, a body's placement is not looked up for the rows + // above it (that names every placement again after each edit): only the one Find in + // Browser found is known, until the selection changes. + let follows = follows_view(app); + if app.tree.found.as_ref().is_some_and(|found| found.selection != app.session.selection) { + app.tree.found = None; + } let doc = app.session.doc.clone(); let (mut paths, mut components) = (Vec::new(), Vec::new()); for thing in selected.iter().chain(&hovered) { match thing { - Thing::Body(b) => { + Thing::Body(b) if follows => { if let Some(path) = app.tree.model.as_mut().and_then(|model| model.body_path(&app.session, b)) { paths.push(path); } } + Thing::Body(b) => { + paths.extend(app.tree.found.as_ref().filter(|found| found.body == *b && !found.path.is_empty()).map(|found| found.path.clone())); + } Thing::Sketch(id) => { components.extend(doc.features.iter().find(|f| f.id == *id && matches!(f.kind, FeatureKind::Sketch { .. })).map(|f| f.component)) } @@ -1629,14 +1703,6 @@ fn component_rows_inner( return; } let key = &root.key; - let reveal = body_reveal(app).map(str::to_owned); - if let Some(body) = reveal.as_ref() { - let reveals = - cache.root_bodies.contains(body) || reveal_path(app).is_some_and(|rp| root.children.iter().any(|path| rp.starts_with(path.as_slice()))); - if reveals { - app.tree.collapsed.remove(key); - } - } let open = is_open(app, key, true); let active = app.session.active_component == id; let bodies = &cache.root_bodies; @@ -1790,9 +1856,6 @@ fn occurrence_rows_inner( placement: &mut cache::Node, ) { let key = &placement.key; - if reveal_path(app).is_some_and(|rp| rp.starts_with(path)) { - app.tree.open_row(key); - } let open = is_open(app, key, true); let on_screen = ui.is_rect_visible(row_rect(ui)); let active = app.session.active_occurrence_path.as_deref() == Some(path) @@ -2197,14 +2260,15 @@ fn analysis_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &mut // Each eye is its own: the folder's never follows the section's, nor the other way round. let (folder_shown, section_shown) = (!app.tree.analysis_hidden, !app.tree.section_hidden); let key = "analysis"; - let open = is_open(app, key, true); + let start_open = rows_start_open(app); + let open = is_open(app, key, start_open); let r = draw_row( ui, ui.id().with(key), &Row { depth, fold: Some(open), eye: Some(folder_shown), icon: "folder", label: "Analysis", dim: !folder_shown, ..Default::default() }, ); if r.fold || r.clicked { - toggle(app, key, true); + toggle(app, key, start_open); } if r.eye { app.tree.analysis_hidden = folder_shown; @@ -2287,7 +2351,8 @@ fn canvas_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &mut A return; } let key = "canvases"; - let open = is_open(app, key, true); + let start_open = rows_start_open(app); + let open = is_open(app, key, start_open); // The folder's eye is its own: each canvas keeps its eye while the folder hides them all. let shown = !app.session.folder_hidden(CANVASES); let r = draw_row( @@ -2296,7 +2361,7 @@ fn canvas_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &mut A &Row { depth, fold: Some(open), eye: Some(shown), icon: "folder", label: "Canvases", dim: !shown, ..Default::default() }, ); if r.fold || r.clicked { - toggle(app, key, true); + toggle(app, key, start_open); } if r.eye { toggle_folder(app, CANVASES); @@ -2758,21 +2823,14 @@ fn folder_rows_at( let fstatic = folder_static(folder); let key = &data.key; let prefix = key.rsplit_once('/').map_or(key.as_str(), |(prefix, _)| prefix); - if let Some(r) = body_reveal(app) - && folder == "bodies" - && let Some(e) = data.entries().find(|e| e.row_key.strip_prefix("b:") == Some(r)) - { - app.tree.collapsed.remove(key); - app.tree.collapsed.remove(&format!("c{comp}")); - open_group_chain(app, "", comp, "bodies", &e.key); - } // A folded folder draws no row: its groups and items move up into its place, and their own // eyes, hover and drops do its jobs. It is always open, as nothing could open it again. let render = crate::render_workspace::active(app); let folded = !render && folder == "bodies" && bodies_folded(app, comp, prefix, data.count); + let start_open = rows_start_open(app); // With the history in the browser the sketches are there too: their folder starts closed. - let default_open = !(folder == "sketches" && app.preferences.history_in_browser); - let open = folded || is_open(app, key, default_open); + let folder_start_open = start_open && !(folder == "sketches" && app.preferences.history_in_browser); + let open = folded || is_open(app, key, folder_start_open); let inner = if folded { depth } else { depth + 1 }; // The folder's eye is its own: hiding it hides its items without changing theirs, and its // items never change it. It and everything in it fade while it or a placement above is @@ -2799,14 +2857,14 @@ fn folder_rows_at( ) }; if r.fold { - toggle(app, key, default_open); + toggle(app, key, folder_start_open); } else if r.clicked { // The Bodies label is the whole set while a command is asking for bodies. The arrow // still folds it. With no such command, the label folds, as it always has. let names: Vec = data.entries().flat_map(|e| e.bodies.clone()).collect(); if !offer_bodies(app, &names, Take::Toggle) { pick_folder(app, key); - toggle(app, key, default_open); + toggle(app, key, folder_start_open); } } if r.eye { @@ -2869,6 +2927,7 @@ fn folder_level( acts: &mut Actions, ) { let render = crate::render_workspace::active(app); + let start_open = rows_start_open(app); // The render workspace has always listed a folder's loose items above its groups. let items_first = render && holder.is_none(); let rows = rows @@ -2884,7 +2943,7 @@ fn folder_level( cache::Row::Group(g) => g, }; let (id, gkey) = (group.id, &group.key); - let gopen = is_open(app, gkey, true); + let gopen = is_open(app, gkey, start_open); let gshown = !app.session.folder_hidden(gkey); let group_faded = faded || !gshown; let label = if render { @@ -2910,12 +2969,12 @@ fn folder_level( }, ); if r.fold { - toggle(app, gkey, true); + toggle(app, gkey, start_open); } else if r.clicked { let names: Vec = group.entries().into_iter().flat_map(|e| e.bodies.clone()).collect(); if !offer_bodies(app, &names, Take::Toggle) { pick_folder(app, gkey); - toggle(app, gkey, true); + toggle(app, gkey, start_open); } } if r.eye { @@ -3044,7 +3103,8 @@ fn entry_row( } app.tree.remember(&e.row_key); let pattern_key = e.patterns.as_deref(); - let patterns_open = pattern_key.is_some_and(|key| is_open(app, key, true)); + let start_open = rows_start_open(app); + let patterns_open = pattern_key.is_some_and(|key| is_open(app, key, start_open)); let rect = row_rect(ui); let revealed = folder == "bodies" && body_reveal(app).is_some_and(|b| e.row_key.strip_prefix("b:") == Some(b)); if !ui.is_rect_visible(rect) && !patterns_open && !revealed { @@ -3101,7 +3161,7 @@ fn entry_row( if r.fold && let Some(key) = pattern_key { - toggle(app, key, true); + toggle(app, key, start_open); } if folder == "bodies" && body_reveal(app).is_some_and(|b| e.row_key.strip_prefix("b:") == Some(b)) diff --git a/crates/ui-egui/src/browser/features.rs b/crates/ui-egui/src/browser/features.rs index 4d1d9b434..aeda44b73 100644 --- a/crates/ui-egui/src/browser/features.rs +++ b/crates/ui-egui/src/browser/features.rs @@ -28,25 +28,14 @@ pub(crate) fn reveal(app: &mut SolveApp, id: u64, body: &str) { return; // Sketches are listed in Sketches, not Features. } let component = feature.component; - let state = app.session.model.state(); - let world = crate::open_meshing::session_world(&app.session); - let Some(source) = world.body(body).map(|selected| selected.definition_name()) else { return }; - let Some((_, path, _)) = app - .session - .doc - .placements() - .into_iter() - .find(|(owner, path, _)| *owner == component && app.session.doc.world_body_name(&state, source, component, path) == body) - else { + let Some(source) = crate::open_meshing::session_world(&app.session).body(body).map(|selected| selected.definition_name().to_string()) else { return; }; + let Some(path) = super::placement_named(app, &source, component, body) else { return }; app.ui.show_browser = true; app.preferences.timeline_left_browser_collapsed = false; app.tree.reveal = None; - app.tree.collapsed.remove("c0"); - for depth in 1..=path.len() { - app.tree.open_row(&occurrence_key(&path[..depth])); - } + super::open_path(app, &path); let scope = if path.is_empty() { format!("c{component}") } else { occurrence_key(&path) }; app.tree.open_row(&scope); app.tree.expanded.insert(format!("{scope}/features")); @@ -67,13 +56,15 @@ pub(crate) fn reveal_in_history(app: &mut SolveApp, id: u64) { .unwrap_or_else(|| app.session.doc.first_path(component)) }; app.ui.show_browser = true; - app.tree.collapsed.remove("c0"); + // Opened whichever way each row starts (Preferences › Layout can start rows closed). + let start_open = rows_start_open(app); + set_open(app, "c0", true, true); for depth in 1..=path.len() { - app.tree.open_row(&occurrence_key(&path[..depth])); + set_open(app, &occurrence_key(&path[..depth]), start_open, true); } let scope = if path.is_empty() { format!("c{component}") } else { occurrence_key(&path) }; - app.tree.open_row(&scope); - app.tree.collapsed.remove(&format!("{scope}/history")); + set_open(app, &scope, path.is_empty() || start_open, true); + set_open(app, &format!("{scope}/history"), true, true); app.tree.reveal_feature = Some(Reveal { id, path, history: true }); } @@ -803,6 +794,106 @@ mod tests { assert!(!crate::scenario::handles("status:error:Features").is_empty(), "a folder on screen shows its mark"); } + /// Whether a row is open, read the way it starts (the design's row open, the others as the + /// preference says). + fn row_open(app: &SolveApp, key: &str) -> bool { + is_open(app, key, key == "c0" || rows_start_open(app)) + } + + /// While the Browser's rows start closed (Preferences › Layout, #8768), Find in Browser + /// opens the rows down to the body it finds and no others, and lights them from the path it + /// found, without walking the placements again. The next find closes the rows the last one + /// opened, but not rows opened or closed by hand since. + #[test] + fn browser_find_opens_only_the_found_bodys_rows_and_the_next_find_closes_them() { + let mut h = Harness::new(); + assert_eq!(h.call("ui.prefs", json!({"browser_rows_start_closed": true}))["ok"], true); + // Part placed twice, through two placements of Assembly, and Leaf inside Other. + let assembly = h.app.run("component.create", json!({"name":"Assembly"})).unwrap()["occurrence"].as_u64().unwrap(); + let part = h.app.run("component.create", json!({"name":"Part"})).unwrap()["occurrence"].as_u64().unwrap(); + h.app.run("solid.box", json!({"length":40,"width":30,"height":20,"body_name":"Plate"})).unwrap(); + let copy = h.app.run("occurrence.copy", json!({"occurrence":assembly,"translate":[70,25,10]})).unwrap()["occurrence"].as_u64().unwrap(); + h.app.run("component.activate", json!({"component":0})).unwrap(); + let other = h.app.run("component.create", json!({"name":"Other"})).unwrap()["occurrence"].as_u64().unwrap(); + let leaf = h.app.run("component.create", json!({"name":"Leaf"})).unwrap()["occurrence"].as_u64().unwrap(); + h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"corner":[0,90,0],"body_name":"Pin"})).unwrap(); + h.app.run("component.activate", json!({"component":0})).unwrap(); + h.app.ui.show_browser = true; + let (first, second, pin) = (vec![assembly, part], vec![copy, part], vec![other, leaf]); + let mut rows = Vec::new(); + for path in [&first, &second, &pin] { + rows.extend([occurrence_key(&path[..1]), occurrence_key(path), format!("{}/bodies", occurrence_key(path))]); + } + h.frames(2); + assert!(rows.iter().all(|key| !row_open(&h.app, key)), "placements and folders start closed"); + let plate = h.app.session.occurrence_bodies(&second, false).unwrap()[0].clone(); + let first_plate = h.app.session.occurrence_bodies(&first, false).unwrap()[0].clone(); + find_in_browser(&mut h.app, face(&plate)); + let opened: Vec<&String> = rows.iter().filter(|key| row_open(&h.app, key)).collect(); + assert_eq!(opened, rows[3..6].iter().collect::>(), "only the rows down to the body open"); + h.frames(2); + assert!(h.app.tree.reveal.is_none(), "the body row was drawn and scrolled to"); + assert!( + h.app.tree.content.owner(crate::semantic_content::ContentOwner::BROWSER).unwrap().order.contains(&format!("b:{plate}")) + && !h.app.tree.content.owner(crate::semantic_content::ContentOwner::BROWSER).unwrap().order.contains(&format!("b:{first_plate}")) + ); + h.app.viewport.hover = None; + assert_eq!(Lit::of(&mut h.app).paths, std::slice::from_ref(&second), "the rows above the found body are marked"); + assert!(!h.app.tree.model.as_ref().unwrap().body_paths_walked(), "from the path found once"); + + // By hand: the first Assembly opens, and Part in the second is closed and opened again. + crate::test_support::click(&mut h, &format!("fold:occurrence:{assembly}")); + let part_row = format!("fold:occurrence:{copy}/{part}"); + crate::test_support::click(&mut h, &part_row); + crate::test_support::click(&mut h, &part_row); + assert!(row_open(&h.app, &rows[0]) && row_open(&h.app, &rows[4])); + + let pin_body = h.app.session.occurrence_bodies(&pin, false).unwrap()[0].clone(); + find_in_browser(&mut h.app, face(&pin_body)); + let open: Vec = rows.iter().map(|key| row_open(&h.app, key)).collect(); + assert_eq!( + open, + [true, false, false, false, true, false, true, true, true], + "the second Assembly and Part's Bodies close again; the rows opened by hand stay open: {rows:?}" + ); + assert!(row_open(&h.app, "c0")); + h.frames(2); + assert!( + h.app.tree.reveal.is_none() + && h.app.tree.content.owner(crate::semantic_content::ContentOwner::BROWSER).unwrap().order.contains(&format!("b:{pin_body}")) + ); + h.app.viewport.hover = None; + assert_eq!(Lit::of(&mut h.app).paths, std::slice::from_ref(&pin)); + h.app.run("select.clear", json!({})).unwrap(); + assert!(Lit::of(&mut h.app).paths.is_empty(), "the marks go with the selection"); + assert!(!h.app.tree.found_rows.is_empty()); + // Another design's tab: a Find there leaves the rows of this one alone. + crate::documents::new_tab(&mut h.app); + assert!(h.app.tree.found_rows.is_empty() && h.app.tree.found.is_none(), "the rows found belong to the other design"); + } + + /// While the Browser's rows start closed, the History's Find in Browser finds the feature's + /// body as the body's own Find in Browser does: the Browser shows, and only the rows down to + /// the body open. + #[test] + fn history_find_in_browser_opens_the_rows_down_to_the_features_body() { + let mut h = Harness::new(); + assert_eq!(h.call("ui.prefs", json!({"browser_rows_start_closed": true}))["ok"], true); + let assembly = h.app.run("component.create", json!({"name":"Assembly"})).unwrap()["occurrence"].as_u64().unwrap(); + let part = h.app.run("component.create", json!({"name":"Part"})).unwrap()["occurrence"].as_u64().unwrap(); + let feature = h.app.run("solid.box", json!({"length":40,"width":30,"height":20,"body_name":"Plate"})).unwrap()["feature"].as_u64().unwrap(); + h.app.run("component.activate", json!({"component":0})).unwrap(); + let path = [assembly, part]; + let rows = [occurrence_key(&path[..1]), occurrence_key(&path), format!("{}/bodies", occurrence_key(&path))]; + h.app.ui.show_browser = false; + crate::timeline::find_in_browser(&mut h.app, feature); + assert!(h.app.ui.show_browser); + assert!(rows.iter().all(|key| row_open(&h.app, key)), "{rows:?}"); + assert_eq!(h.app.session.selection, [Sel::Body { name: "Plate".into() }]); + h.frames(2); + assert!(h.app.tree.reveal.is_none(), "the body row was drawn and scrolled to"); + } + #[test] fn browser_find_reveals_a_placed_body_whose_row_is_off_screen() { let mut h = Harness::new(); diff --git a/crates/ui-egui/src/browser/point_clouds.rs b/crates/ui-egui/src/browser/point_clouds.rs index 2c17627f3..294798e40 100644 --- a/crates/ui-egui/src/browser/point_clouds.rs +++ b/crates/ui-egui/src/browser/point_clouds.rs @@ -10,7 +10,7 @@ use serde_json::{Value, json}; use solidcraft_engine::doc::point_cloud::{COORDINATES, ColorBy, Filter, Keep, MAX_FILTERS, Names, PLAIN, PointCloud, UNITS, byte, label_color}; use solidcraft_engine::view::POINT_CLOUDS_FOLDER; -use super::{Actions, Row, draw_row, is_open, panel_pos, toggle, toggle_folder}; +use super::{Actions, Row, draw_row, is_open, panel_pos, rows_start_open, toggle, toggle_folder}; use crate::SolveApp; use crate::context_menu::{Item, Target}; use crate::ui_kit; @@ -189,7 +189,9 @@ pub(super) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &m return; } let key = "point_clouds"; - let open = is_open(app, key, true); + // Like the other folders, it starts closed while the Browser's rows do (Preferences › Layout). + let start_open = rows_start_open(app); + let open = is_open(app, key, start_open); // The folder's eye is its own: each cloud keeps its eye while the folder hides them all. let shown = !app.session.folder_hidden(POINT_CLOUDS_FOLDER); let r = draw_row( @@ -198,7 +200,7 @@ pub(super) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &m &Row { depth, fold: Some(open), eye: Some(shown), icon: "folder", label: "Point Clouds", dim: !shown, ..Default::default() }, ); if r.fold || r.clicked { - toggle(app, key, true); + toggle(app, key, start_open); } if r.eye { toggle_folder(app, POINT_CLOUDS_FOLDER); diff --git a/crates/ui-egui/src/browser_model.rs b/crates/ui-egui/src/browser_model.rs index 9b116b6db..4f80ce058 100644 --- a/crates/ui-egui/src/browser_model.rs +++ b/crates/ui-egui/src/browser_model.rs @@ -107,4 +107,10 @@ impl Model { } self.body_paths.as_ref()?.get(body).cloned() } + + /// Whether [`Model::body_path`] has walked the placements for this model. + #[cfg(test)] + pub fn body_paths_walked(&self) -> bool { + self.body_paths.is_some() + } } diff --git a/crates/ui-egui/src/browser_model_tests.rs b/crates/ui-egui/src/browser_model_tests.rs index a562ace07..2f2dc8bb1 100644 --- a/crates/ui-egui/src/browser_model_tests.rs +++ b/crates/ui-egui/src/browser_model_tests.rs @@ -116,6 +116,114 @@ fn a_face_picked_in_the_viewport_opens_the_browser_to_its_placements_body() { ); } +/// #8768: by default the Browser's folders start open, as before, and placements as "Components +/// start open" says (#9274): with it on, a placement lists its body at once. Browser rows start +/// closed (Preferences › Layout) closes the rows nobody opened, placements too whatever +/// "Components start open" says, and turning it off again opens them. +#[test] +fn browser_rows_start_closed_closes_placements_even_with_components_start_open() { + let (mut h, _, occurrence) = fixture(); + assert!(!h.app.preferences.browser_rows_start_closed, "off by default"); + assert_eq!(h.call("ui.prefs", json!({"browser_components_open": true}))["ok"], true); + let body = super::model_placement(&mut h.app, &[occurrence]).unwrap().bodies[0].world.clone(); + let row = format!("b:{body}"); + h.app.ui.show_browser = true; + h.frames(2); + assert!( + h.app.tree.content.owner(crate::semantic_content::ContentOwner::BROWSER).unwrap().order.contains(&row), + "the placement starts open and lists its body" + ); + assert_eq!(h.call("ui.prefs", json!({"browser_rows_start_closed": true}))["ok"], true); + h.frames(2); + assert!( + !h.app.tree.content.owner(crate::semantic_content::ContentOwner::BROWSER).unwrap().order.contains(&row), + "with the preference on, the placement starts closed" + ); + assert_eq!(h.call("ui.prefs", json!({"browser_rows_start_closed": false}))["ok"], true); + h.frames(2); + assert!(h.app.tree.content.owner(crate::semantic_content::ContentOwner::BROWSER).unwrap().order.contains(&row), "off again, it is open again"); +} + +/// #8768: while the Browser's rows start closed (Preferences › Layout), a pick in the 3D view +/// opens, closes and scrolls nothing, and neither the pick nor a body under the pointer has its +/// placement looked up to mark the rows above it: on a large assembly that lookup names every +/// placement again after each edit. With the preference off again, the rows above the hovered +/// body are marked (#3009); a picked face marks its feature's row, not its body's (#9848). +#[test] +fn a_pick_in_the_viewport_leaves_the_browser_alone_while_its_rows_start_closed() { + let (mut h, _, occurrence) = fixture(); + assert_eq!(h.call("ui.prefs", json!({"browser_rows_start_closed": true}))["ok"], true); + let copy = h.app.run("occurrence.copy", json!({"occurrence":occurrence,"translate":[50,0,0]})).unwrap()["occurrence"].as_u64().unwrap(); + let second = super::model_placement(&mut h.app, &[copy]).unwrap().bodies[0].world.clone(); + h.app.ui.show_browser = true; + // Both placements open by hand, their Bodies folders closed as they start. + h.app.tree.expanded.extend([super::occurrence_key(&[occurrence]), super::occurrence_key(&[copy])]); + h.frames(2); + let (collapsed, expanded, order) = ( + h.app.tree.collapsed.clone(), + h.app.tree.expanded.clone(), + h.app.tree.content.owner(crate::semantic_content::ContentOwner::BROWSER).unwrap().order.clone(), + ); + let point = solidcore_record::Vec3::new(55.0, 5.0, 10.0); + crate::viewport::select(&mut h.app, Some(Sel::Face { body: second.clone(), index: 0, point }), false, false); + assert!(h.app.tree.reveal.is_none(), "nothing to scroll to"); + h.frames(3); + assert!(!h.app.session.selection.is_empty(), "the face is picked"); + assert_eq!((&h.app.tree.collapsed, &h.app.tree.expanded), (&collapsed, &expanded), "every row stays open or closed as it was"); + assert_eq!(h.app.tree.content.owner(crate::semantic_content::ContentOwner::BROWSER).unwrap().order, order, "the same rows are drawn"); + h.app.viewport.hover = Some(crate::viewport::Hit::Face { body: second.clone(), index: 0, point }); + let lit = super::Lit::of(&mut h.app); + assert!(lit.paths.is_empty(), "no row above the picked or hovered body is marked: {:?}", lit.paths); + assert!(!h.app.tree.model.as_ref().unwrap().body_paths_walked(), "the placements were not walked for the pick or the pointer"); + assert_eq!(h.call("ui.prefs", json!({"browser_rows_start_closed": false}))["ok"], true); + // The call's frames took the hover from the pointer, which is elsewhere. + h.app.viewport.hover = Some(crate::viewport::Hit::Face { body: second.clone(), index: 0, point }); + let lit = super::Lit::of(&mut h.app); + assert_eq!(lit.paths, [vec![copy]], "the placement above the hovered body; the picked face marks its feature"); +} + +/// #8768: while the Browser's rows start closed, a new design's Bodies and Sketches folders list +/// nothing until their arrow opens them, and Find in Browser opens the Bodies folder that holds +/// the body it finds. +#[test] +fn with_rows_starting_closed_a_designs_folders_open_with_their_arrow_or_find_in_browser() { + let mut h = crate::scenario::Harness::new(); + assert_eq!(h.call("ui.prefs", json!({"browser_rows_start_closed": true}))["ok"], true); + h.app.run("sketch.create", json!({"plane":"XY","name":"Sketch1"})).unwrap(); + h.app.run("sketch.finish", json!({})).unwrap(); + h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Block"})).unwrap(); + h.app.ui.show_browser = true; + h.frames(2); + let drawn = |label: &str| super::drawn_rows().iter().any(|row| row.0 == label); + let body_row = "b:Block".to_string(); + assert!(drawn("Bodies") && drawn("Sketches"), "the folders are listed"); + assert!(!super::is_open(&h.app, "c0/bodies", false) && !super::is_open(&h.app, "c0/sketches", false)); + assert!( + !h.app.tree.content.owner(crate::semantic_content::ContentOwner::BROWSER).unwrap().order.contains(&body_row), + "the body's row is closed away" + ); + assert!(!drawn("Sketch1"), "so is the sketch's"); + click(&mut h, "fold:Sketches"); + h.frames(1); + assert!(drawn("Sketch1"), "the arrow opens the Sketches folder"); + assert!( + !h.app.tree.content.owner(crate::semantic_content::ContentOwner::BROWSER).unwrap().order.contains(&body_row), + "the Bodies folder stays closed" + ); + + crate::context_menu::run_item( + &mut h.app, + &crate::context_menu::Item::action("ui.findBrowser", "", "").with(json!({"body":"Block"})), + egui::Pos2::ZERO, + ); + h.frames(2); + assert!(super::is_open(&h.app, "c0/bodies", false), "Find in Browser opens the Bodies folder"); + assert!( + h.app.tree.content.owner(crate::semantic_content::ContentOwner::BROWSER).unwrap().order.contains(&body_row) && h.app.tree.reveal.is_none(), + "and scrolls to the body's row" + ); +} + /// Hovering a placement row lights its whole subtree: the subtree is walked once per model, not /// on every frame the pointer stays on the row (#3892: a nested STEP assembly cost a frame per /// thousand placements while the pointer was over the tree, even with the rows collapsed). diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rs index e9ea4bf17..3a5246f48 100644 --- a/crates/ui-egui/src/context_menu.rs +++ b/crates/ui-egui/src/context_menu.rs @@ -1588,8 +1588,9 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) { } "ui.findBrowser" => { if let Some(b) = p.get("body").and_then(Value::as_str) { - crate::browser::reveal_body(app, b); + // Selected first: the rows above the body stay marked until the selection changes. let _ = app.run("select.set", json!({"items": [{"type": "body", "name": b}]})); + crate::browser::reveal_body(app, b); } } "ui.findTimeline" => { diff --git a/crates/ui-egui/src/dialogs_assembly.rs b/crates/ui-egui/src/dialogs_assembly.rs index 66959144b..3e34c1d41 100644 --- a/crates/ui-egui/src/dialogs_assembly.rs +++ b/crates/ui-egui/src/dialogs_assembly.rs @@ -1921,7 +1921,8 @@ pub fn browser_joints(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize) { // `eye:Joints`, `row:`). The folder's eye is its own: hiding it hides every joint's // glyph without changing each joint's eye. let key = "c0/joints"; - let open = is_open(app, key, true); + let start_open = crate::browser::rows_start_open(app); + let open = is_open(app, key, start_open); let folder_shown = !app.session.folder_hidden(key); let r = draw_row( ui, @@ -1931,7 +1932,7 @@ pub fn browser_joints(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize) { if r.eye { crate::browser::toggle_folder(app, key); } else if r.fold || r.clicked { - toggle(app, key, true); + toggle(app, key, start_open); } if !open { return; diff --git a/crates/ui-egui/src/documents.rs b/crates/ui-egui/src/documents.rs index 5cb1d31c9..87c1c3585 100644 --- a/crates/ui-egui/src/documents.rs +++ b/crates/ui-egui/src/documents.rs @@ -279,6 +279,7 @@ fn swap_in(app: &mut SolveApp, mut slot: DocSlot) -> DocSlot { pending.view_changed(before, app.session.revision); } app.jobs_view_changed(before, app.session.revision); + crate::browser::forget_found(app); put_work(app, slot.work, before); out } diff --git a/crates/ui-egui/src/occurrence_ui_tests.rs b/crates/ui-egui/src/occurrence_ui_tests.rs index 069fb80fd..67be957d8 100644 --- a/crates/ui-egui/src/occurrence_ui_tests.rs +++ b/crates/ui-egui/src/occurrence_ui_tests.rs @@ -462,6 +462,39 @@ fn bodies_folders_fold_by_the_preference_but_never_the_designs_or_a_hidden_one() /// deep, with no Bodies row, even when that folder was closed while it was still drawn (nothing /// could open it again). Always draws the folder, closed as it was left, then open with the body /// two levels under the placement. +/// #8768: while the Browser's rows start closed (Preferences › Layout), a placement's contents +/// stay hidden until its arrow opens it, even with "Components start open" on (#9274), Find in +/// Browser opens the placements holding its body, and Collapse All and Expand All close and open +/// them. +#[test] +fn placements_start_closed_with_the_preference_and_find_in_browser_opens_the_path_to_its_body() { + let mut h = Harness::new(); + assert_eq!(h.call("ui.prefs", json!({"browser_components_open": true, "browser_rows_start_closed": true}))["ok"], true); + let outer = h.app.run("component.create", json!({"name":"Frame"})).unwrap()["occurrence"].as_u64().unwrap(); + let inner = h.app.run("component.create", json!({"name":"Part"})).unwrap()["occurrence"].as_u64().unwrap(); + h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Deep"})).unwrap(); + h.app.run("component.activate", json!({"component":0})).unwrap(); + h.frames(3); + let row = |path: &str| crate::scenario::handle_at(&format!("row:occurrence:{path}")); + assert!(row(&outer.to_string()).is_some(), "the top-level placement shows"); + assert!(row(&format!("{outer}/{inner}")).is_none(), "a placement's contents stay hidden until it is opened"); + click(&mut h, &[outer], "fold"); + assert!(row(&format!("{outer}/{inner}")).is_some(), "opening a placement shows its children"); + click(&mut h, &[outer], "fold"); + assert!(row(&format!("{outer}/{inner}")).is_none(), "closing it hides them again"); + let deep = h.app.session.occurrence_bodies(&[outer, inner], false).unwrap()[0].clone(); + crate::browser::reveal_body(&mut h.app, &deep); + h.frames(3); + assert!(h.app.tree.expanded.contains(&format!("o:{outer}")) && h.app.tree.expanded.contains(&format!("o:{outer}/{inner}"))); + assert!(row(&format!("{outer}/{inner}")).is_some(), "Find in Browser opened the placements holding the body"); + h.app.run("browser.collapse_all", json!({})).unwrap(); + h.frames(3); + assert!(row(&format!("{outer}/{inner}")).is_none(), "Collapse All closes the placements"); + h.app.run("browser.expand_all", json!({})).unwrap(); + h.frames(3); + assert!(row(&format!("{outer}/{inner}")).is_some(), "Expand All opens them"); +} + #[test] fn a_folded_body_sits_one_level_under_its_nested_placement() { use crate::prefs::BodiesFolders; diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index d56e70a63..c5c44e6be 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -1384,6 +1384,14 @@ preference_settings! { /// Every component placement in the browser starts open, as before #9274, instead of closed /// until the user opens it. Off by default. browser_components_open: bool = false, PAGE_LAYOUT; + /// Folders in the Browser start closed, and placements too whatever "Components start open" + /// says, and they open only on request (#8768): with their arrow, Expand All or Find in + /// Browser, which opens just the rows down to its body and closes again the ones the last find + /// opened. A body picked in the 3D view leaves the Browser as it is, and only the body Find in + /// Browser found has the rows above it marked, so a large assembly's placements are not named + /// again after each edit. Off by default: folders start open, placements as "Components start + /// open" says, and a pick in the 3D view opens the Browser down to its body (#3005), as before. + browser_rows_start_closed: bool = false, PAGE_LAYOUT; /// The wheel zooms toward the point under the cursor (else toward the view's centre). zoom_to_cursor: bool = true, PAGE_NAVIGATION => check("Zoom to the cursor", "The wheel zooms toward the point under the cursor (off: toward the view's center)"); /// Speed multiplier for wheel zoom, independent of the 3D mouse. @@ -6111,6 +6119,7 @@ mod tests { ("status_bar", json!(true), PAGE_LAYOUT), ("browser_eye_left", json!(true), PAGE_LAYOUT), ("browser_components_open", json!(true), PAGE_LAYOUT), + ("browser_rows_start_closed", json!(true), PAGE_LAYOUT), ("quick_measure", json!(true), PAGE_GRAPHICS), ("origin_plane_names", json!("top_front_right"), PAGE_DESIGN), ("direct_interaction", json!(true), PAGE_TOOLS), diff --git a/crates/ui-egui/src/prefs/interface.rs b/crates/ui-egui/src/prefs/interface.rs index 45313f046..8ec94b623 100644 --- a/crates/ui-egui/src/prefs/interface.rs +++ b/crates/ui-egui/src/prefs/interface.rs @@ -405,6 +405,14 @@ pub(super) fn layout(app: &mut SolveApp, ui: &mut egui::Ui) { &mut app.preferences.browser_components_open, "browser_components_open", ); + // Folders and placements start closed and open only on request (#8768). + layout_check( + ui, + app.tr("prefs.browser_rows_start_closed"), + app.tr("prefs.browser_rows_start_closed_note"), + &mut app.preferences.browser_rows_start_closed, + "browser_rows_start_closed", + ); layout_check( ui, app.tr("prefs.browser_eye_left"), diff --git a/crates/ui-egui/src/render_workspace.rs b/crates/ui-egui/src/render_workspace.rs index a334fec2f..b0d985cf5 100644 --- a/crates/ui-egui/src/render_workspace.rs +++ b/crates/ui-egui/src/render_workspace.rs @@ -758,6 +758,8 @@ pub(crate) fn select_stage(app: &mut SolveApp, key: &str) { if stage == Stage::Look { app.tree.collapsed.remove("c0"); app.tree.collapsed.remove("c0/bodies"); + // The Bodies folder starts closed while the Browser's rows do (Preferences › Layout). + app.tree.expanded.insert("c0/bodies".into()); } } diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rs index 09e45d8aa..0117193b7 100644 --- a/crates/ui-egui/src/timeline.rs +++ b/crates/ui-egui/src/timeline.rs @@ -1287,12 +1287,23 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) { }); } -/// Select what a feature made, so the browser shows it. -fn find_in_browser(app: &mut SolveApp, id: u64) { +/// Select what a feature made, so the browser shows it. While the browser's rows start closed +/// (Preferences › Layout), its first body is also found there, as Find in Browser on a body +/// does: the rows down to it open. +pub(crate) fn find_in_browser(app: &mut SolveApp, id: u64) { let st = crate::open_meshing::session_world(&app.session); - let bodies: Vec = st.bodies.iter().filter(|b| b.feature == id).map(|b| json!({"type": "body", "name": b.name})).collect(); - let items = if bodies.is_empty() { vec![json!({"type": "feature", "id": id})] } else { bodies }; + let bodies: Vec = st.bodies.iter().filter(|b| b.feature == id).map(|b| b.name.clone()).collect(); + let items: Vec = if bodies.is_empty() { + vec![json!({"type": "feature", "id": id})] + } else { + bodies.iter().map(|name| json!({"type": "body", "name": name})).collect() + }; let _ = app.run("select.set", json!({ "items": items })); + if !crate::browser::rows_start_open(app) + && let Some(first) = bodies.first() + { + crate::browser::reveal_body(app, first); + } } #[cfg(test)] diff --git a/docs/book/src/guide/ui-tour.md b/docs/book/src/guide/ui-tour.md index b291c4abe..6a9d67468 100644 --- a/docs/book/src/guide/ui-tour.md +++ b/docs/book/src/guide/ui-tour.md @@ -40,7 +40,11 @@ view. when the whole tree is collapsed). Components start closed, so a large assembly opens as a short list; open one with its fold arrow, or use **Find in Browser** on a body to open the rows down to it (**Preferences › Interface › Components start open** opens every component from the - start, as before). Rows drag into groups and other components. **Preferences › + start, as before). **Preferences › Layout › Browser rows start closed** (off by default) starts + folders closed too, and components whatever **Components start open** says: they open with + their arrow, **Expand All**, or **Find in Browser** on a body, face or edge in the view, which + opens just the rows down to that body, and a pick in the view leaves the Browser as it is. Rows + drag into groups and other components. **Preferences › Interface › Bodies folders** sets when a component's bodies sit in a Bodies folder of their own: **Several bodies only** (the default) lists a component's body straight under it when it has only one and no groups, **Never** lists every component's bodies and groups straight under it diff --git a/docs/picked-face-navigation.md b/docs/picked-face-navigation.md index 039d9bdcc..c4284b11e 100644 --- a/docs/picked-face-navigation.md +++ b/docs/picked-face-navigation.md @@ -4,6 +4,8 @@ A face selected in the viewport uses its persistent creating feature for **Edit **Find in Browser** finds the body, whether the menu was opened on a face, an edge or the body itself: it opens the body's folders, selects the body and scrolls its row into view. +With **Preferences › Layout › Browser rows start closed** on (off by default), placements and folders start closed and Find in Browser opens only the rows down to the body: the placements that hold it, its Bodies folder and any group around it. The next Find in Browser closes the rows this one opened, except rows opened or closed by hand in between, and the History's Find in Browser does the same for the feature's first body. A pick in the 3D view then leaves the Browser as it is, and only the body Find in Browser found has the rows above it marked, until the selection changes. + **Find in Timeline** selects the feature and opens any collapsed history folders around it. It also opens the **Features** folder that the Browser keeps for each native component with history, in the selected body's actual occurrence, and scrolls the feature's row there into view. Started from a sketch, construction plane or feature row in the Browser, there is no body to tell which copy of a component was meant, so the Browser is left as it is. Sketches appear only in **Sketches**, and a sketch-only component has no Features folder. Double-clicking the row opens its editor. This leaves the timeline layout, active component and history marker unchanged until an edit is requested. A face with an unavailable creator does not fall back to the body's base feature. Imported source identifiers do not acquire an unrelated editable native history.