Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

LR-IMP-DRAGDROP: a drop is refused while a Local folder browse scan runs, not only an import or review scan

Nathaniel Ledford8ec606c6550a
diff --git a/crates/ui-egui/src/import.rs b/crates/ui-egui/src/import.rs
index cf4d667aa..d66694273 100644
--- a/crates/ui-egui/src/import.rs
+++ b/crates/ui-egui/src/import.rs
@@ -647,16 +647,23 @@ fn show_pending_review(app: &mut LightcraftApp, ctx: &egui::Context) {
/// Tests: a review scan that never ends while the returned value lives, so a drop meets it running.
#[cfg(test)]
pub(crate) fn stall_scan(app: &mut LightcraftApp) -> Box<dyn std::any::Any> {
+ stall_scan_of(app, false)
+}
+
+/// Tests: the same, for a Local folder browse scan (`browse`) instead of the review's scan.
+#[cfg(test)]
+pub(crate) fn stall_scan_of(app: &mut LightcraftApp, browse: bool) -> Box<dyn std::any::Any> {
let progress = std::sync::Arc::new(ScanProgress::default());
let (tx, rx) = std::sync::mpsc::channel::<ScanOutput>();
let guard = scan_guard(app, &progress, false);
- app.scan = Some(ScanTask { progress, rx, copy: false, album: None, browse: false, sources: Vec::new(), guard });
+ app.scan = Some(ScanTask { progress, rx, copy: false, album: None, browse, sources: Vec::new(), guard });
Box::new(tx)
}
-/// Whether an import (or the review's scan) is running, which a drop of photos must not replace.
+/// Whether an import or any scan (the review's, or a Local folder browse) is running, which a drop of
+/// photos must not replace: `open` refuses while a scan runs, and a browse that finishes replaces `app.import`.
pub fn running(app: &LightcraftApp) -> bool {
- app.import.is_some() || app.scan.as_ref().is_some_and(|t| !t.browse)
+ app.import.is_some() || app.scan.is_some()
}
impl ScanTask {
diff --git a/crates/ui-egui/src/tests_drop_import.rs b/crates/ui-egui/src/tests_drop_import.rs
index bee26a184..c82d62278 100644
--- a/crates/ui-egui/src/tests_drop_import.rs
+++ b/crates/ui-egui/src/tests_drop_import.rs
@@ -200,6 +200,28 @@ fn a_direct_drop_while_an_import_runs_is_refused_too() {
assert!(h.app.ui.toast.is_some());
}
+/// A Local folder browse scan counts too: a review-first drop would be rejected by `open`, and a
+/// direct drop would be replaced when the browse completes.
+#[test]
+fn a_drop_while_a_browse_scan_runs_is_refused_in_both_modes() {
+ for direct in [false, true] {
+ let dir = Scratch::new("running-browse");
+ let mut h = app(&dir);
+ h.app.ui.settings.import_dropped_directly = direct;
+ write_png(&dir.path("more/c.png"), 3);
+ let _scan = crate::import::stall_scan_of(&mut h.app, true);
+ drop_files(&mut h, &[dir.path("more/c.png")], true);
+ assert!(said(&h, "An import is running"), "{:?}", h.painted_text());
+ drop_files(&mut h, &[dir.path("more")], false);
+ for _ in 0..30 {
+ h.step();
+ }
+ assert!(h.app.ui.dialog.is_none() && h.app.import.is_none(), "direct={direct}: nothing started");
+ assert!(h.app.scan.is_some(), "the browse was left alone");
+ assert!(h.app.ui.toast.is_some(), "the person is told why");
+ }
+}
+
/// While a Lightroom catalog import is pending the drop is refused, and the card says so instead of
/// promising a review.
#[test]