Apply completed jobs while showing progress

This commit is contained in:
yoriswind committed 2026-11-30 17:43:53 -08:00
1 parent 0e2ee79784
commit 250ba3e76a
9 files changed
+34 -9

No files matched your search

+1 -2
View File
@@ -13,7 +13,6 @@
use std::time::Duration;
use craft::ui::dialog::{JobAnswer, JobProgress};
use craft::ui::runtime::overlay::OpenFilter;
use serde_json::json;
use crate::VectorcraftApp;
@@ -69,7 +68,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) {
return;
}
// Progress is modal for input, but the window must not block itself on its next pass.
if app.dialog_open(OpenFilter::Asks) {
if app.asking_dialog_open() {
return;
}
let Shown { title, step, fraction, counts, queued, cancel, hide, .. } = shown;
+6 -1
View File
@@ -378,8 +378,13 @@ impl VectorcraftApp {
self.dialog_open(OpenFilter::Modal)
}
/// Whether a question or popup is open. Applying a job's result can close its progress window.
pub(crate) fn asking_dialog_open(&self) -> bool {
self.dialog_open(OpenFilter::Asks)
}
/// Whether a layer matching the filter, a popup or a pending app modal is open.
pub(crate) fn dialog_open(&self, filter: OpenFilter) -> bool {
fn dialog_open(&self, filter: OpenFilter) -> bool {
// A modeless layer with a focus scope (the canvas's task bar) takes keys too, and blocks nothing.
let popup = |ctx: &egui::Context| overlay::top(ctx).and_then(|id| overlay::entry(ctx, id)).is_some_and(|e| e.rank == overlay::Rank::Popup);
self.ui_ctx.as_ref().is_some_and(|ctx| overlay::any_open(ctx, filter) || popup(ctx))
+1 -1
View File
@@ -148,7 +148,7 @@ fn track(app: &mut VectorcraftApp, path: &str, done: Receiver<Result<ReadFile, S
/// May the active document change now ([`poll`])?
pub(crate) fn may_switch(app: &mut VectorcraftApp) -> bool {
if app.any_dialog_open() || crate::dialogs::missing_fonts::waiting(app) {
if app.asking_dialog_open() || crate::dialogs::missing_fonts::waiting(app) {
return false;
}
let s = &app.session;
+18
View File
@@ -573,6 +573,24 @@ fn a_file_that_takes_a_while_to_open_shows_a_progress_window() {
assert_eq!(app.session.documents().len(), before + 2);
}
#[test]
fn a_file_ready_while_progress_is_visible_opens_without_hiding_progress() {
let mut app = VectorcraftApp::new(Session::new(), Services::default());
app.now_override = Some(0.0);
let ctx = crate::testing::ui_context();
app.adopt_context(&ctx);
start(&mut app, "/art/Big.vectorcraft", bytes("Big"));
age(&mut app);
progress(&mut app, &ctx);
assert!(progress(&mut app, &ctx).contains("Opening Big.vectorcraft"));
assert!(app.any_dialog_open());
open_ready(&mut app);
assert!(app.opening.pending.is_empty());
assert_eq!(app.session.doc().unwrap().path.as_deref(), Some("/art/Big.vectorcraft"));
assert_eq!(progress(&mut app, &ctx), "", "completion closes progress");
}
/// #5930: the progress window's Cancel (`file.cancelOpen`): the file doesn't open, even once it
/// has been read, and the status bar no longer says it is opening.
#[test]
+1 -1
View File
@@ -445,7 +445,7 @@ fn spawn_labeled(
/// the file is placed unless the tool has a preview open (the Flare tool after its center drag).
pub fn poll(app: &mut VectorcraftApp) {
settle_swatch_paste(app);
while !app.any_dialog_open()
while !app.asking_dialog_open()
&& !app.session.in_interaction()
&& !(app.session.tool_busy() && app.session.pointer_held())
&& let Some(p) = app.placing.pending.first()
+4 -1
View File
@@ -1980,6 +1980,7 @@ fn a_file_that_takes_a_while_to_place_shows_a_progress_window() {
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
let ctx = crate::testing::ui_context();
app.adopt_context(&ctx);
assert_eq!(progress(&mut app, &ctx), "", "nothing placing");
let slow_path = saved("progress", "slow.png", &picture(Png, 100, 100));
@@ -2002,10 +2003,12 @@ fn a_file_that_takes_a_while_to_place_shows_a_progress_window() {
start(&mut app, &json!({"path": next_path, "at": [200, 150]}), false).unwrap();
let texts = progress(&mut app, &ctx);
assert!(texts.contains("Placing slow.png…") && texts.contains("waiting"), "{texts}");
assert!(app.any_dialog_open());
// Release and finish
// Releasing the read applies both files without dismissing the progress window first.
drop(go);
placed(&mut app);
assert_eq!(progress(&mut app, &ctx), "", "completion closes progress");
}
/// #5930: cancelling a place aborts the operation, drops the parsed asset, leaves the document
+1 -1
View File
@@ -458,7 +458,7 @@ pub fn poll(app: &mut VectorcraftApp) {
poll_checks(app);
let mut i = 0;
while let Some(r) = app.plugin_runs.running.get(i) {
let dialog = app.any_dialog_open() || app.session.script_running();
let dialog = app.asking_dialog_open() || app.session.script_running();
let ended = match &r.backend {
Backend::Thread(_) if dialog => None,
Backend::Worker(..) if dialog => watch_worker(app, i),
+1 -1
View File
@@ -130,7 +130,7 @@ fn stop(app: &mut VectorcraftApp) {
/// Runs the command of the search that is done (each frame). Not while a dialog is open, nor while
/// an interaction is open or a tool drags with the pointer button held, as [`crate::trace_runs::poll`].
pub fn poll(app: &mut VectorcraftApp) {
if app.any_dialog_open() || app.session.in_interaction() || (app.session.tool_busy() && app.session.pointer_held()) {
if app.asking_dialog_open() || app.session.in_interaction() || (app.session.tool_busy() && app.session.pointer_held()) {
return;
}
let Some(r) = &app.retype_runs.running else { return };
+1 -1
View File
@@ -140,7 +140,7 @@ pub fn start(app: &mut VectorcraftApp, command: &str, p: Value, from_panel: bool
/// dialog is open (its OK acts on the active document, which a trace's result changes), nor while
/// an interaction is open or a tool drags with the pointer button held, as [`crate::placing::poll`].
pub fn poll(app: &mut VectorcraftApp) {
if app.any_dialog_open() || app.session.in_interaction() || (app.session.tool_busy() && app.session.pointer_held()) {
if app.asking_dialog_open() || app.session.in_interaction() || (app.session.tool_busy() && app.session.pointer_held()) {
return;
}
let mut i = 0;