From 55d784ad91dbccfd39d26f9222c1049ec2acc8e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Mon, 30 Nov 2026 07:53:33 -0500 Subject: [PATCH 1/4] feat(project): reopen a project on the layout that was open (#3446) --- crates/engine/src/cmd/project.rs | 3 +- crates/engine/src/lib.rs | 5 +- crates/engine/src/project.rs | 6 + crates/engine/src/project_capabilities.rs | 1 + crates/engine/src/tests.rs | 3 + crates/engine/src/tests/layout_open.rs | 162 ++++++++++++++++++++++ docs/user-guide/workspace.md | 4 + schema/project.schema.json | 10 ++ 8 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 crates/engine/src/tests/layout_open.rs diff --git a/crates/engine/src/cmd/project.rs b/crates/engine/src/cmd/project.rs index 92e19268fc..79ba3c719f 100644 --- a/crates/engine/src/cmd/project.rs +++ b/crates/engine/src/cmd/project.rs @@ -416,7 +416,8 @@ fn reset(s: &mut Session, p: Project) { s.active_layer = s.map().layers.first().map(|l| l.id); s.table_layer = None; s.table_standalone = None; - s.active_layout = None; + // The layout open when it was saved; one the file doesn't have is the map view (#3446). + s.active_layout = s.project.open_layout.filter(|i| *i < s.project.layouts.len()); s.tool = Tool::Explore; s.clear_history(); s.file_identity = s.state(); diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index afb4312b6f..08628caca5 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -4374,11 +4374,14 @@ impl Session { self.layer_selection_of = active; } - /// Keeps `active_layer` pointing at a layer of the active map. + /// Keeps `active_layer` pointing at a layer of the active map, the other open items within + /// the project's, and the open layout written in the project, so every save carries it + /// (#3446). Writing it isn't an edit: [`Session::state`] doesn't change. pub(crate) fn fix_active_layer(&mut self) { if self.active_layout.is_some_and(|i| i >= self.project.layouts.len()) { self.active_layout = None; } + self.project.open_layout = self.active_layout; if self.active_report.is_some_and(|i| i >= self.project.reports.len()) { self.active_report = None; } diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 71ab3346b2..dff0e652e0 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -475,6 +475,10 @@ pub struct Project { #[serde(default)] #[cfg_attr(feature = "schema", schemars(with = "Vec"))] pub layouts: Vec, + /// The layout shown when the project was saved, an index into `layouts`; none is the map + /// view. Kept as the session's open layout after each command, and opened with the project. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub open_layout: Option, /// Folder connections shown in the Browser. #[serde(default)] pub folders: Vec, @@ -1353,6 +1357,7 @@ impl Project { next_table_id: 1, gp_history: Vec::new(), layouts: Vec::new(), + open_layout: None, folders: Vec::new(), styles: Vec::new(), ramps: Vec::new(), @@ -2927,6 +2932,7 @@ impl Durable for Project { next_table_id: _, gp_history, layouts: _, + open_layout: _, folders: _, styles: _, ramps: _, diff --git a/crates/engine/src/project_capabilities.rs b/crates/engine/src/project_capabilities.rs index 23d1b6ec59..89dd81936e 100644 --- a/crates/engine/src/project_capabilities.rs +++ b/crates/engine/src/project_capabilities.rs @@ -1604,6 +1604,7 @@ fn project_needs_wkt(project: &Project) -> bool { next_table_id: _, gp_history: _, layouts: _, + open_layout: _, folders: _, styles: _, ramps: _, diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index cc08ead40f..f493146625 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -185,6 +185,9 @@ mod layout_table; #[path = "tests/layout_extents.rs"] mod layout_extents; +#[path = "tests/layout_open.rs"] +mod layout_open; + #[path = "tests/sde_connections.rs"] mod sde_connections; diff --git a/crates/engine/src/tests/layout_open.rs b/crates/engine/src/tests/layout_open.rs new file mode 100644 index 0000000000..3b37c0bef5 --- /dev/null +++ b/crates/engine/src/tests/layout_open.rs @@ -0,0 +1,162 @@ +//! A project reopens on the layout that was open when it was saved (#3446). + +use crate::{Project, Session}; +use serde_json::{Value, json}; +use std::path::PathBuf; + +/// A folder of this test's own, removed when it ends. +struct Dir(PathBuf); + +impl Dir { + fn new(name: &str) -> Self { + let dir = std::env::temp_dir().join(format!("rustgis-open-layout-{name}-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + Dir(dir) + } +} + +impl Drop for Dir { + fn drop(&mut self) { + let _ = std::fs::remove_dir_all(&self.0); + } +} + +/// A session with the layouts A and B, B open. +fn two_layouts() -> Session { + let mut s = Session::new(Project::default()); + for name in ["A", "B"] { + s.run("layout.new", &json!({"page": "a4", "template": "map", "name": name})).unwrap(); + } + assert_eq!(s.active_layout, Some(1)); + s +} + +/// The project as a save writes it. +fn saved(s: &mut Session) -> String { + s.project.saved_text(None).unwrap().0 +} + +/// What the saved text says is open. +fn written(text: &str) -> Value { + serde_json::from_str::(text).unwrap().get("open_layout").cloned().unwrap_or(Value::Null) +} + +/// `text` opened in a new session. +fn opened(text: &str) -> Session { + let mut s = Session::new(Project::default()); + s.run("project.openText", &json!({"text": text})).unwrap(); + s +} + +/// Whether opening said a key was left out. +fn said_unread(s: &Session) -> bool { + s.notices_since(0).iter().any(|n| n.text.contains("this version doesn't read")) +} + +#[test] +fn a_saved_project_reopens_on_the_layout_that_was_open() { + let dir = Dir::new("save"); + let path = dir.0.join("atlas.rgis"); + let mut s = two_layouts(); + s.run("project.saveAs", &json!({"path": path})).unwrap(); + let mut o = Session::new(Project::default()); + o.run("project.open", &json!({"path": path})).unwrap(); + assert_eq!(o.active_layout, Some(1)); + assert!(!said_unread(&o)); +} + +#[test] +fn text_a_package_and_a_recovery_copy_reopen_on_the_layout() { + let dir = Dir::new("package"); + let package = dir.0.join("atlas.rgispkg"); + let mut s = two_layouts(); + let text = saved(&mut s); + assert_eq!(written(&text), json!(1)); + assert_eq!(opened(&text).active_layout, Some(1)); + assert_eq!(opened(&s.project.clone().recovery_text().unwrap()).active_layout, Some(1)); + s.run("project.package", &json!({"path": package})).unwrap(); + let mut o = Session::new(Project::default()); + o.run("project.open", &json!({"path": package})).unwrap(); + assert_eq!(o.active_layout, Some(1)); +} + +#[test] +fn a_project_saved_on_the_map_view_reopens_on_it() { + let mut s = two_layouts(); + s.run("layout.close", &Value::Null).unwrap(); + let text = saved(&mut s); + assert_eq!(written(&text), Value::Null); + assert_eq!(opened(&text).active_layout, None); +} + +#[test] +fn a_moved_open_layout_reopens_at_its_new_place() { + let mut s = two_layouts(); + s.run("layout.move", &json!({"name": "B", "to": 0})).unwrap(); + let o = opened(&saved(&mut s)); + assert_eq!(o.active_layout, Some(0)); + assert_eq!(o.project.layouts[0].name, "B"); +} + +#[test] +fn removing_the_open_layout_leaves_none_to_reopen() { + let mut s = two_layouts(); + s.run("layout.remove", &json!({"name": "B"})).unwrap(); + assert_eq!(s.active_layout, None); + assert_eq!(written(&saved(&mut s)), Value::Null); +} + +#[test] +fn undo_writes_the_layout_then_open() { + let mut s = two_layouts(); + s.run("layout.remove", &json!({"name": "A"})).unwrap(); + assert_eq!(written(&saved(&mut s)), json!(0)); + s.run("edit.undo", &Value::Null).unwrap(); + assert_eq!(written(&saved(&mut s)), json!(1)); +} + +#[test] +fn a_file_without_the_key_or_with_one_past_the_layouts_opens_on_the_map() { + let mut s = two_layouts(); + let mut v: Value = serde_json::from_str(&saved(&mut s)).unwrap(); + v["open_layout"] = json!(2); + let o = opened(&v.to_string()); + assert_eq!(o.active_layout, None); + assert_eq!(o.project.open_layout, None); + v.as_object_mut().unwrap().remove("open_layout"); + let o = opened(&v.to_string()); + assert_eq!(o.active_layout, None); + assert!(!said_unread(&o)); +} + +#[test] +fn a_new_or_sample_project_opens_on_the_map() { + for command in ["project.new", "project.sample"] { + let mut s = two_layouts(); + s.run(command, &Value::Null).unwrap(); + assert_eq!((s.active_layout, s.project.open_layout), (None, None), "{command}"); + } +} + +#[test] +fn a_failed_command_keeps_the_layout_open_before_it() { + let mut s = two_layouts(); + let steps = json!([ + {"title": "Open A", "command": "layout.activate", "params": {"name": "A"}}, + {"title": "Fail", "command": "layout.activate", "params": {"name": "none"}}, + ]); + s.run("task.new", &json!({"name": "Fails", "steps": steps})).unwrap(); + assert!(s.run("task.run", &json!({"task": "Fails"})).is_err()); + assert_eq!(s.project.open_layout, s.active_layout); +} + +#[test] +fn switching_layouts_leaves_the_project_saved() { + let mut s = two_layouts(); + s.mark_saved(); + let state = s.state(); + s.run("layout.activate", &json!({"name": "A"})).unwrap(); + assert_eq!((s.state(), s.project.open_layout), (state, Some(0))); + s.run("layout.close", &Value::Null).unwrap(); + assert_eq!((s.state(), s.project.open_layout), (state, None)); +} diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index a9e433dc5d..f04f185310 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -11,6 +11,10 @@ streamed layers reopen their sources, and file-backed rasters reopen their files sources accessible when moving a project. See [Project items](data.md#project-items) for templates, packages and files for individual items. +A project saved while a layout is open opens on that layout, also from a package, from a +recovery copy and in the web app; saved on a map, it opens on the map view. Opening another +layout isn't an unsaved change: save the project to keep which one is open. + A project file holds the features of every layer loaded whole (GeoJSON, KML/KMZ, GPX, and Shapefiles of up to 100,000 features), so a project of many such layers grows large. How large a project can be saved and opened follows the computer's memory: on the desktop, as much as a diff --git a/schema/project.schema.json b/schema/project.schema.json index 4f83cbbba0..636aab0916 100644 --- a/schema/project.schema.json +++ b/schema/project.schema.json @@ -1204,6 +1204,16 @@ }, "type": "array" }, + "open_layout": { + "description": "The layout shown when the project was saved, an index into `layouts`; none is the map\nview. Kept as the session's open layout after each command, and opened with the project.", + "format": "uint", + "maximum": 18446744073709551615, + "minimum": 0, + "type": [ + "integer", + "null" + ] + }, "origin_id": { "description": "Persistent home-project identity for offline returns; legacy projects acquire it when packaged.", "type": "string" From b37c251c8f9d823af7a4c2644c6763527c208dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Mon, 30 Nov 2026 08:36:05 -0500 Subject: [PATCH 2/4] fix(project): open the saved layout in a session made from a project, with a fixture --- crates/engine/src/cmd/project.rs | 2 +- crates/engine/src/lib.rs | 3 ++- crates/engine/src/project.rs | 6 ++++++ crates/engine/src/tests/layout_open.rs | 18 +++++++++++++++++- schema/fixtures/open_layout.rgis | 1 + 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 schema/fixtures/open_layout.rgis diff --git a/crates/engine/src/cmd/project.rs b/crates/engine/src/cmd/project.rs index 79ba3c719f..6c9b5ab492 100644 --- a/crates/engine/src/cmd/project.rs +++ b/crates/engine/src/cmd/project.rs @@ -417,7 +417,7 @@ fn reset(s: &mut Session, p: Project) { s.table_layer = None; s.table_standalone = None; // The layout open when it was saved; one the file doesn't have is the map view (#3446). - s.active_layout = s.project.open_layout.filter(|i| *i < s.project.layouts.len()); + s.active_layout = s.project.saved_open_layout(); s.tool = Tool::Explore; s.clear_history(); s.file_identity = s.state(); diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 08628caca5..4b63b108d4 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -1499,6 +1499,7 @@ impl Session { web_time::SystemTime::now().duration_since(web_time::UNIX_EPOCH).map(|d| d.as_millis() as u64).unwrap_or(0) }); let label_notices = project.take_read_notices(&crate::project::ALL_PARTS); + let open_layout = project.saved_open_layout(); let mut session = Session { project, path: None, @@ -1567,7 +1568,7 @@ impl Session { clipboard: None, layer_clipboard: None, keep_tool: false, - active_layout: None, + active_layout: open_layout, policy: Default::default(), document_assets: Default::default(), browse_origins: Default::default(), diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index dff0e652e0..559e5e1257 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1866,6 +1866,12 @@ impl Project { notices } + /// The layout the project was saved with open, as a session opens it; an index the project + /// has no layout for is the map view. + pub(crate) fn saved_open_layout(&self) -> Option { + self.open_layout.filter(|i| *i < self.layouts.len()) + } + pub fn map(&self) -> &Map { // `normalize` guarantees a map; fall back to the first for safety. self.maps.get(self.active_map).or_else(|| self.maps.first()).unwrap_or_else(|| empty_map()) diff --git a/crates/engine/src/tests/layout_open.rs b/crates/engine/src/tests/layout_open.rs index 3b37c0bef5..c928c99d6e 100644 --- a/crates/engine/src/tests/layout_open.rs +++ b/crates/engine/src/tests/layout_open.rs @@ -147,7 +147,7 @@ fn a_failed_command_keeps_the_layout_open_before_it() { ]); s.run("task.new", &json!({"name": "Fails", "steps": steps})).unwrap(); assert!(s.run("task.run", &json!({"task": "Fails"})).is_err()); - assert_eq!(s.project.open_layout, s.active_layout); + assert_eq!((s.active_layout, s.project.open_layout), (Some(1), Some(1))); } #[test] @@ -160,3 +160,19 @@ fn switching_layouts_leaves_the_project_saved() { s.run("layout.close", &Value::Null).unwrap(); assert_eq!((s.state(), s.project.open_layout), (state, None)); } + +#[test] +fn a_session_made_from_a_project_keeps_its_open_layout() { + let s = two_layouts(); + let mut copy = Session::new(s.project.clone()); + assert_eq!(copy.active_layout, Some(1)); + copy.run("project.rename", &json!({"name": "Copy"})).unwrap(); + assert_eq!(copy.project.open_layout, Some(1)); +} + +#[test] +fn the_open_layout_fixture_opens_on_its_second_layout() { + let o = opened(include_str!("../../../../schema/fixtures/open_layout.rgis")); + assert_eq!(o.active_layout, Some(1)); + assert!(!said_unread(&o)); +} diff --git a/schema/fixtures/open_layout.rgis b/schema/fixtures/open_layout.rgis new file mode 100644 index 0000000000..f0a334cccb --- /dev/null +++ b/schema/fixtures/open_layout.rgis @@ -0,0 +1 @@ +{"format":2,"name":"Open layout","maps":[{"name":"Map","layers":[],"basemap":"Paper","camera":{"center":{"x":0.0,"y":2000000.0},"res":30000.0,"bearing":0.0,"pitch":0.0},"bookmarks":[],"graticule":true,"projection":"WebMercator","popup_mode":"Topmost","label_display":{"paused":false,"locked":false,"show_unplaced":false},"editing":{"relationships":[],"snapping":{"enabled":false,"tolerance_px":10.0,"vertex":true,"edge":true,"end":true},"topology":[],"settings":{"enabled":true,"show_vertices":true,"elevation":"None","ground_to_grid":null}},"swipe":null,"view":{"effects":{"stars":true,"sun_time":null,"weather":"None","vignette":false,"edges":false,"tilt_shift":false,"grain":false,"brightness":0.0,"contrast":0.0,"saturation":0.0,"sepia":0.0},"wireframe":false,"clip_distance":null,"terrain":null},"animation":[],"next_layer_id":1}],"active_map":0,"tables":[],"next_table_id":1,"gp_history":[],"layouts":[{"name":"A","width":120,"height":90,"elements":[]},{"name":"B","width":120,"height":90,"elements":[]}],"folders":[],"styles":[],"ramps":[],"tasks":[],"gp_env":{"extent":null,"cell_size":null},"models":[],"workspaces":[],"link_views":false,"jobs":[],"offline_areas":[],"reports":[],"presentations":[],"notebooks":[],"dl_models":[],"shared":[],"data_stores":[],"open_layout":1} From 89f51bcd6e902abad4d9373bdcb314d902955e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Mon, 30 Nov 2026 08:47:17 -0500 Subject: [PATCH 3/4] test(project): another layout moved past the open one; reword a comment --- crates/engine/src/lib.rs | 6 +++--- crates/engine/src/tests/layout_open.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 4b63b108d4..06486db667 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -4375,9 +4375,9 @@ impl Session { self.layer_selection_of = active; } - /// Keeps `active_layer` pointing at a layer of the active map, the other open items within - /// the project's, and the open layout written in the project, so every save carries it - /// (#3446). Writing it isn't an edit: [`Session::state`] doesn't change. + /// Keeps `active_layer` pointing at a layer of the active map and the other open items at + /// items the project has, and writes the open layout into the project, so every save + /// carries it (#3446). Writing it isn't an edit: [`Session::state`] doesn't change. pub(crate) fn fix_active_layer(&mut self) { if self.active_layout.is_some_and(|i| i >= self.project.layouts.len()) { self.active_layout = None; diff --git a/crates/engine/src/tests/layout_open.rs b/crates/engine/src/tests/layout_open.rs index c928c99d6e..5ff9d8b5ca 100644 --- a/crates/engine/src/tests/layout_open.rs +++ b/crates/engine/src/tests/layout_open.rs @@ -98,6 +98,15 @@ fn a_moved_open_layout_reopens_at_its_new_place() { assert_eq!(o.project.layouts[0].name, "B"); } +#[test] +fn another_layout_moved_past_the_open_one_shifts_what_is_written() { + let mut s = two_layouts(); + s.run("layout.move", &json!({"name": "A", "to": 1})).unwrap(); + let text = saved(&mut s); + assert_eq!(written(&text), json!(0)); + assert_eq!(opened(&text).project.layouts[0].name, "B"); +} + #[test] fn removing_the_open_layout_leaves_none_to_reopen() { let mut s = two_layouts(); From df94312c84e9e75c24e5d6e9c4b62e1fad79d9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Mon, 30 Nov 2026 09:11:04 -0500 Subject: [PATCH 4/4] fix(project): require project-open-layout, and write the open layout after each step --- crates/engine/src/lib.rs | 15 +++++++--- crates/engine/src/project.rs | 4 +++ crates/engine/src/project_capabilities.rs | 3 ++ crates/engine/src/tests/layout_files.rs | 2 ++ crates/engine/src/tests/layout_open.rs | 32 ++++++++++++++++++++++ crates/engine/src/tests/layout_pictures.rs | 5 +++- crates/engine/src/tests/layout_table.rs | 4 ++- docs/maintaining.md | 4 +++ docs/user-guide/workspace.md | 3 +- schema/fixtures/open_layout.rgis | 2 +- schema/project.schema.json | 6 ++-- 11 files changed, 70 insertions(+), 10 deletions(-) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 06486db667..622c6f79e4 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -2567,6 +2567,7 @@ impl Session { let kept = !spec.atomic || matches!(res, Ok(Ok(_))); self.shared_steps.requested |= unchanged; self.shared_steps.edited |= moved || (spec.mutates && kept && !unchanged); + self.keep_open_layout(); res.unwrap_or_else(|panic| std::panic::resume_unwind(panic)) } @@ -4375,14 +4376,20 @@ impl Session { self.layer_selection_of = active; } - /// Keeps `active_layer` pointing at a layer of the active map and the other open items at - /// items the project has, and writes the open layout into the project, so every save - /// carries it (#3446). Writing it isn't an edit: [`Session::state`] doesn't change. - pub(crate) fn fix_active_layer(&mut self) { + /// Writes the open layout into the project, so a save carries it (#3446), after each command + /// and each step of one: a step may save. An index the project has no layout for is let go. + /// Writing it isn't an edit: [`Session::state`] doesn't change. + fn keep_open_layout(&mut self) { if self.active_layout.is_some_and(|i| i >= self.project.layouts.len()) { self.active_layout = None; } self.project.open_layout = self.active_layout; + } + + /// Keeps `active_layer` pointing at a layer of the active map and the other open items at + /// items the project has. + pub(crate) fn fix_active_layer(&mut self) { + self.keep_open_layout(); if self.active_report.is_some_and(|i| i >= self.project.reports.len()) { self.active_report = None; } diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 559e5e1257..92c63350aa 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -152,6 +152,7 @@ pub const CAPABILITIES: &[&str] = &[ "shaded-relief-flats", "layout-publication-crs", "shaded-relief-generalize", + PROJECT_OPEN_LAYOUT, ]; /// An offline area keeping the versions that lost a sync or a Bring Back /// (`OfflineArea::conflicts`, #2468): an older reader would save it again without them. @@ -163,6 +164,9 @@ pub(crate) const NATIVE_COORDINATES: &str = "native-coordinates"; /// (`Project::coordinate_system`, `Project::crs_from_first_layer`, #2032 C3a): an older reader /// would save it again without them. pub(crate) const PROJECT_CRS: &str = "project-crs"; +/// A project saved with a layout open (`Project::open_layout`, #3446): an older reader would +/// save it again without it. +pub(crate) const PROJECT_OPEN_LAYOUT: &str = "project-open-layout"; /// Independent marker sizes alongside classified point colours (`Layer::size_by`). pub(crate) const SIZE_BY_CAPABILITY: &str = "classified-point-size"; /// The most entries a document's `requires` may list: past it the document is refused without diff --git a/crates/engine/src/project_capabilities.rs b/crates/engine/src/project_capabilities.rs index 89dd81936e..3138ce1ad3 100644 --- a/crates/engine/src/project_capabilities.rs +++ b/crates/engine/src/project_capabilities.rs @@ -57,6 +57,9 @@ impl Project { if self.coordinate_system.is_some() || self.crs_from_first_layer { required.push(super::PROJECT_CRS); } + if self.saved_open_layout().is_some() { + required.push(super::PROJECT_OPEN_LAYOUT); + } // Saved symbology keeps its images too. if !required.contains(&"picture-markers") && self.styles.iter().any(|s| s.renderer.has_picture_markers()) { required.push("picture-markers"); diff --git a/crates/engine/src/tests/layout_files.rs b/crates/engine/src/tests/layout_files.rs index d809e2be41..3f367aeeb7 100644 --- a/crates/engine/src/tests/layout_files.rs +++ b/crates/engine/src/tests/layout_files.rs @@ -173,6 +173,8 @@ fn a_layout_file_requires_nothing_for_other_layouts_or_saved_commands() { document["tasks"] = json!([{"name": "Task", "steps": [{"title": "Wrap", "command": "layout.addElement", "params": {"kind": "text", "text": "A", "wrap": true}}]}]); let mut s = Session::new(Project::from_json(&document.to_string()).unwrap()); s.run("layout.new", &json!({"page": "a4", "template": "map"})).unwrap(); + // On the map view: an open layout is the project's own requirement (#3446). + s.run("layout.close", &Value::Null).unwrap(); let project = serde_json::to_value(&s.project).unwrap(); assert_eq!(project["requires"], json!(["layout-element-wrap", "layout-element-background"])); let (_, background) = saved_file(&mut s, 0, "other-background"); diff --git a/crates/engine/src/tests/layout_open.rs b/crates/engine/src/tests/layout_open.rs index 5ff9d8b5ca..e40994f87b 100644 --- a/crates/engine/src/tests/layout_open.rs +++ b/crates/engine/src/tests/layout_open.rs @@ -185,3 +185,35 @@ fn the_open_layout_fixture_opens_on_its_second_layout() { assert_eq!(o.active_layout, Some(1)); assert!(!said_unread(&o)); } + +/// Whether the saved text requires the capability an older reader refuses it by. +fn required(text: &str) -> bool { + let v: Value = serde_json::from_str(text).unwrap(); + v["requires"].as_array().is_some_and(|r| r.contains(&json!("project-open-layout"))) +} + +#[test] +fn only_a_project_saved_with_a_layout_open_requires_the_capability() { + let mut s = two_layouts(); + assert!(required(&saved(&mut s))); + assert!(required(&s.project.clone().recovery_text().unwrap())); + s.run("layout.close", &Value::Null).unwrap(); + assert!(!required(&saved(&mut s))); + assert!(required(include_str!("../../../../schema/fixtures/open_layout.rgis"))); +} + +#[test] +fn a_task_that_opens_another_layout_and_saves_writes_it() { + let dir = Dir::new("task"); + let path = dir.0.join("atlas.rgis"); + let mut s = two_layouts(); + for (name, then, open) in [ + ("To A", json!({"title": "Open A", "command": "layout.activate", "params": {"name": "A"}}), json!(0)), + ("To the map", json!({"title": "Map", "command": "layout.close", "params": {}}), Value::Null), + ] { + let steps = json!([then, {"title": "Save", "command": "project.saveAs", "params": {"path": path}}]); + s.run("task.new", &json!({"name": name, "steps": steps})).unwrap(); + s.run("task.run", &json!({"task": name})).unwrap(); + assert_eq!(written(&std::fs::read_to_string(&path).unwrap()), open, "{name}"); + } +} diff --git a/crates/engine/src/tests/layout_pictures.rs b/crates/engine/src/tests/layout_pictures.rs index 95dc3e9274..027c903b97 100644 --- a/crates/engine/src/tests/layout_pictures.rs +++ b/crates/engine/src/tests/layout_pictures.rs @@ -148,7 +148,10 @@ fn pictures_save_and_say_as_before() { let li = s.project.layouts.len() - 1; let name = s.project.layouts[li].name.clone(); assert_eq!((s.project.layouts.len(), name.as_str(), s.project.layouts[li].elements.len()), (1, "Pictures", 4)); - let requires = serde_json::to_value(&s.project).unwrap()["requires"].to_string(); + // As saved on the map view: an open layout adds a requirement of the project's own (#3446). + let mut on_map = s.project.clone(); + on_map.open_layout = None; + let requires = serde_json::to_value(&on_map).unwrap()["requires"].to_string(); let saves = [ ("layouts".to_string(), super::fnv_bytes(serde_json::to_string(&s.project.layouts).unwrap().as_bytes())), ( diff --git a/crates/engine/src/tests/layout_table.rs b/crates/engine/src/tests/layout_table.rs index 2329247bb5..27ac8c0977 100644 --- a/crates/engine/src/tests/layout_table.rs +++ b/crates/engine/src/tests/layout_table.rs @@ -39,11 +39,13 @@ fn refused(s: &mut Session, command: &str, params: Value, said: &str) { #[test] fn a_table_without_the_new_options_saves_none_of_them() { - let (s, id) = tabled(); + let (mut s, id) = tabled(); let stored = table(&s, id); for key in ["fields", "text_size", "header"] { assert!(stored.get(key).is_none(), "{key}: {stored}"); } + // On the map view: an open layout is the project's own requirement (#3446). + s.run("layout.close", &Value::Null).unwrap(); assert!(serde_json::to_value(&s.project).unwrap().get("requires").is_none()); } diff --git a/docs/maintaining.md b/docs/maintaining.md index 948deca8a9..66091a198b 100644 --- a/docs/maintaining.md +++ b/docs/maintaining.md @@ -299,6 +299,10 @@ object without a width or with one above 0 require it too (only a chart takes th a width of 0 need nothing. A saved `layout.import` whose `text` has such a chart requires it as well. +Projects saved with a layout open (`open_layout`) require `project-open-layout`, so an older +reader refuses them instead of saving them again without it (#3446). A project saved on the map +view has no such key and requires nothing for it. + Projects with a layout table whose columns are chosen (`fields` on a table element), whose text isn't 8 points (`text_size`) or whose header is off (`header`) require `layout-table-look`, so an older reader refuses them instead of drawing the whole table and saving it again without (#3409). diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index f04f185310..b394f960fd 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -13,7 +13,8 @@ templates, packages and files for individual items. A project saved while a layout is open opens on that layout, also from a package, from a recovery copy and in the web app; saved on a map, it opens on the map view. Opening another -layout isn't an unsaved change: save the project to keep which one is open. +layout isn't an unsaved change: save the project to keep which one is open. An older RustGIS +refuses a project saved with a layout open; save it on the map view for it to open there. A project file holds the features of every layer loaded whole (GeoJSON, KML/KMZ, GPX, and Shapefiles of up to 100,000 features), so a project of many such layers grows large. How large a diff --git a/schema/fixtures/open_layout.rgis b/schema/fixtures/open_layout.rgis index f0a334cccb..66f97fc121 100644 --- a/schema/fixtures/open_layout.rgis +++ b/schema/fixtures/open_layout.rgis @@ -1 +1 @@ -{"format":2,"name":"Open layout","maps":[{"name":"Map","layers":[],"basemap":"Paper","camera":{"center":{"x":0.0,"y":2000000.0},"res":30000.0,"bearing":0.0,"pitch":0.0},"bookmarks":[],"graticule":true,"projection":"WebMercator","popup_mode":"Topmost","label_display":{"paused":false,"locked":false,"show_unplaced":false},"editing":{"relationships":[],"snapping":{"enabled":false,"tolerance_px":10.0,"vertex":true,"edge":true,"end":true},"topology":[],"settings":{"enabled":true,"show_vertices":true,"elevation":"None","ground_to_grid":null}},"swipe":null,"view":{"effects":{"stars":true,"sun_time":null,"weather":"None","vignette":false,"edges":false,"tilt_shift":false,"grain":false,"brightness":0.0,"contrast":0.0,"saturation":0.0,"sepia":0.0},"wireframe":false,"clip_distance":null,"terrain":null},"animation":[],"next_layer_id":1}],"active_map":0,"tables":[],"next_table_id":1,"gp_history":[],"layouts":[{"name":"A","width":120,"height":90,"elements":[]},{"name":"B","width":120,"height":90,"elements":[]}],"folders":[],"styles":[],"ramps":[],"tasks":[],"gp_env":{"extent":null,"cell_size":null},"models":[],"workspaces":[],"link_views":false,"jobs":[],"offline_areas":[],"reports":[],"presentations":[],"notebooks":[],"dl_models":[],"shared":[],"data_stores":[],"open_layout":1} +{"format":2,"requires":["project-open-layout"],"name":"Open layout","maps":[{"name":"Map","layers":[],"basemap":"Paper","camera":{"center":{"x":0.0,"y":2000000.0},"res":30000.0,"bearing":0.0,"pitch":0.0},"bookmarks":[],"graticule":true,"projection":"WebMercator","popup_mode":"Topmost","label_display":{"paused":false,"locked":false,"show_unplaced":false},"editing":{"relationships":[],"snapping":{"enabled":false,"tolerance_px":10.0,"vertex":true,"edge":true,"end":true},"topology":[],"settings":{"enabled":true,"show_vertices":true,"elevation":"None","ground_to_grid":null}},"swipe":null,"view":{"effects":{"stars":true,"sun_time":null,"weather":"None","vignette":false,"edges":false,"tilt_shift":false,"grain":false,"brightness":0.0,"contrast":0.0,"saturation":0.0,"sepia":0.0},"wireframe":false,"clip_distance":null,"terrain":null},"animation":[],"next_layer_id":1}],"active_map":0,"tables":[],"next_table_id":1,"gp_history":[],"layouts":[{"name":"A","width":120,"height":90,"elements":[]},{"name":"B","width":120,"height":90,"elements":[]}],"folders":[],"styles":[],"ramps":[],"tasks":[],"gp_env":{"extent":null,"cell_size":null},"models":[],"workspaces":[],"link_views":false,"jobs":[],"offline_areas":[],"reports":[],"presentations":[],"notebooks":[],"dl_models":[],"shared":[],"data_stores":[],"open_layout":1} diff --git a/schema/project.schema.json b/schema/project.schema.json index 636aab0916..93becb7890 100644 --- a/schema/project.schema.json +++ b/schema/project.schema.json @@ -1320,7 +1320,8 @@ "shaded-relief-terrain-type", "shaded-relief-flats", "layout-publication-crs", - "shaded-relief-generalize" + "shaded-relief-generalize", + "project-open-layout" ], "type": "string" }, @@ -1459,7 +1460,8 @@ "shaded-relief-terrain-type", "shaded-relief-flats", "layout-publication-crs", - "shaded-relief-generalize" + "shaded-relief-generalize", + "project-open-layout" ], "x-rustgis-reads-format": 2, "x-rustgis-writes-format": 2