fix: improve plot style editing and print all plot actions
This commit is contained in:
parent
c4dfa7567d
commit
9fb075f8ee
5 changed files with 101 additions and 26 deletions
|
|
@ -2755,7 +2755,9 @@ pub enum Message {
|
||||||
PlotStylePanelScreenBuf(String),
|
PlotStylePanelScreenBuf(String),
|
||||||
/// Apply current edit buffers to the selected ACI entry.
|
/// Apply current edit buffers to the selected ACI entry.
|
||||||
PlotStylePanelApply,
|
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,
|
PlotStylePanelSave,
|
||||||
/// Save callback.
|
/// Save callback.
|
||||||
PlotStylePanelSavePath(Option<std::path::PathBuf>),
|
PlotStylePanelSavePath(Option<std::path::PathBuf>),
|
||||||
|
|
|
||||||
|
|
@ -3319,9 +3319,6 @@ pub(super) fn on_open_file(&mut self) -> Task<Message> {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
M::SetCurrent => {
|
M::SetCurrent => {
|
||||||
if self.print_all_options {
|
|
||||||
return Task::none();
|
|
||||||
}
|
|
||||||
self.apply_dialog_to_layout();
|
self.apply_dialog_to_layout();
|
||||||
self.command_line.push_info(crate::t!("Page setup applied to the layout.").as_ref());
|
self.command_line.push_info(crate::t!("Page setup applied to the layout.").as_ref());
|
||||||
Task::none()
|
Task::none()
|
||||||
|
|
@ -3424,7 +3421,6 @@ pub(super) fn on_open_file(&mut self) -> Task<Message> {
|
||||||
self.plot_dialog.name_rename = false;
|
self.plot_dialog.name_rename = false;
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
M::Preview if self.print_all_options => Task::none(),
|
|
||||||
M::Preview => self.on_plot_dlg_commit(true),
|
M::Preview => self.on_plot_dlg_commit(true),
|
||||||
M::Commit if self.print_all_options => {
|
M::Commit if self.print_all_options => {
|
||||||
if self.plot_dialog.style_missing {
|
if self.plot_dialog.style_missing {
|
||||||
|
|
|
||||||
|
|
@ -6531,6 +6531,32 @@ impl OpenCADStudio {
|
||||||
|
|
||||||
// ── Plot Style Panel ──────────────────────────────────────────────
|
// ── Plot Style Panel ──────────────────────────────────────────────
|
||||||
Message::PlotStylePanelOpen => {
|
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.
|
// Initialise edit buffers for ACI 1.
|
||||||
self.plotstyle_panel_aci = 1;
|
self.plotstyle_panel_aci = 1;
|
||||||
let entry = self
|
let entry = self
|
||||||
|
|
@ -6610,9 +6636,58 @@ impl OpenCADStudio {
|
||||||
|
|
||||||
Message::PlotStylePanelApply => self.on_plot_style_panel_apply(),
|
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
|
let path = if path
|
||||||
.extension()
|
.extension()
|
||||||
.is_some_and(|extension| extension.eq_ignore_ascii_case("ctb"))
|
.is_some_and(|extension| extension.eq_ignore_ascii_case("ctb"))
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,10 @@ pub fn view_window<'a>(
|
||||||
.on_press(Message::PlotStyleLoad)
|
.on_press(Message::PlotStyleLoad)
|
||||||
.style(btn_s(false))
|
.style(btn_s(false))
|
||||||
.padding([4, 10]),
|
.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))
|
button(text(t!("Save As…")).size(11))
|
||||||
.on_press(Message::PlotStylePanelSave)
|
.on_press(Message::PlotStylePanelSave)
|
||||||
.style(btn_s(false))
|
.style(btn_s(false))
|
||||||
|
|
|
||||||
|
|
@ -892,24 +892,22 @@ pub fn view_window(
|
||||||
let body = row![list_panel, vsep(height), detail]
|
let body = row![list_panel, vsep(height), detail]
|
||||||
.width(width)
|
.width(width)
|
||||||
.height(height);
|
.height(height);
|
||||||
let mut toolbar_row = row![left_bar, Space::new().width(width)].align_y(iced::Center);
|
let mut toolbar_row = row![left_bar, Space::new().width(width)]
|
||||||
if !print_all_options {
|
.align_y(iced::Center)
|
||||||
toolbar_row = toolbar_row
|
.push(
|
||||||
.push(
|
button(text(t!("Set current")).size(11))
|
||||||
button(text(t!("Set current")).size(11))
|
.on_press(Message::PlotDlg(PlotDlgMsg::SetCurrent))
|
||||||
.on_press(Message::PlotDlg(PlotDlgMsg::SetCurrent))
|
.style(btn(false))
|
||||||
.style(btn(false))
|
.padding([4, 12]),
|
||||||
.padding([4, 12]),
|
)
|
||||||
)
|
.push(Space::new().width(6))
|
||||||
.push(Space::new().width(6))
|
.push(
|
||||||
.push(
|
button(text(t!("Preview")).size(11))
|
||||||
button(text(t!("Preview")).size(11))
|
.on_press(Message::PlotDlg(PlotDlgMsg::Preview))
|
||||||
.on_press(Message::PlotDlg(PlotDlgMsg::Preview))
|
.style(btn(false))
|
||||||
.style(btn(false))
|
.padding([4, 12]),
|
||||||
.padding([4, 12]),
|
)
|
||||||
)
|
.push(Space::new().width(6));
|
||||||
.push(Space::new().width(6));
|
|
||||||
}
|
|
||||||
toolbar_row = toolbar_row.push(
|
toolbar_row = toolbar_row.push(
|
||||||
button(text(action).size(11))
|
button(text(action).size(11))
|
||||||
.on_press(Message::PlotDlg(PlotDlgMsg::Commit))
|
.on_press(Message::PlotDlg(PlotDlgMsg::Commit))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue