Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions crates/engine/src/cmd/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,24 +633,33 @@ 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.
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<crate::notice_text::NoticeText> {
use crate::notice_text::NoticeText;

/// A presentation listed: where it is, its name, its first pages and how many it has.
Expand All @@ -663,14 +672,15 @@ pub(crate) fn say_pages_without_their_map(s: &mut Session, which: PagesOf<'_>) {

let (mut pages, mut places) = (0usize, Vec::<Place<'_>>::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)) {
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
continue;
}
pages += 1;
Expand Down Expand Up @@ -704,9 +714,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())]);
}
Expand All @@ -725,8 +733,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.
Expand Down
9 changes: 7 additions & 2 deletions crates/engine/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,9 +1538,14 @@ 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)> {
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};
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
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
Expand Down
98 changes: 97 additions & 1 deletion crates/engine/src/tests/layout_removed_map.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<String> {
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::<String>::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::<String>::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::<String>::new());
}
4 changes: 2 additions & 2 deletions docs/user-guide/layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading