fix(dock): block palette reflects new blocks without reopening
Creating a block from selected entities now bumps the geometry epoch, so the block palette's per-update stale check notices the new definition and refreshes its list in place instead of requiring the user to close and reopen the panel.
This commit is contained in:
parent
bd33600ee7
commit
dceb9626ae
2 changed files with 49 additions and 1 deletions
|
|
@ -1039,6 +1039,49 @@ mod tests {
|
|||
assert_eq!(app.block_palette.placing.as_deref(), Some("Fixture"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blockpalette_reflects_new_block_without_reopen() {
|
||||
use acadrust::types::Transform;
|
||||
|
||||
let mut app = fresh();
|
||||
let i = app.active_tab;
|
||||
|
||||
// Reproduce the user-facing flow: select entities and run the BLOCK
|
||||
// command, which goes through `create_block_from_entities` (not the
|
||||
// clipboard / paste-as-block path).
|
||||
let mut line = Line::new();
|
||||
line.start = Vector3::ZERO;
|
||||
line.end = Vector3::new(10.0, 0.0, 0.0);
|
||||
let first = app.tabs[i].scene.add_entity(EntityType::Line(line));
|
||||
app.tabs[i].scene.select_entity(first, false);
|
||||
app.show_block_palette = true;
|
||||
let ws = Transform::identity();
|
||||
let id = Transform::identity();
|
||||
app.tabs[i]
|
||||
.scene
|
||||
.create_block_from_entities(&[first], "First", &ws, &id)
|
||||
.unwrap();
|
||||
app.refresh_block_palette_if_stale();
|
||||
assert!(app.block_palette.blocks.iter().any(|b| b.name == "First"));
|
||||
|
||||
// Create a second block on the same tab, then re-run the per-update
|
||||
// stale check. It must pick up the new block WITHOUT reopening.
|
||||
line = Line::new();
|
||||
line.start = Vector3::ZERO;
|
||||
line.end = Vector3::new(9.0, 0.0, 0.0);
|
||||
let second = app.tabs[i].scene.add_entity(EntityType::Line(line));
|
||||
app.tabs[i].scene.select_entity(second, false);
|
||||
app.tabs[i]
|
||||
.scene
|
||||
.create_block_from_entities(&[second], "Second", &ws, &id)
|
||||
.unwrap();
|
||||
app.refresh_block_palette_if_stale();
|
||||
assert!(
|
||||
app.block_palette.blocks.iter().any(|b| b.name == "Second"),
|
||||
"Second must appear without reopening the panel"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blockpalette_pin_toggles_autocollapse_and_close_hides() {
|
||||
let mut app = fresh();
|
||||
|
|
|
|||
|
|
@ -698,7 +698,12 @@ impl Scene {
|
|||
|
||||
let mut insert = DxfInsert::new(name, acadrust::types::Vector3::ZERO);
|
||||
acadrust::Entity::apply_transform(&mut insert, block_to_world);
|
||||
Ok(self.add_entity(EntityType::Insert(insert)))
|
||||
let insert_handle = self.add_entity(EntityType::Insert(insert));
|
||||
// A new block definition landed in the document; advance the block
|
||||
// epoch so consumers (the block palette stale check) notice it even
|
||||
// when the panel stays open. Mirrors `define_block_from_owned_entities`.
|
||||
self.bump_geometry();
|
||||
Ok(insert_handle)
|
||||
}
|
||||
|
||||
/// Define a new block named `name` from `entities` (owned, not yet in the
|
||||
|
|
|
|||
Loading…
Reference in a new issue