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 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 4.8 committed 2026-06-12 01:46:17 +03:00
1 parent 2519d64907
commit b47e1bf706
4 files changed
+46 -21

No files matched your search

+19 -4
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();
+6
View File
@@ -325,6 +325,12 @@ impl OpenCADStudio {
/// marker to do better).
pub(super) fn sync_ribbon_from_selection(&mut self) {
let i = self.active_tab;
// The Start (welcome) tab has no document — keep the ribbon's
// current-layer chip empty rather than re-seeding it with a default.
if self.tabs[i].is_start {
self.ribbon.active_layer = String::new();
return;
}
let selected = self.tabs[i].scene.selected_entities();
if selected.is_empty() {
// Creation defaults: prefer the file's saved CECOLOR / CELTYPE /
+7
View File
@@ -322,6 +322,10 @@ impl OpenCADStudio {
.layers
.sync_with_viewports(&doc_layers, vp_info);
self.sync_ribbon_layers();
// Load the Annotate-ribbon style dropdowns (text / dimension /
// multileader / table) from the opened document instead of
// leaving them on the hard-coded "Standard" default.
self.sync_ribbon_styles();
// Reset the Home-ribbon Color / Linetype / Lineweight chips
// to the newly opened document's CECOLOR / CELTYPE / CELWEIGHT
// defaults (or to ByLayer when the file leaves them empty).
@@ -917,6 +921,7 @@ impl OpenCADStudio {
self.tabs.push(new_tab);
self.active_tab = self.tabs.len() - 1;
self.sync_ribbon_layers();
self.sync_ribbon_styles();
// #21: reset ribbon Color / Linetype / Lineweight to the
// fresh tab's defaults (ByLayer) instead of inheriting the
// previous tab's last selection.
@@ -928,6 +933,7 @@ impl OpenCADStudio {
if idx < self.tabs.len() {
self.active_tab = idx;
self.sync_ribbon_layers();
self.sync_ribbon_styles();
// #21: also re-seed ribbon Color / Linetype / Lineweight
// from the newly active tab so they reflect that doc's
// CECOLOR / CELTYPE / CELWEIGHT (or its current selection
@@ -963,6 +969,7 @@ impl OpenCADStudio {
// different existing tab; in both cases the ribbon needs
// to track that doc's defaults / selection. #21.
self.sync_ribbon_layers();
self.sync_ribbon_styles();
self.sync_ribbon_from_selection();
Task::none()
}
+14 -17
View File
@@ -74,15 +74,10 @@ impl Ribbon {
ortho_mode: true,
open_dropdown: None,
last_cmd: HashMap::default(),
layer_names: vec!["0".to_string()],
active_layer: "0".to_string(),
layer_infos: vec![LayerInfo {
name: "0".to_string(),
color: Color::WHITE,
visible: true,
frozen: false,
locked: false,
}],
// Empty until a document is open — populated by sync_ribbon_layers.
layer_names: vec![],
active_layer: String::new(),
layer_infos: vec![],
active_color: AcadColor::ByLayer,
active_linetype: "ByLayer".to_string(),
active_lineweight: LineWeight::ByLayer,
@@ -91,14 +86,16 @@ impl Ribbon {
art: String::new(),
}],
prop_color_palette_open: false,
text_style_names: vec!["Standard".to_string()],
active_text_style: "Standard".to_string(),
dim_style_names: vec!["Standard".to_string()],
active_dim_style: "Standard".to_string(),
mleader_style_names: vec!["Standard".to_string()],
active_mleader_style: "Standard".to_string(),
table_style_names: vec!["Standard".to_string()],
active_table_style: "Standard".to_string(),
// Empty until a document is open — the Annotate style dropdowns
// are populated from the active document by sync_ribbon_styles.
text_style_names: vec![],
active_text_style: String::new(),
dim_style_names: vec![],
active_dim_style: String::new(),
mleader_style_names: vec![],
active_mleader_style: String::new(),
table_style_names: vec![],
active_table_style: String::new(),
}
}