mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-27 21:02:58 +00:00
#5597: decide the Print page's hidden job message per window
The shared printing.message is no longer cleared on reopening Print (ui.printSettings and other windows still report it). Each window remembers what it said (status bar or Print page) and hides only that; a result that arrived under File's other pages is not counted as said. Tests: failure-on-open-page now depends on reopen detection, never-said and two-window state. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
52cb1bcfd4
commit
0df0137b4e
@@ -58,7 +58,7 @@ impl WordApp {
|
||||
seen_full_screen,
|
||||
escape_free,
|
||||
status_counts,
|
||||
print_page_pass,
|
||||
print_memo,
|
||||
missing_fonts,
|
||||
last_autosave,
|
||||
equation_prev_tab,
|
||||
@@ -179,7 +179,7 @@ impl WordApp {
|
||||
seen_full_screen,
|
||||
escape_free,
|
||||
status_counts,
|
||||
print_page_pass,
|
||||
print_memo,
|
||||
missing_fonts,
|
||||
last_autosave,
|
||||
equation_prev_tab,
|
||||
|
||||
@@ -320,6 +320,8 @@ impl WordApp {
|
||||
return;
|
||||
}
|
||||
self.print_feedback_seen = self.printing.message.clone();
|
||||
// A new message: what this window said before no longer stands for it.
|
||||
self.print_memo.said = None;
|
||||
let Some(message @ (printing::Feedback::Submitted(_) | printing::Feedback::Failed(_) | printing::Feedback::WorkerStopped)) =
|
||||
self.printing.message.clone()
|
||||
else {
|
||||
@@ -334,6 +336,11 @@ impl WordApp {
|
||||
self.ui.backstage = false;
|
||||
self.canvas.want_focus = true;
|
||||
}
|
||||
// Said only where the status bar is drawn: not under File's other pages, and a failure on
|
||||
// the Print page is the page's to show.
|
||||
if !self.ui.backstage {
|
||||
self.print_memo.said = Some(message);
|
||||
}
|
||||
}
|
||||
|
||||
/// Files dropped on the native window. Raw input is taken only in the first UI pass: a
|
||||
|
||||
@@ -787,7 +787,7 @@ pub struct WordApp {
|
||||
pub status_counts: (u64, StatusCounts),
|
||||
/// The window's viewport and the pass its Print page was last drawn in: a gap means the
|
||||
/// page has just been opened. Per window, as each window counts its own passes.
|
||||
print_page_pass: Option<(egui::ViewportId, u64)>,
|
||||
print_memo: crate::print_page::Memo,
|
||||
last_autosave: f64,
|
||||
/// The tab shown before the Equation tab came up (restored when editing ends).
|
||||
pub(crate) equation_prev_tab: Option<String>,
|
||||
|
||||
@@ -170,6 +170,17 @@ fn return_prints(ctx: &egui::Context) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
/// Per window: what the Print page needs to know about the last job's message.
|
||||
#[derive(Default)]
|
||||
pub struct Memo {
|
||||
/// The viewport and pass the page was last drawn in: a gap means it was just opened.
|
||||
pass: Option<(egui::ViewportId, u64)>,
|
||||
/// The job result this window has already said, in its status bar or on this page.
|
||||
pub(crate) said: Option<crate::printing::Feedback>,
|
||||
/// The result held back on this opening of the page.
|
||||
hidden: Option<crate::printing::Feedback>,
|
||||
}
|
||||
|
||||
/// The Print page: settings on the left, the preview on the right.
|
||||
pub fn show(app: &mut WordApp, ui: &mut Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
@@ -178,22 +189,31 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
|
||||
let total = lay.pages.len();
|
||||
let current = app.session.current_pages(&lay);
|
||||
app.ui.print.preview = app.ui.print.preview.min(total.saturating_sub(1));
|
||||
// Opened afresh, the page doesn't repeat how the last job went: that was said once in the
|
||||
// status bar. What the printers are doing (finding them, none found) still shows.
|
||||
// Passes are counted per viewport, so the marker is per window and names its viewport.
|
||||
// Opened afresh, the page doesn't repeat how the last job went when this window already said
|
||||
// it (its status bar, or this page): `printing.message` itself stays, as `ui.printSettings`
|
||||
// and other windows still report it. What the printers are doing (finding them, none found)
|
||||
// always shows. Passes are counted per viewport, so the marker is per window.
|
||||
let here = (ctx.viewport_id(), ctx.cumulative_pass_nr());
|
||||
let opened = app.print_page_pass.is_none_or(|(viewport, last)| viewport != here.0 || last.saturating_add(1) < here.1);
|
||||
app.print_page_pass = Some(here);
|
||||
// Only once the status bar has said it (`print_feedback`), so nothing goes unsaid.
|
||||
if opened
|
||||
&& !app.printing.busy()
|
||||
&& app.printing.message == app.print_feedback_seen
|
||||
&& matches!(
|
||||
app.printing.message,
|
||||
Some(crate::printing::Feedback::Submitted(_) | crate::printing::Feedback::Failed(_) | crate::printing::Feedback::WorkerStopped)
|
||||
)
|
||||
{
|
||||
app.printing.message = None;
|
||||
let opened = app.print_memo.pass.is_none_or(|(viewport, last)| viewport != here.0 || last.saturating_add(1) < here.1);
|
||||
app.print_memo.pass = Some(here);
|
||||
let result = |m: &Option<crate::printing::Feedback>| {
|
||||
matches!(m, Some(crate::printing::Feedback::Submitted(_) | crate::printing::Feedback::Failed(_) | crate::printing::Feedback::WorkerStopped))
|
||||
};
|
||||
let message = app.printing.message.clone();
|
||||
if opened {
|
||||
app.print_memo.hidden = if result(&message) && app.print_memo.said == message { message.clone() } else { None };
|
||||
}
|
||||
// A different message (a job started again, then failed the same way) is shown afresh.
|
||||
if app.print_memo.hidden != message {
|
||||
app.print_memo.hidden = None;
|
||||
}
|
||||
let hide_message = app.print_memo.hidden.is_some();
|
||||
if hide_message {
|
||||
} else if result(&message) {
|
||||
// Shown here, so the next opening needn't repeat it.
|
||||
app.print_memo.said = message;
|
||||
} else {
|
||||
app.print_memo.said = None;
|
||||
}
|
||||
|
||||
let settings = |app: &mut WordApp, ui: &mut Ui| {
|
||||
@@ -223,7 +243,7 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
|
||||
}
|
||||
if native {
|
||||
if let Some(discover) = &app.services.printers {
|
||||
crate::printing::show(&mut app.printing, ui, discover, |label| crate::i18n::t(label).to_owned());
|
||||
crate::printing::show(&mut app.printing, ui, discover, hide_message, |label| crate::i18n::t(label).to_owned());
|
||||
}
|
||||
// A job can wait long on a sleeping printer's driver; Cancel frees the page.
|
||||
if app.printing.busy() && app.services.cancel_print.is_some() && ui.button(tl!("Cancel printing")).clicked() {
|
||||
|
||||
@@ -23,8 +23,8 @@ pub fn commands(app: &crate::WordApp) -> Vec<serde_json::Value> {
|
||||
}
|
||||
|
||||
/// Builds translated print labels, draws the shared print-settings panel, and shows the current
|
||||
/// feedback message.
|
||||
pub fn show(state: &mut State, ui: &mut egui::Ui, discover: &Discover, translate: impl Fn(&str) -> String) {
|
||||
/// feedback message (unless `hide_message`: this window has already said it).
|
||||
pub fn show(state: &mut State, ui: &mut egui::Ui, discover: &Discover, hide_message: bool, translate: impl Fn(&str) -> String) {
|
||||
let labels = Labels {
|
||||
printer: &translate("Printer"),
|
||||
select_printer: &translate("Select a printer"),
|
||||
@@ -38,7 +38,7 @@ pub fn show(state: &mut State, ui: &mut egui::Ui, discover: &Discover, translate
|
||||
grayscale: &translate("Grayscale"),
|
||||
};
|
||||
state.show(ui, egui::Id::unique("wordcraft_print_settings"), discover, &labels);
|
||||
if let Some(message) = &state.message {
|
||||
if let Some(message) = state.message.as_ref().filter(|_| !hide_message) {
|
||||
ui.label(feedback(message, translate));
|
||||
}
|
||||
}
|
||||
|
||||
+99
-23
@@ -3767,17 +3767,16 @@ fn the_print_button_shows_only_with_a_print_hook() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Opened again, the Print page doesn't repeat how the last job went (that was said once, in the
|
||||
/// status bar), but a failure that comes in while it is open stays, and what the printers are
|
||||
/// doing (none found) shows each time.
|
||||
#[test]
|
||||
fn the_print_page_opens_without_the_last_jobs_message() {
|
||||
use crate::printing::Feedback;
|
||||
/// A Print page with printers found (so it draws the job message), in English.
|
||||
fn print_page_harness(message: Option<crate::printing::Feedback>) -> egui_kittest::Harness<'static, WordApp> {
|
||||
let mut a = app();
|
||||
// A job went away earlier: its message was said in the status bar, and the page closed.
|
||||
a.printing.message = Some(Feedback::Submitted("job 7".into()));
|
||||
a.print_feedback_seen = a.printing.message.clone();
|
||||
a.run("file.print", json!({})).unwrap();
|
||||
a.ui.language = "en".into();
|
||||
a.services.printers = Some(Box::new(|| {
|
||||
let (sender, receiver) = std::sync::mpsc::channel();
|
||||
let _ = sender.send(vec![printing::Printer { name: "Test queue".into(), label: String::new(), default: true }]);
|
||||
receiver
|
||||
}));
|
||||
a.services.print_native = Some(Box::new(|_, _, _, _| std::sync::mpsc::channel().1));
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|
||||
|ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
@@ -3786,22 +3785,99 @@ fn the_print_page_opens_without_the_last_jobs_message() {
|
||||
},
|
||||
a,
|
||||
);
|
||||
// The page's first drawing starts discovery, which replaces the message: draw it once, leave,
|
||||
// and let the printers arrive.
|
||||
let _ = h.state_mut().run("file.print", json!({}));
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().printing.message, None, "the last job's message is gone");
|
||||
let _ = h.state_mut().run("ui.backstage", json!({"value": false}));
|
||||
h.run_steps(3);
|
||||
set_print_message(&mut h, message);
|
||||
h.state_mut().print_memo = Default::default();
|
||||
h
|
||||
}
|
||||
|
||||
/// A job message that arrives without the app's own `print_feedback` acting on it (a submitted job
|
||||
/// would close the Print page); what the window has said is set by the test.
|
||||
fn set_print_message(h: &mut egui_kittest::Harness<'_, WordApp>, message: Option<crate::printing::Feedback>) {
|
||||
h.state_mut().printing.message = message.clone();
|
||||
h.state_mut().print_feedback_seen = message;
|
||||
}
|
||||
|
||||
fn leave_and_reopen_print(h: &mut egui_kittest::Harness<'_, WordApp>) {
|
||||
let _ = h.state_mut().run("ui.backstage", json!({"value": false}));
|
||||
h.run_steps(2);
|
||||
let _ = h.state_mut().run("file.print", json!({}));
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
/// Opened again, the Print page doesn't repeat how the last job went when the window already said
|
||||
/// it (in its status bar), but a failure that comes in while it is open stays, and what the
|
||||
/// printers are doing (none found) shows each time. The shared message is never cleared, so
|
||||
/// `ui.printSettings` still reports it.
|
||||
#[test]
|
||||
fn the_print_page_opens_without_the_last_jobs_message() {
|
||||
use crate::printing::Feedback;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
let mut h = print_page_harness(Some(Feedback::Submitted("job 7".into())));
|
||||
// A job went away earlier: its message was said in this window's status bar, and the page closed.
|
||||
h.state_mut().print_memo.said = h.state().printing.message.clone();
|
||||
let _ = h.state_mut().run("file.print", json!({}));
|
||||
h.run_steps(4);
|
||||
assert!(h.query_by_label_contains("job 7").is_none(), "the last job's message isn't repeated");
|
||||
assert_eq!(h.state().printing.message, Some(Feedback::Submitted("job 7".into())), "but the shared message stays");
|
||||
// A failure arrives while the page is open, said (by the status bar) in the very frame, so
|
||||
// only the page being open keeps it showing: wrong reopen detection would hide it.
|
||||
let failure = Some(Feedback::Failed("no paper".into()));
|
||||
set_print_message(&mut h, failure.clone());
|
||||
h.state_mut().print_memo.said = failure.clone();
|
||||
h.run_steps(3);
|
||||
assert!(h.query_by_label_contains("no paper").is_some(), "a failure on the open page stays");
|
||||
leave_and_reopen_print(&mut h);
|
||||
assert!(h.query_by_label_contains("no paper").is_none(), "reopened, the failure isn't repeated");
|
||||
assert_eq!(h.state().printing.message, failure, "but it is still the shared message");
|
||||
set_print_message(&mut h, Some(Feedback::NoPrinters));
|
||||
leave_and_reopen_print(&mut h);
|
||||
assert!(h.query_by_label_contains("No printers found").is_some(), "no printers still shows");
|
||||
}
|
||||
|
||||
/// A result nobody has said yet isn't dropped: a failure that arrived while File showed another
|
||||
/// page (so no status bar was drawn) shows when Print opens.
|
||||
#[test]
|
||||
fn the_print_page_shows_a_result_that_was_never_said() {
|
||||
use crate::printing::Feedback;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
let mut h = print_page_harness(None);
|
||||
h.state_mut().ui.backstage = true;
|
||||
h.state_mut().ui.backstage_page = "home".into();
|
||||
h.run_steps(2);
|
||||
// Through the app's own `print_feedback` (run each frame), which says it in a status bar that isn't drawn.
|
||||
h.state_mut().printing.message = Some(Feedback::Failed("no paper".into()));
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().printing.message, Some(Feedback::Failed("no paper".into())), "a failure on the open page stays");
|
||||
let leave_and_reopen = |h: &mut egui_kittest::Harness<'_, WordApp>| {
|
||||
let _ = h.state_mut().run("ui.backstage", json!({"value": false}));
|
||||
h.run_steps(2);
|
||||
let _ = h.state_mut().run("file.print", json!({}));
|
||||
h.run_steps(2);
|
||||
};
|
||||
leave_and_reopen(&mut h);
|
||||
assert_eq!(h.state().printing.message, None, "reopened, the failure is gone");
|
||||
h.state_mut().printing.message = Some(Feedback::NoPrinters);
|
||||
leave_and_reopen(&mut h);
|
||||
assert_eq!(h.state().printing.message, Some(Feedback::NoPrinters), "no printers still shows");
|
||||
assert_eq!(h.state().print_memo.said, None, "File's home page doesn't say it");
|
||||
let _ = h.state_mut().run("file.print", json!({}));
|
||||
h.run_steps(4);
|
||||
assert!(h.query_by_label_contains("no paper").is_some());
|
||||
}
|
||||
|
||||
/// Per window: what one window has said of the last job isn't another window's, and the shared
|
||||
/// message is the same in both. (The harness draws one viewport, which re-enters a window of its
|
||||
/// own, so the per-window state is checked where windows swap; `the_print_page_opens_without_the_last_jobs_message`
|
||||
/// and `the_print_page_shows_a_result_that_was_never_said` show what each state does on the page.)
|
||||
#[test]
|
||||
fn the_print_pages_of_two_windows_decide_separately() {
|
||||
use crate::printing::Feedback;
|
||||
let failure = Some(Feedback::Failed("no paper".into()));
|
||||
let mut a = app();
|
||||
a.printing.message = failure.clone();
|
||||
let first = a.windows.shown();
|
||||
a.print_memo.said = failure.clone();
|
||||
a.new_window();
|
||||
assert_ne!(first, a.windows.shown());
|
||||
assert_eq!(a.print_memo.said, None, "the second window never said it, so its page shows it");
|
||||
assert_eq!(a.printing.message, failure, "the message is shared, and still there");
|
||||
assert!(a.enter_window(first));
|
||||
assert_eq!(a.print_memo.said, failure, "the first window said it, so its page doesn't repeat it");
|
||||
assert_eq!(a.printing.message, failure);
|
||||
}
|
||||
|
||||
/// Return on the Print page prints, as in Word, where ⌘P opens on Print as the default
|
||||
|
||||
@@ -39,7 +39,7 @@ pub(crate) struct WindowUi {
|
||||
pub(crate) seen_full_screen: Option<bool>,
|
||||
pub(crate) escape_free: bool,
|
||||
pub(crate) status_counts: (u64, crate::StatusCounts),
|
||||
pub(crate) print_page_pass: Option<(egui::ViewportId, u64)>,
|
||||
pub(crate) print_memo: crate::print_page::Memo,
|
||||
/// Per window, as each window shows its own layout: one shared list would be read again
|
||||
/// on every frame of every window.
|
||||
pub(crate) missing_fonts: crate::chrome::MissingFontsMemo,
|
||||
@@ -113,7 +113,7 @@ impl WindowUi {
|
||||
seen_full_screen: None,
|
||||
escape_free: false,
|
||||
status_counts: NOT_COUNTED,
|
||||
print_page_pass: None,
|
||||
print_memo: Default::default(),
|
||||
missing_fonts: Default::default(),
|
||||
last_autosave: 0.0,
|
||||
equation_prev_tab: None,
|
||||
@@ -245,7 +245,7 @@ impl WordApp {
|
||||
seen_full_screen,
|
||||
escape_free,
|
||||
status_counts,
|
||||
print_page_pass,
|
||||
print_memo,
|
||||
missing_fonts,
|
||||
last_autosave,
|
||||
equation_prev_tab,
|
||||
@@ -352,7 +352,7 @@ impl WordApp {
|
||||
seen_full_screen,
|
||||
escape_free,
|
||||
status_counts,
|
||||
print_page_pass,
|
||||
print_memo,
|
||||
missing_fonts,
|
||||
last_autosave,
|
||||
equation_prev_tab,
|
||||
|
||||
+2
-2
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user