forked from 1b-agent/opencadstudio-upstream
fix(plot-style): load plot style tables written by other applications
Tables copied from other applications into the plot styles folder were listed but refused on selection, showing as "missing" with the reason lost on a console: the loader failed hard on a checksum or a text length that did not add up and on any non-UTF-8 byte — and those files carry their descriptions in Windows-1252. - decompress_ctb reads the file as it is: a checksum or length mismatch is reported and read past (a genuinely cut-off file is still an error), a zlib stream with a bad trailer is retried as raw deflate, and text that is not UTF-8 is read as Windows-1252 (pens and colours are numbers and unaffected; other code pages only show wrong characters in descriptions). - PlotStyleTable carries load_warnings; every load site reports them on the command line, so a table that needed tolerance says so. - load_named explains itself: a .stb name says named tables are not supported yet, a .ctb missing from the folder says which folder to copy it into (instead of "Unknown built-in plot style"). - The Plot dialog shows the reason under the Table row (style_error) — from a selection, from a page setup that names a table, and from the Load… picker, whose error used to be swallowed. - A table picked with Load… from outside the plot styles folder is copied into it (unless a file of that name is already there), so it is listed from then on and page setups naming it resolve after a restart. Tests: flipped checksum, text length off by one, a short payload field, Windows-1252 descriptions, a truncated stream, .stb and missing names. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2b38f798c0
commit
7a75d430cd
28 files changed
+339
-35
No files matched your search
@@ -431,6 +431,9 @@ pub struct PlotDialogState {
|
||||
/// The selected setup references a style table that is not loaded.
|
||||
#[serde(skip)]
|
||||
pub style_missing: bool,
|
||||
/// Why the selected table could not be loaded, shown under the Table row.
|
||||
#[serde(skip)]
|
||||
pub style_error: Option<String>,
|
||||
/// Named page setups in the document (refreshed when the dialog opens).
|
||||
#[serde(skip)]
|
||||
pub page_setups: Vec<String>,
|
||||
@@ -489,6 +492,7 @@ impl Default for PlotDialogState {
|
||||
show_plot_styles: false,
|
||||
plot_styles: Vec::new(),
|
||||
style_missing: false,
|
||||
style_error: None,
|
||||
page_setups: Vec::new(),
|
||||
selected_setup: String::new(),
|
||||
name_input: None,
|
||||
@@ -670,6 +674,17 @@ fn check_enabled<'a>(
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Why the selected plot style table is not loaded, under the Table row —
|
||||
/// the file's own problem, or where a copy would be found.
|
||||
fn style_note<'a>(s: &'a PlotDialogState) -> Element<'a, Message> {
|
||||
match &s.style_error {
|
||||
Some(error) if s.style_missing => {
|
||||
text(error.clone()).size(10).style(muted_style).into()
|
||||
}
|
||||
_ => Space::new().height(0).into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn panel<'a>(content: impl Into<Element<'a, Message>>) -> Element<'a, Message> {
|
||||
container(content)
|
||||
.width(Length::Fill)
|
||||
@@ -1241,6 +1256,7 @@ pub fn view_window(
|
||||
PlotDlgMsg::Style,
|
||||
width,
|
||||
),
|
||||
style_note(s),
|
||||
check_enabled(
|
||||
t!("Plot with plot styles"),
|
||||
s.apply_plot_styles,
|
||||
|
||||
Reference in new issue
Block a user