fix(ribbon): load style/layer dropdowns from the document

The Annotate style dropdowns (text / dimension / multileader / table) and
the layer dropdown were hard-coded to "Standard" / "0" and never synced
from the opened document, so they showed placeholder values even with no
file open and stale values after closing one.

- Start the ribbon's style and layer lists empty instead of with a
  placeholder entry.
- Sync the style dropdowns from the document on file open and on tab
  new/switch/close (the layer sync already ran there).
- Guard sync_ribbon_layers / sync_ribbon_styles / sync_ribbon_from_selection
  for the Start (welcome) tab so all three dropdowns stay empty there.
- When a style family is absent (e.g. no table/multileader styles), fall
  back to empty rather than a non-existent "Standard".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-06-12 01:46:17 +03:00
commit b47e1bf706
4 changed files with 46 additions and 21 deletions

View file

@ -19,6 +19,14 @@ impl OpenCADStudio {
pub(super) fn sync_ribbon_layers(&mut self) {
let i = self.active_tab;
// The Start (welcome) tab has no document — leave the layer and
// linetype dropdowns empty instead of showing a placeholder "0".
if self.tabs[i].is_start {
self.ribbon.set_layers(vec![], "");
self.ribbon.set_available_linetypes(vec![]);
self.sync_ribbon_styles();
return;
}
let active = self.tabs[i].active_layer.clone();
let infos: Vec<crate::ui::ribbon::LayerInfo> = self.tabs[i]
.layers
@ -63,6 +71,13 @@ impl OpenCADStudio {
pub(super) fn sync_ribbon_styles(&mut self) {
let i = self.active_tab;
// The Start (welcome) tab has no real document — keep the Annotate
// style dropdowns empty rather than showing a placeholder style.
if self.tabs[i].is_start {
self.ribbon
.set_styles(vec![], "", vec![], "", vec![], "", vec![], "");
return;
}
let doc = &self.tabs[i].scene.document;
let text_names: Vec<String> = doc.text_styles.iter().map(|s| s.name.clone()).collect();
@ -73,7 +88,7 @@ impl OpenCADStudio {
text_names
.first()
.cloned()
.unwrap_or_else(|| "Standard".to_string())
.unwrap_or_default()
};
let dim_names: Vec<String> = doc.dim_styles.iter().map(|s| s.name.clone()).collect();
@ -84,7 +99,7 @@ impl OpenCADStudio {
dim_names
.first()
.cloned()
.unwrap_or_else(|| "Standard".to_string())
.unwrap_or_default()
};
let mleader_names: Vec<String> = doc
@ -105,7 +120,7 @@ impl OpenCADStudio {
mleader_names
.first()
.cloned()
.unwrap_or_else(|| "Standard".to_string())
.unwrap_or_default()
};
let table_names: Vec<String> = doc
@ -126,7 +141,7 @@ impl OpenCADStudio {
table_names
.first()
.cloned()
.unwrap_or_else(|| "Standard".to_string())
.unwrap_or_default()
};
let active_mleader2 = active_mleader.clone();