fix(layer): propagate LAY* command changes to panel + dropdown (#39)

LAYOFF / LAYFRZ / LAYLCK / LAYON / LAYTHW / LAYULK / LAYISO /
LAYUNISO mutated the document's layer table (\`turn_off\` /
\`freeze\` / \`lock\` / …) and then called \`sync_ribbon_layers\`,
which feeds the ribbon dropdown from \`self.tabs[i].layers.layers\`
— the \`LayerPanel\` cache. That cache was never refreshed from
the document for these commands, so the dropdown stayed wrong and
the Layers Properties Manager kept showing the old visibility /
lock / freeze icons.

Add \`OpenCADStudio::refresh_layer_panel\` that runs
\`LayerPanel::sync_with_viewports\` from the live document before
calling \`sync_ribbon_layers\`. Replace every direct
\`sync_ribbon_layers\` in \`commands.rs\` (all of them sit inside
LAY* arms) with the new helper.

Closes #39
This commit is contained in:
Hakan Seven committed 2026-05-29 01:30:02 +03:00
1 parent 8f9fe5226b
commit 89fcb21b46
2 files changed
+24 -9

No files matched your search

+9 -9
View File
@@ -131,7 +131,7 @@ impl OpenCADStudio {
}
}
self.tabs[i].dirty = true;
self.sync_ribbon_layers();
self.refresh_layer_panel();
self.command_line.push_info("Layer(s) turned off.");
}
}
@@ -165,7 +165,7 @@ impl OpenCADStudio {
}
}
self.tabs[i].dirty = true;
self.sync_ribbon_layers();
self.refresh_layer_panel();
self.command_line.push_info("Layer(s) frozen.");
}
}
@@ -196,7 +196,7 @@ impl OpenCADStudio {
}
}
self.tabs[i].dirty = true;
self.sync_ribbon_layers();
self.refresh_layer_panel();
self.command_line.push_info("Layer(s) locked.");
}
}
@@ -215,7 +215,7 @@ impl OpenCADStudio {
self.tabs[i].layers.current_layer = layer.clone();
self.command_line
.push_info(&format!("Current layer set to \"{layer}\"."));
self.sync_ribbon_layers();
self.refresh_layer_panel();
}
}
@@ -234,7 +234,7 @@ impl OpenCADStudio {
}
}
self.tabs[i].dirty = true;
self.sync_ribbon_layers();
self.refresh_layer_panel();
self.command_line.push_info("All layers turned on.");
}
@@ -253,7 +253,7 @@ impl OpenCADStudio {
}
}
self.tabs[i].dirty = true;
self.sync_ribbon_layers();
self.refresh_layer_panel();
self.command_line.push_info("All layers thawed.");
}
@@ -283,7 +283,7 @@ impl OpenCADStudio {
}
}
self.tabs[i].dirty = true;
self.sync_ribbon_layers();
self.refresh_layer_panel();
self.command_line.push_info("Layer(s) unlocked.");
}
}
@@ -316,7 +316,7 @@ impl OpenCADStudio {
}
}
self.tabs[i].dirty = true;
self.sync_ribbon_layers();
self.refresh_layer_panel();
self.command_line
.push_info(&format!("LAYISO: isolated {} layer(s).", sel_layers.len()));
}
@@ -338,7 +338,7 @@ impl OpenCADStudio {
}
}
self.tabs[i].dirty = true;
self.sync_ribbon_layers();
self.refresh_layer_panel();
self.command_line
.push_info("LAYUNISO: all layers restored.");
}
+15
View File
@@ -2,6 +2,21 @@ use super::OpenCADStudio;
use crate::ui;
impl OpenCADStudio {
/// Reload the `LayerPanel` cache from the document and push the
/// fresh state through to the ribbon dropdown + every other
/// layer-aware UI mirror. Use this whenever a command mutates the
/// document's layer table directly (LAYOFF / LAYFRZ / LAYLCK …) so
/// the panel + dropdown reflect the change. See #39.
pub(super) fn refresh_layer_panel(&mut self) {
let i = self.active_tab;
let doc_layers = self.tabs[i].scene.document.layers.clone();
let vp_info = self.tabs[i].scene.viewport_list();
self.tabs[i]
.layers
.sync_with_viewports(&doc_layers, vp_info);
self.sync_ribbon_layers();
}
pub(super) fn sync_ribbon_layers(&mut self) {
let i = self.active_tab;
let active = self.tabs[i].active_layer.clone();