Repository navigation
feat(project): reopen a project on the layout that was open (#3446) #3451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jgregoriorincon
merged 4 commits into
opengeos:main
from
jgregoriorincon:feat/3446-open-layout
Nov 30, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
55d784a
feat(project): reopen a project on the layout that was open (#3446)
jgregoriorincon b37c251
fix(project): open the saved layout in a session made from a project,…
jgregoriorincon 89f51bc
test(project): another layout moved past the open one; reword a comment
jgregoriorincon df94312
fix(project): require project-open-layout, and write the open layout …
jgregoriorincon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,219 @@ | ||
| //! 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); | ||
|
jgregoriorincon marked this conversation as resolved.
Resolved
|
||
|
|
||
| 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::<Value>(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 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(); | ||
| 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.active_layout, s.project.open_layout), (Some(1), Some(1))); | ||
| } | ||
|
|
||
| #[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)); | ||
| } | ||
|
|
||
| #[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)); | ||
| } | ||
|
|
||
| /// 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}"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.