mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-02 06:27:53 -06:00
Quit asks about an import handed its files this tick, before it is listed, and about files still waiting
This commit is contained in:
@@ -51,6 +51,11 @@ pub struct ImportTask {
|
||||
}
|
||||
|
||||
impl ImportTask {
|
||||
/// Whether it has its row in the activity list yet (it gets one on its first tick).
|
||||
pub fn listed(&self) -> bool {
|
||||
self.guard.is_some()
|
||||
}
|
||||
|
||||
/// An import of `paths` (files or folders) with `library.import` params (without `paths`).
|
||||
pub fn new(paths: Vec<String>, params: Value, undo0: usize, browse: bool) -> Self {
|
||||
ImportTask { total: paths.len(), queue: paths, params, undo0, browse, ..Default::default() }
|
||||
|
||||
@@ -65,9 +65,15 @@ pub fn may_close(app: &mut LightcraftApp) -> bool {
|
||||
}
|
||||
// before the library is touched: a Cancel here keeps working with it
|
||||
let running = app.session.activity.running_cancellable();
|
||||
if !running.is_empty() {
|
||||
let names = running.iter().map(|t| crate::i18n::tr(&t.label)).collect::<Vec<_>>().join(", ");
|
||||
app.quit_prompt = Some(QuitPrompt::Tasks(tasks_message(running.len(), &names)));
|
||||
let mut names = running.iter().map(|t| crate::i18n::tr(&t.label)).collect::<Vec<_>>();
|
||||
// an import handed its files this tick (files that waited for a library, #2779) is listed only
|
||||
// from its first tick on, and files still waiting will be imported too
|
||||
let unlisted = app.import.as_ref().is_some_and(|t| !t.listed()) || !app.waiting_import.files.is_empty();
|
||||
if unlisted && !running.iter().any(|t| t.kind == "import") {
|
||||
names.push(crate::i18n::tr("Importing"));
|
||||
}
|
||||
if !names.is_empty() {
|
||||
app.quit_prompt = Some(QuitPrompt::Tasks(tasks_message(names.len(), &names.join(", "))));
|
||||
return false;
|
||||
}
|
||||
if app.session.unsaved().is_none() {
|
||||
|
||||
@@ -852,9 +852,23 @@ fn waiting_files_wait_for_a_running_import_instead_of_being_dropped() {
|
||||
assert!(r.as_ref().is_err_and(|e| e.contains("waiting")), "{r:?}");
|
||||
assert_eq!(h.app.session.library.as_ref().map(|l| l.dir.clone()), Some(lib.clone()));
|
||||
|
||||
// the window is hidden from here on: only the background logic runs, and the waiting file
|
||||
// still goes in once the first import ends
|
||||
// quitting while the file waits asks first
|
||||
assert!(!crate::panels::notices::may_close(&mut h.app));
|
||||
h.app.quit_prompt = None;
|
||||
|
||||
// the window is hidden from here on: only the background logic runs. The tick that hands the
|
||||
// file to a new import (once the first one ends) leaves that import unlisted until its own
|
||||
// first tick, and quitting right then still asks
|
||||
let t0 = std::time::Instant::now();
|
||||
while !h.app.waiting_import.files.is_empty() && t0.elapsed() < T {
|
||||
let ctx = h.view.ctx.clone();
|
||||
h.app.logic(&ctx);
|
||||
std::thread::sleep(Duration::from_millis(2));
|
||||
}
|
||||
assert!(h.app.waiting_import.files.is_empty(), "the file was handed to a new import");
|
||||
assert!(h.app.import.as_ref().is_some_and(|t| !t.listed()), "not listed before its first tick");
|
||||
assert!(!crate::panels::notices::may_close(&mut h.app), "quitting asks about the import just handed over");
|
||||
h.app.quit_prompt = None;
|
||||
while !(h.app.import.is_none() && h.app.session.catalog.len() == 101) && t0.elapsed() < T {
|
||||
let ctx = h.view.ctx.clone();
|
||||
h.app.logic(&ctx);
|
||||
|
||||
Reference in New Issue
Block a user