From a3d59d870e4aaefed2d995bf5874843c605e9282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sat, 28 Nov 2026 09:03:28 -0500 Subject: [PATCH 1/2] fix(engine): say which presentation pages lack their map when a project opens --- crates/engine/src/cmd/presentation.rs | 30 +++--- crates/engine/src/project.rs | 6 +- crates/engine/src/tests/layout_removed_map.rs | 98 ++++++++++++++++++- docs/user-guide/layouts.md | 4 +- 4 files changed, 123 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/cmd/presentation.rs b/crates/engine/src/cmd/presentation.rs index 64efe8dce8..ae22308d06 100644 --- a/crates/engine/src/cmd/presentation.rs +++ b/crates/engine/src/cmd/presentation.rs @@ -633,24 +633,34 @@ fn page_map<'a>(input: &'a impl super::InputSource, name: &str) -> &'a rustgis_m s.project.maps.iter().find(|m| m.name.eq_ignore_ascii_case(name)).unwrap_or_else(|| s.map()) } -/// Most map names, presentations and page numbers [`say_pages_without_their_map`] lists: an +/// Most map names, presentations and page numbers [`pages_without_their_map`] lists: an /// imported file may hold hundreds of pages, each naming another map. const MISSING_MAPS_NAMED: usize = 3; const PRESENTATIONS_LISTED: usize = 3; const PAGES_LISTED: usize = 5; -/// The map pages [`say_pages_without_their_map`] looks at. +/// The map pages [`pages_without_their_map`] looks at. +#[derive(Clone, Copy)] pub(crate) enum PagesOf<'a> { + /// Every one: the project has just been opened. + All, /// Those naming this map, in every presentation: it has just gone. Map(&'a str), /// Those of the presentation at this index, whatever they name: it has just come in. Presentation(usize), } -/// Says, once, which of the map pages `which` name a map the project doesn't have, which +/// Says [`pages_without_their_map`], if there is anything to say. +pub(crate) fn say_pages_without_their_map(s: &mut Session, which: PagesOf<'_>) { + if let Some(notice) = pages_without_their_map(&s.project, which) { + s.notify_text(notice, false); + } +} + +/// One notice of which of the map pages `which` name a map the project doesn't have, which /// [`page_map`] draws over the active map (#3047). Pages are numbered from 1, as the Presentation /// pane shows them. The pages keep the name. -pub(crate) fn say_pages_without_their_map(s: &mut Session, which: PagesOf<'_>) { +pub(crate) fn pages_without_their_map(project: &crate::Project, which: PagesOf<'_>) -> Option { use crate::notice_text::NoticeText; /// A presentation listed: where it is, its name, its first pages and how many it has. @@ -663,14 +673,15 @@ pub(crate) fn say_pages_without_their_map(s: &mut Session, which: PagesOf<'_>) { let (mut pages, mut places) = (0usize, Vec::>::new()); let (mut named, mut more_maps, mut more_places) = (Vec::<&str>::new(), false, false); - for (i, pres) in s.project.presentations.iter().enumerate() { + for (i, pres) in project.presentations.iter().enumerate() { for (k, page) in pres.pages.iter().enumerate() { let PageKind::Map { map, .. } = &page.kind else { continue }; let looked_at = match which { + PagesOf::All => true, PagesOf::Map(gone) => map.eq_ignore_ascii_case(gone), PagesOf::Presentation(own) => i == own, }; - if !looked_at || s.project.maps.iter().any(|m| m.name.eq_ignore_ascii_case(map)) { + if !looked_at || project.maps.iter().any(|m| m.name.eq_ignore_ascii_case(map)) { continue; } pages += 1; @@ -704,9 +715,7 @@ pub(crate) fn say_pages_without_their_map(s: &mut Session, which: PagesOf<'_>) { } NoticeText::format(key, [("name", place.name.to_string().into()), ("numbers", numbers.into())]) }); - let Some(mut places) = listed.reduce(|first, next| NoticeText::format("{first}; {next}", [("first", first), ("next", next)])) else { - return; - }; + let mut places = listed.reduce(|first, next| NoticeText::format("{first}; {next}", [("first", first), ("next", next)]))?; if more_places { places = NoticeText::format("{first}; {next}", [("first", places), ("next", "…".to_string().into())]); } @@ -725,8 +734,7 @@ pub(crate) fn say_pages_without_their_map(s: &mut Session, which: PagesOf<'_>) { if more_maps { names.push_str(", …"); } - let notice = NoticeText::format(key, [("count", pages.to_string().into()), ("names", names.into()), ("places", places)]); - s.notify_text(notice, false); + Some(NoticeText::format(key, [("count", pages.to_string().into()), ("names", names.into()), ("places", places)])) } /// Binds the map whose current view initializes the page. diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 1a1d64a64a..7cd53ea26e 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1540,7 +1540,11 @@ impl Project { /// as it is. Returns a notice for each kind of change that removed, cut or renamed /// something, with the part of the project it is about. pub(crate) fn normalize_opened(&mut self) -> Vec<(ReadPart, NoticeText)> { - self.repair(true, "while opening the project") + let mut notices = self.repair(true, "while opening the project"); + // Pages naming a map the project doesn't have are drawn over the active map (#3191). + use crate::cmd::presentation::{PagesOf, pages_without_their_map}; + notices.extend(pages_without_their_map(self, PagesOf::All).map(|notice| (ReadPart::Items, notice))); + notices } /// Reports removed or shortened content, renamed items and repaired group display settings diff --git a/crates/engine/src/tests/layout_removed_map.rs b/crates/engine/src/tests/layout_removed_map.rs index b28b114d12..21fb974d07 100644 --- a/crates/engine/src/tests/layout_removed_map.rs +++ b/crates/engine/src/tests/layout_removed_map.rs @@ -1,5 +1,6 @@ //! A presentation map page whose map the project doesn't have is drawn over the active map: -//! deleting the map, or importing such a presentation, says which pages (#3047). All keep the name. +//! deleting the map, importing such a presentation (#3047) or opening a project that has such pages +//! (#3191) says which pages. All keep the name. use super::*; use rustgis_map::presentation::{Page, PageKind, Presentation}; @@ -210,3 +211,98 @@ fn pages_past_three_presentations_are_counted_and_not_listed() { ] ); } + +const GONE_ON_PAGE_2: &str = "1 map page shows 'Gone', which the project doesn't have, so it is drawn over the active map until a map of that name comes back: presentation 'Tour', page 2"; + +/// The project of [`with_tour`] with a map page showing `map`, which no command checks any more. +fn project_showing(map: &str) -> Session { + let mut s = with_tour(); + page(&mut s, "Other"); + let PageKind::Map { map: shown, .. } = &mut s.project.presentations[0].pages[1].kind else { panic!("a map page") }; + *shown = map.into(); + s +} + +fn text_of(s: &Session) -> Value { + json!({"text": serde_json::to_string(&s.project).unwrap()}) +} + +/// The notices about missing page maps among those `s` holds. +fn held(s: &Session) -> Vec { + s.notices.iter().map(|n| n.text.clone()).filter(|t| t.contains("which the project doesn't have")).collect() +} + +#[test] +fn opening_a_project_says_the_pages_whose_map_is_missing() { + let text = text_of(&project_showing("Gone")); + let mut s = Session::new(Project::default()); + assert_eq!(missing(&mut s, "project.openText", text), [GONE_ON_PAGE_2]); + let PageKind::Map { map, .. } = &s.project.presentations[0].pages[1].kind else { panic!("a map page") }; + assert_eq!(map, "Gone"); +} + +#[test] +fn opening_a_saved_file_after_deleting_the_map_says_so() { + let mut saved = with_tour(); + page(&mut saved, "Other"); + saved.run("map.remove", &json!({"name": "Other"})).unwrap(); + let dir = std::env::temp_dir().join(format!("rustgis-pages-without-map-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let path = dir.join("tour.rgis"); + saved.project.save(&path).unwrap(); + let mut s = Session::new(Project::default()); + let said = missing(&mut s, "project.open", json!({"path": path})); + let _ = std::fs::remove_dir_all(&dir); + assert_eq!(said, [GONE_ON_PAGE_2.replace("'Gone'", "'Other'")]); +} + +#[test] +fn a_session_started_with_such_a_project_says_so() { + let text = serde_json::to_string(&project_showing("Gone").project).unwrap(); + let s = Session::new(Project::from_json(&text).unwrap()); + assert_eq!(held(&s), [GONE_ON_PAGE_2]); +} + +#[test] +fn a_peer_opening_such_a_project_says_so() { + let text = serde_json::to_string(&project_showing("Gone").project).unwrap(); + let mut s = Session::new(Project::default()); + s.open_peer_text(crate::Peer::Embedder, &text).unwrap(); + assert_eq!(held(&s), [GONE_ON_PAGE_2]); +} + +#[test] +fn opening_a_project_whose_pages_have_their_maps_says_nothing() { + let text = text_of(&project_showing("oTHER")); + let mut s = Session::new(Project::default()); + assert_eq!(missing(&mut s, "project.openText", text), Vec::::new()); +} + +#[test] +fn opening_a_project_with_no_presentation_says_nothing() { + let text = text_of(&world()); + let mut s = Session::new(Project::default()); + assert_eq!(missing(&mut s, "project.openText", text), Vec::::new()); +} + +#[test] +fn opening_a_project_says_the_pages_of_two_presentations_once() { + let mut saved = project_showing("Gone"); + saved.run("presentation.new", &json!({"name": "Second"})).unwrap(); + let gone = saved.project.presentations[0].pages[1].clone(); + saved.project.presentations[1].pages.push(gone); + let mut s = Session::new(Project::default()); + assert_eq!( + missing(&mut s, "project.openText", text_of(&saved)), + [ + "2 map pages show 'Gone', which the project doesn't have, so they are drawn over the active map until a map of that name comes back: presentation 'Tour', page 2; presentation 'Second', page 2" + ] + ); +} + +#[test] +fn importing_the_maps_of_such_a_project_says_nothing_of_its_pages() { + let text = text_of(&project_showing("Gone")); + let mut s = world(); + assert_eq!(missing(&mut s, "map.import", text), Vec::::new()); +} diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index d79bcdb5c2..411a8336d1 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -983,8 +983,8 @@ previews, edits and plays it. URL with an optional poster picture. - Each page has a title, speaker notes and a duration (for **Play**), and can move up or down. - A **Map** page follows its map by name. While the project has no map of that name, the page is - drawn over the active map; deleting the map (or the offline area that goes with it), or - importing a presentation that names it, says which pages. + drawn over the active map; deleting the map (or the offline area that goes with it), + importing a presentation that names it, or opening a project with such a page says which pages. - **Publish › Output › Presentation › Export Presentation** writes an HTML slideshow (arrow keys, `N` for notes, `P` to play; videos play in place), a PDF (kept as vectors as a layout's is), or the first page as PNG. From 786d6fe649f22a90acac707bfcf70f13f12b9956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sat, 28 Nov 2026 09:19:31 -0500 Subject: [PATCH 2/2] docs(engine): note the missing-page notice on opening a project --- crates/engine/src/cmd/presentation.rs | 1 - crates/engine/src/project.rs | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/presentation.rs b/crates/engine/src/cmd/presentation.rs index ae22308d06..260ca9d761 100644 --- a/crates/engine/src/cmd/presentation.rs +++ b/crates/engine/src/cmd/presentation.rs @@ -640,7 +640,6 @@ const PRESENTATIONS_LISTED: usize = 3; const PAGES_LISTED: usize = 5; /// The map pages [`pages_without_their_map`] looks at. -#[derive(Clone, Copy)] pub(crate) enum PagesOf<'a> { /// Every one: the project has just been opened. All, diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 7cd53ea26e..83739212b6 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1538,7 +1538,8 @@ impl Project { /// those `map.addTiles` adds) as raster layers read in place: as the project opens only. A /// later repair (a layer file added, maps imported) leaves a tile layer added this session /// as it is. Returns a notice for each kind of change that removed, cut or renamed - /// something, with the part of the project it is about. + /// something, and one for the presentation pages whose map the project doesn't have, each + /// with the part of the project it is about. pub(crate) fn normalize_opened(&mut self) -> Vec<(ReadPart, NoticeText)> { let mut notices = self.repair(true, "while opening the project"); // Pages naming a map the project doesn't have are drawn over the active map (#3191).