fix(styles): re-seed missing Standard styles on open; titled modals (#366)

Deleting/renaming Standard was already blocked in the five style
managers, but a file saved without the built-ins (foreign or damaged)
opened with broken style dropdowns and nothing to reference — re-seed
missing Standard text/dim/table/mleader/mline styles on every open.

Every modal dialog now shows its name in the title bar: centred at
15px across the dialog width, with the move grip and close button
overlaid at the right edge. The bar takes an explicit width from the
caller — a Fill child inside the Shrink frame would blow the dialog
out to the full screen.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-07-21 23:00:36 +03:00
commit ac14e0041d
7 changed files with 127 additions and 1 deletions

View file

@ -22,6 +22,62 @@ use acadrust::objects::{MLineStyle, MultiLeaderStyle, ObjectType, TableStyle};
use acadrust::tables::{DimStyle, TextStyle};
use acadrust::types::Handle;
/// Guarantee the built-in "Standard" style of every kind exists in `doc` —
/// a foreign or damaged file saved without them leaves the style dropdowns
/// broken with no way to recover, and new text/dimensions have nothing to
/// reference (#366). Missing entries are re-seeded with the app defaults.
/// Called on every file open; a no-op for healthy documents.
pub(crate) fn ensure_standard_styles(doc: &mut acadrust::CadDocument) {
if !doc
.text_styles
.iter()
.any(|s| s.name.eq_ignore_ascii_case("Standard"))
{
let mut s = TextStyle::new("Standard");
s.handle = doc.allocate_handle();
let _ = doc.text_styles.add(s);
}
if !doc
.dim_styles
.iter()
.any(|s| s.name.eq_ignore_ascii_case("Standard"))
{
let mut s = DimStyle::new("Standard");
s.handle = doc.allocate_handle();
let _ = doc.dim_styles.add(s);
}
let has = |doc: &acadrust::CadDocument, pred: fn(&ObjectType) -> Option<&str>| {
doc.objects
.values()
.filter_map(pred)
.any(|n| n.eq_ignore_ascii_case("Standard"))
};
if !has(doc, |o| match o {
ObjectType::TableStyle(s) => Some(&s.name),
_ => None,
}) {
let mut s = TableStyle::standard();
s.handle = doc.allocate_handle();
doc.objects.insert(s.handle, ObjectType::TableStyle(s));
}
if !has(doc, |o| match o {
ObjectType::MultiLeaderStyle(s) => Some(&s.name),
_ => None,
}) {
let mut s = MultiLeaderStyle::standard();
s.handle = doc.allocate_handle();
doc.objects.insert(s.handle, ObjectType::MultiLeaderStyle(s));
}
if !has(doc, |o| match o {
ObjectType::MLineStyle(s) => Some(&s.name),
_ => None,
}) {
let mut s = MLineStyle::standard();
s.handle = doc.allocate_handle();
doc.objects.insert(s.handle, ObjectType::MLineStyle(s));
}
}
/// Which style manager an operation targets. Carried by the shared rename
/// messages so one handler can dispatch to the right storage.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]