From 9fb075f8ee7b2a7fa75967e124f68a773c404f76 Mon Sep 17 00:00:00 2001 From: gianlucafiore Date: Tue, 11 Aug 2026 18:45:00 -0300 Subject: [PATCH] fix: improve plot style editing and print all plot actions --- src/app/mod.rs | 4 +- src/app/update/file.rs | 6 +-- src/app/update/mod.rs | 79 ++++++++++++++++++++++++++++++++++++++- src/ui/style/plotstyle.rs | 4 ++ src/ui/window/plot.rs | 34 ++++++++--------- 5 files changed, 101 insertions(+), 26 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index 1d8cea4e2..b9b6ba2a3 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -2755,7 +2755,9 @@ pub enum Message { PlotStylePanelScreenBuf(String), /// Apply current edit buffers to the selected ACI entry. PlotStylePanelApply, - /// Save the modified table back to disk. + /// Save the modified table directly over the currently edited CTB. + PlotStylePanelSaveDirect, + /// Save the modified table under a chosen name/path. PlotStylePanelSave, /// Save callback. PlotStylePanelSavePath(Option), diff --git a/src/app/update/file.rs b/src/app/update/file.rs index 5c437aa1a..915357b27 100644 --- a/src/app/update/file.rs +++ b/src/app/update/file.rs @@ -3318,10 +3318,7 @@ pub(super) fn on_open_file(&mut self) -> Task { } Task::none() } - M::SetCurrent => { - if self.print_all_options { - return Task::none(); - } + M::SetCurrent => { self.apply_dialog_to_layout(); self.command_line.push_info(crate::t!("Page setup applied to the layout.").as_ref()); Task::none() @@ -3424,7 +3421,6 @@ pub(super) fn on_open_file(&mut self) -> Task { self.plot_dialog.name_rename = false; Task::none() } - M::Preview if self.print_all_options => Task::none(), M::Preview => self.on_plot_dlg_commit(true), M::Commit if self.print_all_options => { if self.plot_dialog.style_missing { diff --git a/src/app/update/mod.rs b/src/app/update/mod.rs index c179d686c..395e50939 100644 --- a/src/app/update/mod.rs +++ b/src/app/update/mod.rs @@ -6531,6 +6531,32 @@ impl OpenCADStudio { // ── Plot Style Panel ────────────────────────────────────────────── Message::PlotStylePanelOpen => { + // The Plot dialog's selected table is authoritative. Make sure + // the editor opens that table rather than a stale active table. + let selected_style = self.plot_dialog.style_name.clone(); + + if selected_style.is_empty() { + self.active_plot_style = None; + } else { + let needs_load = self + .active_plot_style + .as_ref() + .is_none_or(|table| !table.name.eq_ignore_ascii_case(&selected_style)); + + if needs_load { + match crate::io::plot_style::PlotStyleTable::load_named(&selected_style) { + Ok(table) => { + self.active_plot_style = Some(table); + self.plot_dialog.style_missing = false; + } + Err(error) => { + self.plot_dialog.style_missing = true; + self.command_line.push_error(&error); + return Task::none(); + } + } + } + } // Initialise edit buffers for ACI 1. self.plotstyle_panel_aci = 1; let entry = self @@ -6610,9 +6636,58 @@ impl OpenCADStudio { Message::PlotStylePanelApply => self.on_plot_style_panel_apply(), - Message::PlotStylePanelSave => self.on_plot_style_panel_save(), + Message::PlotStylePanelSaveDirect => { + let Some(table) = self.active_plot_style.as_ref() else { + self.command_line.push_error( + crate::t!("No plot style table loaded. Load or create one first.").as_ref(), + ); + return Task::none(); + }; - Message::PlotStylePanelSavePath(Some(path)) => { + #[cfg(not(target_arch = "wasm32"))] + { + let table_name = table.name.clone(); + + let result = crate::io::plot_style::ensure_plot_styles_dir().and_then(|dir| { + let path = dir.join(&table_name); + table.save(&path)?; + Ok(path) + }); + + match result { + Ok(path) => { + self.plot_dialog.style_name = table_name; + self.plot_dialog.style_missing = false; + self.plot_dialog.plot_styles = + crate::io::plot_style::available_ctb_names(); + + self.command_line.push_output( + crate::tf!( + "Plot style table saved to \"{}\".", + path.display() + ) + .as_ref(), + ); + } + Err(error) => { + self.command_line + .push_error(crate::tf!("Save error: {error}").as_ref()); + } + } + + Task::none() + } + + #[cfg(target_arch = "wasm32")] + { + // Browsers cannot overwrite a local file directly, so fall back + // to the existing Save As flow. + self.on_plot_style_panel_save() + } + } + + Message::PlotStylePanelSave => self.on_plot_style_panel_save(), + Message::PlotStylePanelSavePath(Some(path)) => { let path = if path .extension() .is_some_and(|extension| extension.eq_ignore_ascii_case("ctb")) diff --git a/src/ui/style/plotstyle.rs b/src/ui/style/plotstyle.rs index 97be90a7d..7900f762c 100644 --- a/src/ui/style/plotstyle.rs +++ b/src/ui/style/plotstyle.rs @@ -133,6 +133,10 @@ pub fn view_window<'a>( .on_press(Message::PlotStyleLoad) .style(btn_s(false)) .padding([4, 10]), + button(text(t!("Save")).size(11)) + .on_press(Message::PlotStylePanelSaveDirect) + .style(btn_s(true)) + .padding([4, 14]), button(text(t!("Save As…")).size(11)) .on_press(Message::PlotStylePanelSave) .style(btn_s(false)) diff --git a/src/ui/window/plot.rs b/src/ui/window/plot.rs index 1f8ff0d28..462c6ab20 100644 --- a/src/ui/window/plot.rs +++ b/src/ui/window/plot.rs @@ -892,24 +892,22 @@ pub fn view_window( let body = row![list_panel, vsep(height), detail] .width(width) .height(height); - let mut toolbar_row = row![left_bar, Space::new().width(width)].align_y(iced::Center); - if !print_all_options { - toolbar_row = toolbar_row - .push( - button(text(t!("Set current")).size(11)) - .on_press(Message::PlotDlg(PlotDlgMsg::SetCurrent)) - .style(btn(false)) - .padding([4, 12]), - ) - .push(Space::new().width(6)) - .push( - button(text(t!("Preview")).size(11)) - .on_press(Message::PlotDlg(PlotDlgMsg::Preview)) - .style(btn(false)) - .padding([4, 12]), - ) - .push(Space::new().width(6)); - } + let mut toolbar_row = row![left_bar, Space::new().width(width)] + .align_y(iced::Center) + .push( + button(text(t!("Set current")).size(11)) + .on_press(Message::PlotDlg(PlotDlgMsg::SetCurrent)) + .style(btn(false)) + .padding([4, 12]), + ) + .push(Space::new().width(6)) + .push( + button(text(t!("Preview")).size(11)) + .on_press(Message::PlotDlg(PlotDlgMsg::Preview)) + .style(btn(false)) + .padding([4, 12]), + ) + .push(Space::new().width(6)); toolbar_row = toolbar_row.push( button(text(action).size(11)) .on_press(Message::PlotDlg(PlotDlgMsg::Commit))