feat(plot): add Print All workflow

This commit is contained in:
Hakan Seven committed 2026-08-04 11:29:11 +03:00
1 parent 734afd5611
commit f6b9d6514e
11 files changed
+655 -41

No files matched your search

+1
View File
@@ -2,6 +2,7 @@ pub mod about;
pub mod layout_manager;
pub mod layer_state_manager;
pub mod plot;
pub mod print_all;
pub mod plugin_manager;
pub mod shortcuts;
pub mod layers;
+49 -31
View File
@@ -490,11 +490,18 @@ fn choices(items: &[&str]) -> Vec<PlotChoice> {
pub fn view_window(
s: &PlotDialogState,
print_all_options: bool,
sizing: crate::ui::modal::ModalSizing,
) -> Element<'_, Message> {
let width = sizing.width;
let height = sizing.height;
let action = if s.to_file { t!("Export PDF") } else { t!("Print") };
let action = if print_all_options {
t!("Apply")
} else if s.to_file {
t!("Export PDF")
} else {
t!("Print")
};
let is_special = s.selected_setup == SETUP_NONE || s.selected_setup == SETUP_PREV;
let sel_is_layout = s.selected_setup.len() >= 2
&& s.selected_setup.starts_with('*')
@@ -578,23 +585,26 @@ pub fn view_window(
left: 12.0,
});
let mut new_button = button(text(t!("New")).size(11))
.style(btn(false))
.padding([4, 12]);
if !print_all_options {
new_button = new_button.on_press(Message::PlotDlg(PlotDlgMsg::NewSetup));
}
let mut copy_button = button(text(t!("Copy")).size(11))
.style(btn(false))
.padding([4, 12]);
if can_copy {
if can_copy && !print_all_options {
copy_button = copy_button.on_press(Message::PlotDlg(PlotDlgMsg::CopySetup));
}
let mut delete_button = button(text(t!("Delete")).size(11))
.style(btn(false))
.padding([4, 12]);
if is_named {
if is_named && !print_all_options {
delete_button = delete_button.on_press(Message::PlotDlg(PlotDlgMsg::DeleteSetup));
}
let left_bar = row![
button(text(t!("New")).size(11))
.on_press(Message::PlotDlg(PlotDlgMsg::NewSetup))
.style(btn(false))
.padding([4, 12]),
new_button,
copy_button,
delete_button,
]
@@ -672,8 +682,12 @@ pub fn view_window(
paper_note,
].spacing(7));
let mut area_options = choices(&["Extents", "Display", "Window"]);
if s.paper_space {
let mut area_options = if print_all_options {
choices(&["Layout"])
} else {
choices(&["Extents", "Display", "Window"])
};
if s.paper_space && !print_all_options {
area_options.insert(0, PlotChoice::localized("Layout"));
}
let mut area_row = row![
@@ -690,7 +704,7 @@ pub fn view_window(
]
.spacing(8)
.align_y(iced::Center);
if s.area == "Window" {
if s.area == "Window" && !print_all_options {
area_row = area_row.push(
button(text(t!("Pick…")).size(11))
.on_press(Message::PlotDlg(PlotDlgMsg::PickWindow))
@@ -877,27 +891,31 @@ pub fn view_window(
let body = row![list_panel, vsep(height), detail]
.width(width)
.height(height);
let toolbar = container(
row![
left_bar,
Space::new().width(width),
button(text(t!("Set current")).size(11))
.on_press(Message::PlotDlg(PlotDlgMsg::SetCurrent))
.style(btn(false))
.padding([4, 12]),
Space::new().width(6),
button(text(t!("Preview")).size(11))
.on_press(Message::PlotDlg(PlotDlgMsg::Preview))
.style(btn(false))
.padding([4, 12]),
Space::new().width(6),
button(text(action).size(11))
.on_press(Message::PlotDlg(PlotDlgMsg::Commit))
.style(btn(true))
.padding([4, 18]),
]
.align_y(iced::Center),
)
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));
}
toolbar_row = toolbar_row.push(
button(text(action).size(11))
.on_press(Message::PlotDlg(PlotDlgMsg::Commit))
.style(btn(true))
.padding([4, 18]),
);
let toolbar = container(toolbar_row)
.style(|theme: &Theme| container::Style {
background: Some(Background::Color(theme.palette().background.weak.color)),
..Default::default()
+127
View File
@@ -0,0 +1,127 @@
use crate::app::Message;
use crate::t;
use iced::widget::{button, checkbox, column, container, row, scrollable, text, Space};
use iced::{Background, Border, Element, Length, Theme};
fn button_style(primary: bool) -> impl Fn(&Theme, button::Status) -> button::Style {
move |theme, status| {
if primary {
button::primary(theme, status)
} else {
button::secondary(theme, status)
}
}
}
fn muted(theme: &Theme) -> iced::widget::text::Style {
iced::widget::text::Style {
color: Some(theme.palette().background.base.text.scale_alpha(0.68)),
}
}
pub fn view_window<'a>(
layouts: &'a [(String, bool)],
printer: Option<&'a str>,
sizing: crate::ui::modal::ModalSizing,
) -> Element<'a, Message> {
let selected = layouts.iter().filter(|(_, checked)| *checked).count();
let rows: Vec<Element<'a, Message>> = layouts
.iter()
.map(|(name, checked)| {
let layout = name.clone();
container(
checkbox(*checked)
.label(name.clone())
.on_toggle(move |_| Message::PrintAllToggle(layout.clone()))
.size(16)
.text_size(12),
)
.padding([6, 8])
.width(Length::Fill)
.into()
})
.collect();
let list: Element<'a, Message> = if rows.is_empty() {
container(text(t!("No paper layouts are available.")).size(12).style(muted))
.center_x(Length::Fill)
.center_y(Length::Fill)
.into()
} else {
scrollable(column(rows).spacing(2)).height(sizing.height).into()
};
let printer = printer
.filter(|name| !name.is_empty())
.map(str::to_owned)
.unwrap_or_else(|| t!("Default printer").into_owned());
let summary = if selected == 1 {
t!("1 layout selected").into_owned()
} else {
format!("{selected} {}", t!("layouts selected"))
};
let mut pdf = button(text(t!("PDF")).size(11))
.style(button_style(false))
.padding([5, 16]);
let mut print = button(text(t!("Print")).size(11))
.style(button_style(true))
.padding([5, 18]);
if selected > 0 {
pdf = pdf.on_press(Message::PrintAllPdf);
print = print.on_press(Message::PrintAllPrint);
}
let list_panel = container(list)
.width(sizing.width)
.height(sizing.height)
.padding(4)
.style(|theme: &Theme| container::Style {
background: Some(Background::Color(theme.palette().background.weak.color)),
border: Border {
color: theme.palette().background.neutral.color,
width: 1.0,
radius: 4.0.into(),
},
..Default::default()
});
container(
column![
text(t!("Select the layouts to output. Each page is printed in Layout mode."))
.size(12),
row![
button(text(t!("Select all")).size(11))
.on_press(Message::PrintAllSelectAll)
.style(button_style(false))
.padding([4, 10]),
button(text(t!("Select none")).size(11))
.on_press(Message::PrintAllSelectNone)
.style(button_style(false))
.padding([4, 10]),
Space::new().width(Length::Fill),
text(summary).size(11).style(muted),
]
.spacing(6)
.align_y(iced::Center),
list_panel,
row![
text(format!("{}: {printer}", t!("Printer")))
.size(11)
.style(muted),
Space::new().width(Length::Fill),
button(text(t!("Options…")).size(11))
.on_press(Message::PrintAllOptions)
.style(button_style(false))
.padding([5, 12]),
pdf,
print,
]
.spacing(7)
.align_y(iced::Center),
]
.spacing(10),
)
.padding(14)
.width(sizing.width)
.height(sizing.height)
.into()
}