diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 6d63ec2715..8ff0162418 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -2847,6 +2847,11 @@ impl RustGisApp { }; } match name.strip_prefix(DELIMITED_PICK) { + // A cancelled picker opens nothing; its request's options end with it. + Some("") => { + self.ui.pending_csv = None; + Ok(Value::Null) + } Some(name) => match self.ui.pending_csv.take() { Some(Value::Null) => dialogs::open_csv(self, name, dialogs::CsvSource::Bytes(bytes.to_vec())), csv => self.open_bytes_with(name, bytes, csv), @@ -7712,6 +7717,13 @@ impl RustGisApp { if let Some(id) = name.strip_prefix(DXF_PICK).and_then(|p| p.split_once(':')).and_then(|(id, _)| id.parse::().ok()) { self.ui.pending_dxf.remove(&id); } + // So does the request a held answer was for: its options or command aren't left + // for a later, unrelated file to be opened with. + if name.starts_with(DELIMITED_PICK) { + self.ui.pending_csv = None; + } else if !name.starts_with('\u{1}') { + self.ui.pending_open = None; + } held += 1; continue; } @@ -10963,6 +10975,27 @@ mod peer_output_tests { assert!(notices.is_empty(), "a cancelled Shapefile picker said: {notices:?}"); assert_eq!(h.state_mut().open_picked(SHAPEFILE_PICK, &[]), Ok(Value::Null)); assert!(h.state_mut().open_picked(&format!("{SHAPEFILE_PICK}roads.shp"), &[]).is_err(), "a non-zip name is still refused"); + // A cancelled Add Delimited Text picker opens nothing and ends its request. + h.state_mut().ui.pending_csv = Some(Value::Null); + let mark = h.state().session.notice_mark(); + inbox.lock().unwrap().push((DELIMITED_PICK.to_string(), Vec::new())); + h.step(); + assert!( + h.state().ui.pending_csv.is_none() && h.state().dialogs.open.is_none(), + "a cancelled Add Delimited Text opened {:?}", + h.state().dialogs.open + ); + assert!(h.state().session.notices_since(mark).is_empty()); + // A picked file held while the prompt waits ends the picker's request: the command it + // was for isn't left for the next file opened. + h.state_mut().ui.pending_open = Some("project.fromTemplate"); + inbox.lock().unwrap().push(("other.rgistemplate".to_string(), b"{}".to_vec())); + h.step(); + assert_eq!(h.state().ui.pending_open, None); + h.state_mut().ui.pending_csv = Some(json!({"x": "lon", "y": "lat"})); + inbox.lock().unwrap().push((format!("{DELIMITED_PICK}places.csv"), b"lon,lat\n1,2\n".to_vec())); + h.step(); + assert!(h.state().ui.pending_csv.is_none(), "a held Add Delimited Text answer ends its request"); assert_eq!(h.state().session.map().layers.len(), layers, "nothing is added to the project about to be replaced"); assert_eq!(h.state().session.map().name, "Unsaved Map"); }