fix: improve plot style editing and print all plot actions

This commit is contained in:
gianlucafiore committed 2026-08-11 18:45:00 -03:00
1 parent c4dfa7567d
commit 9fb075f8ee
5 files changed
+101 -26

No files matched your search

+3 -1
View File
@@ -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<std::path::PathBuf>),
+1 -5
View File
@@ -3318,10 +3318,7 @@ pub(super) fn on_open_file(&mut self) -> Task<Message> {
}
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<Message> {
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 {
+77 -2
View File
@@ -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"))
+4
View File
@@ -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))
+16 -18
View File
@@ -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))