From fc1f200afc341eda4375e3383668e4424e4d6ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 15:01:30 -0500 Subject: [PATCH 1/7] fix(ui): a map's text draft, spectral points, dialogs and import follow it when it moves (#2959) --- crates/ui-egui/src/dialogs.rs | 33 +++++++++------ crates/ui-egui/src/graphicformat.rs | 38 ++++++++++++++--- crates/ui-egui/src/labelpane.rs | 27 ++++++++++-- crates/ui-egui/src/repairsource.rs | 7 ++-- crates/ui-egui/src/serviceui.rs | 33 ++++++++++----- crates/ui-egui/src/spectralui.rs | 42 +++++++++++++++---- .../tests/integration/define_projection.rs | 24 +++++++++++ 7 files changed, 162 insertions(+), 42 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index ef0d3dc4c5..773ba438d1 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -12,6 +12,16 @@ use std::hash::{Hash, Hasher}; use crate::theme::{Tokens, semibold}; use crate::{RustGisApp, i18n}; +/// A live map by what it is (`Map::instance_id`, whatever its place among the project's maps, so +/// moving it is not another map) and its name, which a rename changes. +pub(crate) type MapKey = (u64, String); + +/// The map in view, as a dialog, an import or a form remembers it to find it again. +pub(crate) fn map_key(s: &Session) -> MapKey { + let map = s.map(); + (map.instance_id(), map.name.clone()) +} + #[derive(Default)] pub struct Dialogs { /// Project Properties: the system text last read, and what was said of it (and whether that is @@ -20,7 +30,7 @@ pub struct Dialogs { /// The layer captured when Define Projection opens; changing selection must not retarget it. pub projection_layer: Option, /// Map-local layer IDs require the dialog to retain its original project and map as well. - pub projection_map: Option<(u64, usize, String)>, + pub projection_map: Option<(u64, MapKey)>, pub geometry: Option, /// Publication Layout Wizard: what it has asked so far (#2850). pub publication: Option, @@ -39,7 +49,7 @@ pub struct Dialogs { /// The live instance captured with the map-local ID; Undo can make that ID reusable. pub gpkg_instance: Option, /// Layer IDs are map-local; source writes must stay in the captured project and map. - pub gpkg_map: Option<(u64, usize, String)>, + pub gpkg_map: Option<(u64, MapKey)>, /// The source-backed layer last counted: its name for PostGIS, numeric ID for GeoPackage. pub counted: String, /// Revision after the last count command, which itself advances the session revision. @@ -217,7 +227,7 @@ impl Dialogs { match name { "defineProjection" => { self.projection_layer = active.map(|l| l.id); - self.projection_map = Some((s.opened, s.project.active_map, s.map().name.clone())); + self.projection_map = Some((s.opened, map_key(s))); self.text = active.and_then(|l| l.dataset.crs).map(|c| c.definition_text()).unwrap_or_else(|| "EPSG:4326".into()); } "coordinateSystem" => { @@ -276,7 +286,7 @@ impl Dialogs { let layer = active.filter(gpkg).or_else(|| s.map().layers.iter().find(gpkg)); self.gpkg_layer = layer.map(|l| l.id); self.gpkg_instance = layer.map(|l| l.instance_id()); - self.gpkg_map = Some((s.opened, s.project.active_map, s.map().name.clone())); + self.gpkg_map = Some((s.opened, map_key(s))); } // A table of addresses is what's usually geocoded: picked by its id (`flag` says the // choice is a table), since names can repeat. @@ -291,11 +301,7 @@ impl Dialogs { } fn gpkg_owner(&self, s: &Session) -> Result<(), String> { - if !self - .gpkg_map - .as_ref() - .is_some_and(|(project, index, name)| *project == s.opened && *index == s.project.active_map && *name == s.map().name) - { + if !self.gpkg_map.as_ref().is_some_and(|(project, map)| *project == s.opened && *map == map_key(s)) { return Err(tl!("The active project or map changed; reopen the GeoPackage dialog for the intended layer.").into()); } Ok(()) @@ -618,9 +624,12 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { } } close = buttons(app, ui, "Apply", |app| { - if !app.dialogs.projection_map.as_ref().is_some_and(|(project, index, name)| { - *project == app.session.opened && *index == app.session.project.active_map && *name == app.session.map().name - }) { + if !app + .dialogs + .projection_map + .as_ref() + .is_some_and(|(project, map)| *project == app.session.opened && *map == map_key(&app.session)) + { return Err(tl!("The active project or map changed; reopen Define Projection for the intended layer.").into()); } let id = app.dialogs.projection_layer.ok_or(tl!("No layer selected"))?; diff --git a/crates/ui-egui/src/graphicformat.rs b/crates/ui-egui/src/graphicformat.rs index 6819353b49..3ca4aacc14 100644 --- a/crates/ui-egui/src/graphicformat.rs +++ b/crates/ui-egui/src/graphicformat.rs @@ -10,9 +10,9 @@ use rustgis_engine::map::graphics; use crate::RustGisApp; use crate::theme::Tokens; -/// A text graphic, by map (its index in the project), layer id and row: layer ids and rows are a -/// map's own. -type Key = (usize, u32, usize); +/// A text graphic, by map (`Map::instance_id`, whatever its place among the project's maps), layer +/// id and row: layer ids and rows are a map's own. +type Key = (u64, u32, usize); #[derive(Default)] pub struct GraphicFormat { @@ -40,7 +40,7 @@ pub(crate) fn selected(app: &RustGisApp) -> Option<(u32, usize)> { } fn key(app: &RustGisApp, (layer, row): (u32, usize)) -> Key { - (app.session.project.active_map, layer, row) + (app.session.map().instance_id(), layer, row) } /// Opens the Format pane when another text is selected on the map (run each frame the map shows). @@ -179,7 +179,7 @@ pub(crate) fn save_draft(app: &mut RustGisApp) { return; } let (map, layer, row) = k; - let here = opened == app.session.opened && map == app.session.project.active_map; + let here = opened == app.session.opened && map == app.session.map().instance_id(); let current = app.session.map().layer(layer).and_then(|l| graphics::label(&l.dataset, row)).map(str::to_string); // A blank text goes to `graphics.edit` too, which refuses it and says so, as when Enter ends it. if here && current.is_some_and(|c| c != text) { @@ -270,6 +270,34 @@ mod tests { assert!(edit(h.state_mut(), layer, row + 99).is_err()); } + /// The map with the text being typed moves (its tab, Move Up, `map.move`) and stays in view: the + /// pane keeps the text and saves it when it ends, instead of dropping it for "another map" (#2959). + #[test] + fn moving_the_map_keeps_the_text_being_typed() { + let mut app = RustGisApp::with_sample(); + let added = app.run("graphics.add", json!({"shape": "text", "points": [[10, 50]], "text": "Old"})).unwrap(); + let (layer, row) = (added["layer"].as_u64().unwrap() as u32, added["row"].as_u64().unwrap() as usize); + let first = app.session.map().name.clone(); + let mut h = harness(app); + h.run_steps(2); + h.state_mut().run("select.rows", json!({"layer": layer, "rows": [row]})).unwrap(); + h.run_steps(3); + h.query_all_by_role(Role::MultilineTextInput).find(|n| n.value().as_deref() == Some("Old")).unwrap().focus(); + h.run_steps(2); + h.query_all_by_role(Role::MultilineTextInput).find(|n| n.is_focused()).unwrap().type_text("New"); + h.run_steps(2); + h.state_mut().run("map.new", json!({"name": "Second"})).unwrap(); + h.state_mut().run("map.activate", json!({"name": first})).unwrap(); + h.state_mut().run("map.move", json!({"name": first, "to": 1})).unwrap(); + assert_eq!(h.state().session.project.active_map, 1, "the map in view moved to the end"); + h.state_mut().run("select.rows", json!({"layer": layer, "rows": [row]})).unwrap(); + h.run_steps(3); + h.state_mut().run("ui.pane.format", json!({})).unwrap(); + h.run_steps(2); + let label = h.state().session.map().layer(layer).and_then(|l| graphics::label(&l.dataset, row)).map(str::to_string); + assert!(label.as_deref().is_some_and(|t| t.contains("New")), "{label:?}"); + } + /// A text cleared in the pane is refused, as `graphics.edit` refuses one: when Enter ends it and /// when the pane closes over it alike. The text keeps what it said, and stays on the map. #[test] diff --git a/crates/ui-egui/src/labelpane.rs b/crates/ui-egui/src/labelpane.rs index 8ce46d8495..6c55d1e3b2 100644 --- a/crates/ui-egui/src/labelpane.rs +++ b/crates/ui-egui/src/labelpane.rs @@ -142,10 +142,12 @@ fn shown(c: &Class) -> String { } /// `l` as a layer of this map of this project: another map, or another project, may reuse its id. -/// A map goes by its place and its name, as Define Projection's does: deleting a map moves the -/// next one into its place, and a copy keeps its layer ids. +/// A map goes by what it is (`Map::instance_id`) and its name, as Define Projection's does: moving +/// it keeps its typed text, a map deleted before it doesn't hand its state to the next one, and a +/// copy keeps its layer ids and is another map. pub(crate) fn layer_key(app: &RustGisApp, l: &Layer) -> egui::Id { - egui::Id::unique((app.session.opened, app.session.project.active_map, app.session.map().name.as_str(), l.id)) + let map = app.session.map(); + egui::Id::unique((app.session.opened, map.instance_id(), map.name.as_str(), l.id)) } /// Where the class chosen on a layer is kept. @@ -1433,6 +1435,25 @@ mod tests { app.session.map().layers.iter().find(|l| l.name == name).unwrap().id } + /// What the pane and the Unique Values box keep for a layer (the class chosen, a search, the + /// typed expression) is found again when its map moves among the maps; another map's layer of the + /// same id is another key (#2959). + #[test] + fn a_layers_state_follows_its_map_when_the_map_moves() { + let mut app = with_cities(); + let id = layer_id(&app, "Cities"); + let first = app.session.map().name.clone(); + let key = |app: &RustGisApp| super::layer_key(app, app.session.map().layer(id).unwrap()); + let before = key(&app); + app.run("map.new", json!({"name": "Second"})).unwrap(); + app.run("map.activate", json!({"name": first})).unwrap(); + app.run("map.move", json!({"name": first, "to": 1})).unwrap(); + assert_eq!(app.session.project.active_map, 1, "the map in view moved to the end"); + assert_eq!(key(&app), before, "the same map, moved"); + app.run("map.duplicate", json!({"name": first})).unwrap(); + assert_ne!(key(&app), before, "a copy keeps the layer ids and is another map"); + } + fn with_cities() -> RustGisApp { // Keep the font picker ready before the harness checks its role or settles the layout. super::families::installed(); diff --git a/crates/ui-egui/src/repairsource.rs b/crates/ui-egui/src/repairsource.rs index 84fb1d7b46..9b0bd6818c 100644 --- a/crates/ui-egui/src/repairsource.rs +++ b/crates/ui-egui/src/repairsource.rs @@ -18,7 +18,7 @@ pub enum Target { pub struct Form { target: Target, opened: u64, - map: (usize, String), + map: crate::dialogs::MapKey, /// An index is not an identity: closing on a different archive prevents accidental retargeting. archive: Option<(String, rustgis_engine::map::TileKind)>, name: String, @@ -58,7 +58,7 @@ impl Form { Ok(Self { target, opened: s.opened, - map: (s.project.active_map, s.map().name.clone()), + map: crate::dialogs::map_key(s), archive: match target { Target::Layer(_) => None, Target::Tiles(index) => s.map().tiles.get(index).map(|t| (t.id.clone(), t.kind)), @@ -139,8 +139,7 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { return; }; if app.session.opened != f.opened - || app.session.project.active_map != f.map.0 - || app.session.map().name != f.map.1 + || crate::dialogs::map_key(&app.session) != f.map || match f.target { Target::Layer(id) => app.session.map().layer(id).is_none(), Target::Tiles(index) => app.session.map().tiles.get(index).is_none_or(|t| { diff --git a/crates/ui-egui/src/serviceui.rs b/crates/ui-egui/src/serviceui.rs index 54c3285207..7a82c752c3 100644 --- a/crates/ui-egui/src/serviceui.rs +++ b/crates/ui-egui/src/serviceui.rs @@ -74,9 +74,9 @@ pub struct Import { /// The saved web-service connection to record on imported layers, not a group-plan parameter. connection: Option, token: u64, - /// The originating map: its index and name (names are unique among a project's maps), so a - /// deleted or replaced map at that index cancels the import. - map: (usize, String), + /// The originating map (`dialogs::map_key`), so a deleted or replaced map cancels the import and + /// a moved one doesn't. + map: crate::dialogs::MapKey, slot: Slot, String>>, document: Option, current: Option, @@ -342,7 +342,7 @@ pub fn start(app: &mut RustGisApp, p: &Value, refresh: bool) -> Result<(), Strin refresh, connection, token: app.session.download_started(), - map: active_map(app), + map: crate::dialogs::map_key(&app.session), slot: Slot::default(), document: None, current: None, @@ -464,14 +464,9 @@ impl Import { } } -fn active_map(app: &RustGisApp) -> (usize, String) { - let i = app.session.project.active_map; - (i, app.session.project.maps.get(i).map(|m| m.name.clone()).unwrap_or_default()) -} - pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { let Some(mut task) = app.ui.service_import.take() else { return }; - if !app.session.download_is_pending(task.token) || active_map(app) != task.map { + if !app.session.download_is_pending(task.token) || crate::dialogs::map_key(&app.session) != task.map { app.session.download_failed(task.token); return; } @@ -687,6 +682,24 @@ fn noted(app: &mut RustGisApp, landed: &Landed, note: Option) { mod tests { use super::*; + /// The map an import started on is told by what it is, not by its place among the maps: the same + /// map moved is the same, another map (even a copy under its place) isn't (#2959). + #[test] + fn an_import_follows_its_map_when_it_moves() { + let mut app = RustGisApp::with_sample(); + let first = app.session.map().name.clone(); + app.run("map.new", json!({"name": "Second"})).unwrap(); + let second = crate::dialogs::map_key(&app.session); + app.run("map.activate", json!({"name": first})).unwrap(); + let before = crate::dialogs::map_key(&app.session); + assert_ne!(before, second); + app.run("map.move", json!({"name": first, "to": 1})).unwrap(); + assert_eq!(app.session.project.active_map, 1, "the map in view moved to the end"); + assert_eq!(crate::dialogs::map_key(&app.session), before, "the same map, moved"); + app.run("map.activate", json!({"name": "Second"})).unwrap(); + assert_eq!(crate::dialogs::map_key(&app.session), second, "the other map, now first"); + } + /// Add From Service records a document it read from the internet: the document it links to /// is fetched only from there, and a layer listed there is added restricted to it, however /// their names resolve. A service read from the local network links to its own documents as diff --git a/crates/ui-egui/src/spectralui.rs b/crates/ui-egui/src/spectralui.rs index 4fed09ae20..2577fde7ee 100644 --- a/crates/ui-egui/src/spectralui.rs +++ b/crates/ui-egui/src/spectralui.rs @@ -40,9 +40,10 @@ pub struct Spectral { pub bands: Vec, /// Each band's wavelength in nanometres; empty when the file gives none. pub wavelengths: Vec>, - /// The map (its place in the project) and layer the points were read on: a raster of the - /// same name on another map, or added again, isn't the same one. - pub source: Option<(usize, u32)>, + /// The map (`Map::instance_id`, whatever its place among the project's maps) and layer the + /// points were read on: a raster of the same name on another map, or added again, isn't the + /// same one. + pub source: Option<(u64, u32)>, /// The pixels the points were read from: a raster edited in place (Pixel Editor, say) keeps /// its layer and name but not these, so its points are no longer what it holds. read_on: std::sync::Weak, @@ -118,9 +119,10 @@ pub fn colour(t: &Tokens, slot: usize) -> Color32 { colours.get(slot % colours.len()).copied().unwrap_or(t.accent) } -/// The map (its place in the project) and layer the commands read as `layer`. -fn source_of(app: &RustGisApp, layer: &str) -> Option<(usize, u32)> { - app.session.map().layer_by_name(layer).map(|l| (app.session.project.active_map, l.id)) +/// The map (by identity) and layer the commands read as `layer`. +fn source_of(app: &RustGisApp, layer: &str) -> Option<(u64, u32)> { + let map = app.session.map(); + map.layer_by_name(layer).map(|l| (map.instance_id(), l.id)) } /// The pixels of the raster `layer` names now, for [`Spectral::read_on`] (none when it has none). @@ -133,7 +135,7 @@ fn data_of(app: &RustGisApp, layer: &str) -> std::sync::Weak Date: Wed, 25 Nov 2026 16:00:50 -0500 Subject: [PATCH 2/7] test(ui): the label-pane key test checks that map.duplicate renews the map's identity (#2959) --- crates/ui-egui/src/labelpane.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/labelpane.rs b/crates/ui-egui/src/labelpane.rs index 6c55d1e3b2..05c7803937 100644 --- a/crates/ui-egui/src/labelpane.rs +++ b/crates/ui-egui/src/labelpane.rs @@ -1450,8 +1450,11 @@ mod tests { app.run("map.move", json!({"name": first, "to": 1})).unwrap(); assert_eq!(app.session.project.active_map, 1, "the map in view moved to the end"); assert_eq!(key(&app), before, "the same map, moved"); + let original = app.session.map().instance_id(); app.run("map.duplicate", json!({"name": first})).unwrap(); - assert_ne!(key(&app), before, "a copy keeps the layer ids and is another map"); + // The copy is named " copy", which the key tells apart anyway: it is the identity that + // `map.duplicate` renews, and the key is built from it. + assert_ne!(app.session.map().instance_id(), original, "a copy keeps the layer ids and is another map"); } fn with_cities() -> RustGisApp { From d319720b673ca5a8554ade2208a145866d1d18d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 16:14:11 -0500 Subject: [PATCH 3/7] test(ui): an import in flight, the GeoPackage prompt and Repair Data Source follow their map when it moves (#2959) --- crates/ui-egui/src/dialogs.rs | 16 ++++++++++++ crates/ui-egui/src/labelpane.rs | 3 ++- crates/ui-egui/src/repairsource.rs | 41 +++++++++++++++++++++++++----- crates/ui-egui/src/serviceui.rs | 32 +++++++++++++++++++++++ 4 files changed, 84 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 773ba438d1..304686db04 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -3482,6 +3482,22 @@ fn calculation_preview(rows: &[rustgis_engine::cmd::edit::CalculationPreview]) - mod tests { use super::*; + /// The GeoPackage prompt belongs to the map it opened on, wherever that map goes among the maps; + /// another map or project refuses it (#2959). + #[test] + fn the_gpkg_prompt_follows_its_map_when_the_map_moves() { + let mut app = RustGisApp::with_sample(); + let first = app.session.map().name.clone(); + let dialogs = Dialogs { gpkg_map: Some((app.session.opened, map_key(&app.session))), ..Dialogs::default() }; + assert!(dialogs.gpkg_owner(&app.session).is_ok()); + app.run("map.new", json!({"name": "Second"})).unwrap(); + assert!(dialogs.gpkg_owner(&app.session).is_err(), "another map is in view"); + app.run("map.activate", json!({"name": first})).unwrap(); + app.run("map.move", json!({"name": first, "to": 1})).unwrap(); + assert_eq!(app.session.project.active_map, 1, "the map in view moved to the end"); + assert!(dialogs.gpkg_owner(&app.session).is_ok(), "the same map, moved"); + } + #[test] fn narrow_desktop_dialog_remembers_its_dragged_position() { use egui::accesskit::Role; diff --git a/crates/ui-egui/src/labelpane.rs b/crates/ui-egui/src/labelpane.rs index 05c7803937..00f999eebc 100644 --- a/crates/ui-egui/src/labelpane.rs +++ b/crates/ui-egui/src/labelpane.rs @@ -144,7 +144,8 @@ fn shown(c: &Class) -> String { /// `l` as a layer of this map of this project: another map, or another project, may reuse its id. /// A map goes by what it is (`Map::instance_id`) and its name, as Define Projection's does: moving /// it keeps its typed text, a map deleted before it doesn't hand its state to the next one, and a -/// copy keeps its layer ids and is another map. +/// copy keeps its layer ids and is another map. Renaming the map starts its layers' state afresh, +/// as it always did. pub(crate) fn layer_key(app: &RustGisApp, l: &Layer) -> egui::Id { let map = app.session.map(); egui::Id::unique((app.session.opened, map.instance_id(), map.name.as_str(), l.id)) diff --git a/crates/ui-egui/src/repairsource.rs b/crates/ui-egui/src/repairsource.rs index 9b0bd6818c..f5a4d5a3ed 100644 --- a/crates/ui-egui/src/repairsource.rs +++ b/crates/ui-egui/src/repairsource.rs @@ -133,12 +133,10 @@ impl Form { } /// Shows the captured source and runs the appropriate undoable repair command. -pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { - let Some(f) = app.dialogs.repair.take() else { - app.dialogs.open = None; - return; - }; - if app.session.opened != f.opened +/// The form's item is no longer where it was opened on: another project or map (a moved map is the +/// same one), or its layer or tile layer gone or replaced. +fn gone(app: &RustGisApp, f: &Form) -> bool { + app.session.opened != f.opened || crate::dialogs::map_key(&app.session) != f.map || match f.target { Target::Layer(id) => app.session.map().layer(id).is_none(), @@ -146,7 +144,14 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { t.archive_file() != Some(f.saved.as_str()) || f.archive.as_ref().is_none_or(|(id, kind)| t.id != *id || t.kind != *kind) }), } - { +} + +pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { + let Some(f) = app.dialogs.repair.take() else { + app.dialogs.open = None; + return; + }; + if gone(app, &f) { app.dialogs.open = None; return; } @@ -303,6 +308,28 @@ mod tests { slot } + /// The form stays for its map when that map moves among the maps; another map, or a layer that + /// is gone, closes it (#2959). + #[test] + fn the_form_follows_its_map_when_the_map_moves() { + let mut app = RustGisApp::with_sample(); + let layer = app.session.map().layers[0].id; + let first = app.session.map().name.clone(); + let mut f = form(); + f.target = Target::Layer(layer); + f.opened = app.session.opened; + f.map = crate::dialogs::map_key(&app.session); + assert!(!gone(&app, &f)); + app.run("map.new", json!({"name": "Second"})).unwrap(); + assert!(gone(&app, &f), "another map is in view"); + app.run("map.activate", json!({"name": first})).unwrap(); + app.run("map.move", json!({"name": first, "to": 1})).unwrap(); + assert_eq!(app.session.project.active_map, 1, "the map in view moved to the end"); + assert!(!gone(&app, &f), "the same map, moved"); + f.opened += 1; + assert!(gone(&app, &f), "another project"); + } + #[test] fn editing_only_invalidates_discovery_and_keeps_the_table_default() { let mut f = form(); diff --git a/crates/ui-egui/src/serviceui.rs b/crates/ui-egui/src/serviceui.rs index 7a82c752c3..de7c5a0857 100644 --- a/crates/ui-egui/src/serviceui.rs +++ b/crates/ui-egui/src/serviceui.rs @@ -682,6 +682,38 @@ fn noted(app: &mut RustGisApp, landed: &Landed, note: Option) { mod tests { use super::*; + /// An import in flight goes on when its map moves among the maps, and is given up when another + /// map is in view (#2959). + #[test] + fn an_import_in_flight_goes_on_when_its_map_moves() { + let mut app = RustGisApp::with_sample(); + let first = app.session.map().name.clone(); + let token = app.session.download_started(); + app.ui.service_import = Some(Import { + params: json!({}), + refresh: false, + connection: None, + token, + map: crate::dialogs::map_key(&app.session), + slot: Slot::default(), + document: Some("https://example.test/capabilities".into()), + current: None, + remaining: VecDeque::new(), + responses: Vec::new(), + bytes: 0, + }); + let ctx = egui::Context::default(); + app.run("map.new", json!({"name": "Second"})).unwrap(); + app.run("map.activate", json!({"name": first})).unwrap(); + app.run("map.move", json!({"name": first, "to": 1})).unwrap(); + assert_eq!(app.session.project.active_map, 1, "the map in view moved to the end"); + poll(&mut app, &ctx); + assert!(app.ui.service_import.is_some() && app.session.download_is_pending(token), "the same map, moved"); + app.run("map.activate", json!({"name": "Second"})).unwrap(); + poll(&mut app, &ctx); + assert!(app.ui.service_import.is_none() && !app.session.download_is_pending(token), "another map is in view"); + } + /// The map an import started on is told by what it is, not by its place among the maps: the same /// map moved is the same, another map (even a copy under its place) isn't (#2959). #[test] From 81d86ecc31c96aaea56c3832ae88b7d7e71d499b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 16:28:10 -0500 Subject: [PATCH 4/7] docs(ui): the repair form's doc comment goes back above show (#2959) --- crates/ui-egui/src/repairsource.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/repairsource.rs b/crates/ui-egui/src/repairsource.rs index f5a4d5a3ed..21154c7bb2 100644 --- a/crates/ui-egui/src/repairsource.rs +++ b/crates/ui-egui/src/repairsource.rs @@ -132,7 +132,6 @@ impl Form { } } -/// Shows the captured source and runs the appropriate undoable repair command. /// The form's item is no longer where it was opened on: another project or map (a moved map is the /// same one), or its layer or tile layer gone or replaced. fn gone(app: &RustGisApp, f: &Form) -> bool { @@ -146,6 +145,7 @@ fn gone(app: &RustGisApp, f: &Form) -> bool { } } +/// Shows the captured source and runs the appropriate undoable repair command. pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { let Some(f) = app.dialogs.repair.take() else { app.dialogs.open = None; From b852d0de5297f016a5df81636839588fd240f661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 16:49:09 -0500 Subject: [PATCH 5/7] refactor(ui): one MapOwner holds the project and map a dialog or form was opened on (#2959) --- crates/ui-egui/src/dialogs.rs | 38 ++++++++++++++++++++---------- crates/ui-egui/src/repairsource.rs | 17 +++++-------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 304686db04..8e5a145228 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -22,6 +22,25 @@ pub(crate) fn map_key(s: &Session) -> MapKey { (map.instance_id(), map.name.clone()) } +/// The project (`Session::opened`) and the map in view a dialog or a form was opened on: layer ids +/// are a map's own, so what it captured is only good while both are still in view. +#[derive(Clone, Debug, PartialEq)] +pub struct MapOwner { + project: u64, + map: MapKey, +} + +impl MapOwner { + pub(crate) fn of(s: &Session) -> Self { + Self { project: s.opened, map: map_key(s) } + } + + /// Whether `s` still has that project open with that map in view (a moved map is the same one). + pub(crate) fn holds(&self, s: &Session) -> bool { + self.project == s.opened && self.map == map_key(s) + } +} + #[derive(Default)] pub struct Dialogs { /// Project Properties: the system text last read, and what was said of it (and whether that is @@ -30,7 +49,7 @@ pub struct Dialogs { /// The layer captured when Define Projection opens; changing selection must not retarget it. pub projection_layer: Option, /// Map-local layer IDs require the dialog to retain its original project and map as well. - pub projection_map: Option<(u64, MapKey)>, + pub projection_map: Option, pub geometry: Option, /// Publication Layout Wizard: what it has asked so far (#2850). pub publication: Option, @@ -49,7 +68,7 @@ pub struct Dialogs { /// The live instance captured with the map-local ID; Undo can make that ID reusable. pub gpkg_instance: Option, /// Layer IDs are map-local; source writes must stay in the captured project and map. - pub gpkg_map: Option<(u64, MapKey)>, + pub gpkg_map: Option, /// The source-backed layer last counted: its name for PostGIS, numeric ID for GeoPackage. pub counted: String, /// Revision after the last count command, which itself advances the session revision. @@ -227,7 +246,7 @@ impl Dialogs { match name { "defineProjection" => { self.projection_layer = active.map(|l| l.id); - self.projection_map = Some((s.opened, map_key(s))); + self.projection_map = Some(MapOwner::of(s)); self.text = active.and_then(|l| l.dataset.crs).map(|c| c.definition_text()).unwrap_or_else(|| "EPSG:4326".into()); } "coordinateSystem" => { @@ -286,7 +305,7 @@ impl Dialogs { let layer = active.filter(gpkg).or_else(|| s.map().layers.iter().find(gpkg)); self.gpkg_layer = layer.map(|l| l.id); self.gpkg_instance = layer.map(|l| l.instance_id()); - self.gpkg_map = Some((s.opened, map_key(s))); + self.gpkg_map = Some(MapOwner::of(s)); } // A table of addresses is what's usually geocoded: picked by its id (`flag` says the // choice is a table), since names can repeat. @@ -301,7 +320,7 @@ impl Dialogs { } fn gpkg_owner(&self, s: &Session) -> Result<(), String> { - if !self.gpkg_map.as_ref().is_some_and(|(project, map)| *project == s.opened && *map == map_key(s)) { + if !self.gpkg_map.as_ref().is_some_and(|owner| owner.holds(s)) { return Err(tl!("The active project or map changed; reopen the GeoPackage dialog for the intended layer.").into()); } Ok(()) @@ -624,12 +643,7 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { } } close = buttons(app, ui, "Apply", |app| { - if !app - .dialogs - .projection_map - .as_ref() - .is_some_and(|(project, map)| *project == app.session.opened && *map == map_key(&app.session)) - { + if !app.dialogs.projection_map.as_ref().is_some_and(|owner| owner.holds(&app.session)) { return Err(tl!("The active project or map changed; reopen Define Projection for the intended layer.").into()); } let id = app.dialogs.projection_layer.ok_or(tl!("No layer selected"))?; @@ -3488,7 +3502,7 @@ mod tests { fn the_gpkg_prompt_follows_its_map_when_the_map_moves() { let mut app = RustGisApp::with_sample(); let first = app.session.map().name.clone(); - let dialogs = Dialogs { gpkg_map: Some((app.session.opened, map_key(&app.session))), ..Dialogs::default() }; + let dialogs = Dialogs { gpkg_map: Some(MapOwner::of(&app.session)), ..Dialogs::default() }; assert!(dialogs.gpkg_owner(&app.session).is_ok()); app.run("map.new", json!({"name": "Second"})).unwrap(); assert!(dialogs.gpkg_owner(&app.session).is_err(), "another map is in view"); diff --git a/crates/ui-egui/src/repairsource.rs b/crates/ui-egui/src/repairsource.rs index 21154c7bb2..ad7418e5f2 100644 --- a/crates/ui-egui/src/repairsource.rs +++ b/crates/ui-egui/src/repairsource.rs @@ -17,8 +17,7 @@ pub enum Target { #[cfg_attr(target_arch = "wasm32", expect(dead_code, reason = "the browser can't pick a replacement file, so it reads less of the form"))] pub struct Form { target: Target, - opened: u64, - map: crate::dialogs::MapKey, + owner: crate::dialogs::MapOwner, /// An index is not an identity: closing on a different archive prevents accidental retargeting. archive: Option<(String, rustgis_engine::map::TileKind)>, name: String, @@ -57,8 +56,7 @@ impl Form { }; Ok(Self { target, - opened: s.opened, - map: crate::dialogs::map_key(s), + owner: crate::dialogs::MapOwner::of(s), archive: match target { Target::Layer(_) => None, Target::Tiles(index) => s.map().tiles.get(index).map(|t| (t.id.clone(), t.kind)), @@ -135,8 +133,7 @@ impl Form { /// The form's item is no longer where it was opened on: another project or map (a moved map is the /// same one), or its layer or tile layer gone or replaced. fn gone(app: &RustGisApp, f: &Form) -> bool { - app.session.opened != f.opened - || crate::dialogs::map_key(&app.session) != f.map + !f.owner.holds(&app.session) || match f.target { Target::Layer(id) => app.session.map().layer(id).is_none(), Target::Tiles(index) => app.session.map().tiles.get(index).is_none_or(|t| { @@ -287,8 +284,7 @@ mod tests { fn form() -> Form { Form { target: Target::Layer(1), - opened: 0, - map: (0, String::new()), + owner: crate::dialogs::MapOwner::of(&rustgis_engine::Session::new(rustgis_engine::Project::default())), archive: None, name: "Cities".into(), saved: "old.gpkg".into(), @@ -317,8 +313,7 @@ mod tests { let first = app.session.map().name.clone(); let mut f = form(); f.target = Target::Layer(layer); - f.opened = app.session.opened; - f.map = crate::dialogs::map_key(&app.session); + f.owner = crate::dialogs::MapOwner::of(&app.session); assert!(!gone(&app, &f)); app.run("map.new", json!({"name": "Second"})).unwrap(); assert!(gone(&app, &f), "another map is in view"); @@ -326,7 +321,7 @@ mod tests { app.run("map.move", json!({"name": first, "to": 1})).unwrap(); assert_eq!(app.session.project.active_map, 1, "the map in view moved to the end"); assert!(!gone(&app, &f), "the same map, moved"); - f.opened += 1; + app.run("project.new", json!({})).unwrap(); assert!(gone(&app, &f), "another project"); } From 6f2d7e8cc1b272cb2c2bce13f1aa854c1dc1a68e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 17:18:08 -0500 Subject: [PATCH 6/7] refactor(ui): MapOwner::holds compares the map without cloning its name (#2959) --- crates/ui-egui/src/dialogs.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 8e5a145228..846174a3d1 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -37,7 +37,8 @@ impl MapOwner { /// Whether `s` still has that project open with that map in view (a moved map is the same one). pub(crate) fn holds(&self, s: &Session) -> bool { - self.project == s.opened && self.map == map_key(s) + let map = s.map(); + self.project == s.opened && self.map.0 == map.instance_id() && self.map.1 == map.name } } From 2817aec693999cfc6e45edd4eb080b107675f7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 17:32:48 -0500 Subject: [PATCH 7/7] docs(ui): the import's map doc says a rename cancels it too (#2959) --- crates/ui-egui/src/serviceui.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/serviceui.rs b/crates/ui-egui/src/serviceui.rs index de7c5a0857..0ddb8132ca 100644 --- a/crates/ui-egui/src/serviceui.rs +++ b/crates/ui-egui/src/serviceui.rs @@ -74,8 +74,8 @@ pub struct Import { /// The saved web-service connection to record on imported layers, not a group-plan parameter. connection: Option, token: u64, - /// The originating map (`dialogs::map_key`), so a deleted or replaced map cancels the import and - /// a moved one doesn't. + /// The originating map (`dialogs::map_key`), so a deleted, replaced or renamed map cancels the + /// import and a moved one doesn't. map: crate::dialogs::MapKey, slot: Slot, String>>, document: Option,