* claim: #8266 * Computing toast: a Cancel that gives up on the move (#8266) The Computing toast for a history command (marker move, undo, redo, suppress, reorder) or a delete's check computing off the window thread now has a Cancel button. It drops the job and the commands queued behind it; the design stays as it was, since a deferred command only runs for real once its evaluation is in. A feature edit applying keeps its dialog's own Cancel, so its toast shows none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: thocsmith <193096300+thocsmith@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -52,6 +52,17 @@ impl Deferred {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl Deferred {
|
||||
/// A command that never finishes computing, with the sender that keeps it so, for the tests
|
||||
/// of what waits for one (the real worker would finish in a moment).
|
||||
pub(crate) fn never_done(id: &str, params: Value, revision: u64) -> (Self, std::sync::mpsc::Sender<Option<solidcraft_engine::Evaluated>>) {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let job = Deferred { done: rx, evaluated: None, started: crate::now_ms(), command: (id.to_string(), params), revision, kept: None };
|
||||
(job, tx)
|
||||
}
|
||||
}
|
||||
|
||||
/// How a command asked to run off the window thread goes.
|
||||
enum Start {
|
||||
/// It computes off the window thread.
|
||||
@@ -176,6 +187,25 @@ impl SolveApp {
|
||||
started.into_iter().flatten().reduce(f64::min)
|
||||
}
|
||||
|
||||
/// Whether the "Computing" toast can stop what it waits for (#8266): a history command or a
|
||||
/// delete's check computing off the window thread. A feature edit applying has its own
|
||||
/// dialog, with its own Cancel.
|
||||
pub fn can_cancel_computing(&self) -> bool {
|
||||
self.deferred.is_some() || self.delete_check.is_some()
|
||||
}
|
||||
|
||||
/// Stop waiting for the history command, and the delete check, computing off the window thread
|
||||
/// (#8266), and drop the commands waiting behind them. The design is as it was before they
|
||||
/// started: a command only runs for real once its evaluation is in. The worker threads run
|
||||
/// to the end of what they evaluate and their results are dropped (the same as Cancel while a
|
||||
/// feature is applying).
|
||||
pub fn cancel_computing(&mut self) {
|
||||
self.deferred = None;
|
||||
self.deferred_queue.clear();
|
||||
self.delete_check = None;
|
||||
self.start_after_roll = None;
|
||||
}
|
||||
|
||||
/// Run a delete's check `commands` and carry on with `then` once their replies are in: off
|
||||
/// the window thread when it takes longer than the app's wait (see the module notes),
|
||||
/// otherwise right away. A Delete while another delete is being checked is left out.
|
||||
|
||||
@@ -209,6 +209,43 @@ fn a_marker_moved_again_replaces_the_move_still_waiting() {
|
||||
assert_eq!(marker(&h), None, "where the drag ended: the end of the history");
|
||||
}
|
||||
|
||||
/// The "Computing" toast has a Cancel (#8266): it gives up on a marker move that takes too long, and
|
||||
/// on the moves waiting behind it, and the design stays as it was.
|
||||
#[test]
|
||||
fn cancel_on_the_computing_toast_gives_up_on_the_move() {
|
||||
let mut h = block_boss_hole();
|
||||
// A move that does not finish, with another waiting behind it.
|
||||
let (job, _keep) = crate::deferred::Deferred::never_done("timeline.roll_to", json!({"position": 1}), h.app.session.revision);
|
||||
h.app.deferred = Some(job);
|
||||
h.app.deferred_queue.push(("timeline.roll_to".into(), json!({"position": 2})));
|
||||
h.frames(2);
|
||||
let toast = crate::scenario::rect_of("toast:computing").expect("the computing toast");
|
||||
let cancel = crate::scenario::handle_at("toast:computing:cancel").expect("its Cancel");
|
||||
assert!(toast.contains(cancel), "{cancel:?} in {toast:?}");
|
||||
assert!(h.widget("Cancel").is_some(), "Cancel has an accessible name");
|
||||
h.step(&json!({"click": {"handle": "toast:computing:cancel"}})).unwrap();
|
||||
h.frames(2);
|
||||
assert!(h.app.deferred.is_none() && h.app.deferred_queue.is_empty(), "nothing computes or waits");
|
||||
assert!(h.app.computing_since().is_none());
|
||||
assert!(crate::scenario::rect_of("toast:computing").is_none(), "the toast is gone");
|
||||
assert_eq!(marker(&h), None, "the marker stays where it was");
|
||||
// And the history moves again afterwards.
|
||||
h.app.run_heavy("timeline.roll_to", json!({"position": 1})).unwrap();
|
||||
until_settled(&mut h);
|
||||
assert_eq!(marker(&h), Some(1));
|
||||
}
|
||||
|
||||
/// A feature edit applying has the dialog's own Cancel, so its toast has none.
|
||||
#[test]
|
||||
fn the_computing_toast_has_no_cancel_for_what_cannot_be_given_up() {
|
||||
let mut h = block_boss_hole();
|
||||
assert!(!h.app.can_cancel_computing(), "nothing computes");
|
||||
h.app.run_heavy("timeline.roll_to", json!({"position": 1})).unwrap();
|
||||
assert!(h.app.can_cancel_computing(), "a move can be given up");
|
||||
until_settled(&mut h);
|
||||
assert!(!h.app.can_cancel_computing());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn undo_computes_off_the_window_thread() {
|
||||
let mut h = block_boss_hole();
|
||||
|
||||
@@ -5348,7 +5348,17 @@ pub(crate) fn transient_messages(app: &mut SolveApp, ui: &egui::Ui, viewport: Re
|
||||
if let Some(since) = app.computing_since() {
|
||||
let seconds = ((crate::now_ms() - since) / 1000.0).floor().max(0.0);
|
||||
let text = crate::i18n::format("dialog.computing", &[("seconds", &format!("{seconds:.0}"))]);
|
||||
if let Some(r) = paint_toast(ui, free, text, false, true) {
|
||||
// A history command or a delete's check can be given up on (#8266); a feature edit
|
||||
// applying has the dialog's Cancel instead.
|
||||
let cancel = app.tr_label("Cancel").to_string();
|
||||
let actions: Vec<(&str, ToastKind)> = if app.can_cancel_computing() { vec![(cancel.as_str(), ToastKind::Secondary)] } else { Vec::new() };
|
||||
if let Some((r, clicked, buttons)) = paint_toast_with(ui, free, text, ToastLead::Spinner, &actions) {
|
||||
if let Some(button) = buttons.first() {
|
||||
crate::scenario::publish_handle("toast:computing:cancel", button.center());
|
||||
}
|
||||
if clicked == Some(0) {
|
||||
app.cancel_computing();
|
||||
}
|
||||
obstacles.push(r);
|
||||
crate::scenario::publish_rect("toast:computing", r);
|
||||
if app.status.is_none() {
|
||||
|
||||
Reference in New Issue
Block a user