mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Restore captured settings when resetting a workspace (#17648)
This commit is contained in:
1 parent
a3288779f1
commit
5fbc4dbc8b
2 files changed
+90
No files matched your search
@@ -0,0 +1,84 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft::settings::testing::MemoryFiles;
|
||||
use craft::settings::{Location, OpenOptions, SettingsStore};
|
||||
use photocraft_engine::Session;
|
||||
use photocraft_engine::prefs::SavedPrefs;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::{PhotocraftApp, Services, menus};
|
||||
|
||||
fn invoke(app: &mut PhotocraftApp, id: &str, params: Value) {
|
||||
let ctx = app.ctx().clone();
|
||||
menus::invoke(app, &ctx, id, params).unwrap();
|
||||
}
|
||||
|
||||
fn customizations(app: &mut PhotocraftApp) -> [Value; 3] {
|
||||
["toolbar", "shortcuts", "menus"].map(|path| app.run("prefs.get", json!({"path": path})).unwrap())
|
||||
}
|
||||
|
||||
fn set_customizations(app: &mut PhotocraftApp, extra_tool: &str, brush_key: &str, fill_color: &str) {
|
||||
app.run("edit.toolbar", json!({"reset": true, "extras": [[extra_tool]]})).unwrap();
|
||||
app.run("prefs.set", json!({"values": {"shortcuts.tools.select.brush": brush_key, "menus.colors.edit.fill": fill_color}})).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_restores_and_saves_all_captured_customizations() {
|
||||
let files = Arc::new(MemoryFiles::new());
|
||||
let open_app = || {
|
||||
let options = OpenOptions::new(Location::Dir("/memory/photocraft".into())).files(files.clone());
|
||||
let services = Services { settings: Some(SettingsStore::<SavedPrefs>::open_with(options)), ..Default::default() };
|
||||
PhotocraftApp::new(Session::new(), services)
|
||||
};
|
||||
let mut app = open_app();
|
||||
set_customizations(&mut app, "Frame", "F8", "red");
|
||||
let captured = customizations(&mut app);
|
||||
invoke(&mut app, "workspace.new", json!({"name": "Retouch", "toolbar": true, "keyboardShortcuts": true, "menus": true}));
|
||||
|
||||
set_customizations(&mut app, "Crop", "F9", "blue");
|
||||
let changed = customizations(&mut app);
|
||||
for (before, after) in captured.iter().zip(&changed) {
|
||||
assert_ne!(before, after);
|
||||
}
|
||||
invoke(&mut app, "workspace.reset", json!({}));
|
||||
assert_eq!(customizations(&mut app), captured);
|
||||
|
||||
crate::prefs_ui::save_preferences(&mut app).unwrap();
|
||||
drop(app);
|
||||
let mut restarted = open_app();
|
||||
assert_eq!(customizations(&mut restarted), captured);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_applies_each_capture_independently() {
|
||||
for toolbar in [true, false] {
|
||||
let mut app = PhotocraftApp::new(Session::new(), Services::default());
|
||||
set_customizations(&mut app, "Frame", "F8", "red");
|
||||
let captured = customizations(&mut app);
|
||||
invoke(&mut app, "workspace.new", json!({"name": "Retouch", "toolbar": toolbar, "keyboardShortcuts": !toolbar, "menus": !toolbar}));
|
||||
|
||||
set_customizations(&mut app, "Crop", "F9", "blue");
|
||||
let changed = customizations(&mut app);
|
||||
invoke(&mut app, "workspace.reset", json!({}));
|
||||
let restored = customizations(&mut app);
|
||||
for (index, captured_by_workspace) in [toolbar, !toolbar, !toolbar].into_iter().enumerate() {
|
||||
let expected = if captured_by_workspace { &captured[index] } else { &changed[index] };
|
||||
assert_eq!(&restored[index], expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_keeps_live_customizations_without_captures() {
|
||||
let mut app = PhotocraftApp::new(Session::new(), Services::default());
|
||||
set_customizations(&mut app, "Frame", "F8", "red");
|
||||
let live = customizations(&mut app);
|
||||
invoke(&mut app, "workspace.reset", json!({}));
|
||||
assert_eq!(customizations(&mut app), live, "built-in workspace");
|
||||
|
||||
invoke(&mut app, "workspace.new", json!({"name": "Panels Only"}));
|
||||
set_customizations(&mut app, "Crop", "F9", "blue");
|
||||
let live = customizations(&mut app);
|
||||
invoke(&mut app, "workspace.reset", json!({}));
|
||||
assert_eq!(customizations(&mut app), live, "saved workspace without captures");
|
||||
}
|
||||
@@ -270,6 +270,8 @@ pub fn run(app: &mut PhotocraftApp, _ctx: &egui::Context, command: WorkspaceComm
|
||||
Some(_) | None => {}
|
||||
}
|
||||
if command == WorkspaceCommands::Reset {
|
||||
let current = app.workspaces.set.current.clone();
|
||||
restore_extras(app, ¤t);
|
||||
crate::dock::persist(app);
|
||||
}
|
||||
store(app);
|
||||
@@ -560,6 +562,10 @@ fn extras_options() -> [(&'static str, &'static str); 13] {
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "workspace_reset_captured_toolbar_tests.rs"]
|
||||
mod workspace_reset_captured_toolbar_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in new issue
Block a user