mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Workspaces: preserve the embedding host menu and rail flags (#2620)
Co-authored-by: Brandon Thomas <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
3 files changed
+86
-1
No files matched your search
@@ -656,7 +656,10 @@ pub fn restore(app: &mut PhotocraftApp) {
|
||||
/// (a workspace or `panelLayout`). Missing or invalid dock parts are left alone; old
|
||||
/// layouts without Timeline visibility restore it closed.
|
||||
pub fn apply(app: &mut PhotocraftApp, v: &Value) {
|
||||
if let Some(p) = v.get("panels").and_then(|p| serde_json::from_value(p.clone()).ok()) {
|
||||
if let Some(mut p) = v.get("panels").and_then(|p| serde_json::from_value::<Panels>(p.clone()).ok()) {
|
||||
// The embedding host owns these flags, including for layouts that serialize them.
|
||||
p.menu_bar = app.ui.panels.menu_bar;
|
||||
p.rail = app.ui.panels.rail;
|
||||
app.ui.panels = p;
|
||||
}
|
||||
if let Some(t) = v.get("dockTabs").and_then(|t| serde_json::from_value(t.clone()).ok()) {
|
||||
|
||||
@@ -490,6 +490,83 @@ mod tests {
|
||||
(PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()), egui::Context::default())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_workspaces_preserve_host_chrome_on_select_and_reset() {
|
||||
for (menu_bar, rail) in [(false, false), (false, true), (true, false), (true, true)] {
|
||||
for legacy_flags in [false, true] {
|
||||
let (mut app, ctx) = app();
|
||||
app.ui.panels.history = true;
|
||||
app.ui.panels.navigator = true;
|
||||
app.ui.timeline.open = true;
|
||||
crate::menus::invoke(&mut app, &ctx, "window.workspace.newWorkspace", json!({"name": "Host layout"})).unwrap();
|
||||
let saved = app.session.prefs().workspaces["Host layout"].clone();
|
||||
assert!(saved["panels"].get("menu_bar").is_none() && saved["panels"].get("rail").is_none());
|
||||
if legacy_flags {
|
||||
app.session.prefs.edit(|p| {
|
||||
let panels = &mut p.workspaces.get_mut("Host layout").unwrap()["panels"];
|
||||
panels["menu_bar"] = json!(!menu_bar);
|
||||
panels["rail"] = json!(!rail);
|
||||
});
|
||||
}
|
||||
app.ui.panels.menu_bar = menu_bar;
|
||||
app.ui.panels.rail = rail;
|
||||
crate::menus::invoke(&mut app, &ctx, "window.workspace.painting", json!({})).unwrap();
|
||||
crate::menus::invoke(&mut app, &ctx, "window.workspace.select", json!({"name": "Host layout"})).unwrap();
|
||||
assert_eq!((app.ui.panels.menu_bar, app.ui.panels.rail), (menu_bar, rail), "select: legacy_flags={legacy_flags}");
|
||||
let restored = json!({"dock": app.ui.dock, "dockTabs": app.ui.dock_tabs, "timelineOpen": app.ui.timeline.open});
|
||||
for key in ["dock", "dockTabs", "timelineOpen"] {
|
||||
assert_eq!(restored[key], saved[key], "select restores {key}");
|
||||
}
|
||||
assert!(app.ui.panels.history && app.ui.panels.navigator);
|
||||
app.ui.panels.menu_bar = !menu_bar;
|
||||
app.ui.panels.rail = !rail;
|
||||
app.ui.panels.history = false;
|
||||
app.ui.panels.navigator = false;
|
||||
app.ui.timeline.open = false;
|
||||
crate::menus::invoke(&mut app, &ctx, "window.workspace.resetWorkspace", json!({})).unwrap();
|
||||
assert_eq!((app.ui.panels.menu_bar, app.ui.panels.rail), (!menu_bar, !rail), "reset: legacy_flags={legacy_flags}");
|
||||
let restored = json!({"dock": app.ui.dock, "dockTabs": app.ui.dock_tabs, "timelineOpen": app.ui.timeline.open});
|
||||
for key in ["dock", "dockTabs", "timelineOpen"] {
|
||||
assert_eq!(restored[key], saved[key], "reset restores {key}");
|
||||
}
|
||||
assert!(app.ui.panels.history && app.ui.panels.navigator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_workspace_keeps_host_menu_and_rail_hidden_in_the_rendered_ui() {
|
||||
let mut failures = Vec::new();
|
||||
for theme in crate::theme::ThemeKind::ALL {
|
||||
for width in [800.0, 1200.0] {
|
||||
let builder = egui_kittest::Harness::builder().with_size(egui::vec2(width, 800.0)).with_max_steps(64);
|
||||
let mut h = builder.build_eframe(move |cc| {
|
||||
PhotocraftApp::setup_context(&cc.egui_ctx, theme);
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("prefs.set", json!({"path": "interface.theme", "value": theme.id()})).unwrap();
|
||||
app.ui.theme = theme;
|
||||
app.ui.panels.menu_bar = false;
|
||||
app.ui.panels.rail = false;
|
||||
app
|
||||
});
|
||||
let ctx = h.ctx.clone();
|
||||
crate::menus::invoke(h.state_mut(), &ctx, "window.workspace.newWorkspace", json!({"name": "Embedded"})).unwrap();
|
||||
crate::menus::invoke(h.state_mut(), &ctx, "window.workspace.select", json!({"name": "Embedded"})).unwrap();
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().ui.theme, theme, "the fixture renders the requested theme");
|
||||
for name in ["title_bar", "rail"] {
|
||||
if egui::containers::panel::PanelState::load(&h.ctx, egui::Id::new(name)).is_some() {
|
||||
failures.push(format!("{theme:?}, width={width}: {name} is drawn"));
|
||||
}
|
||||
}
|
||||
if h.state().ui.panels.menu_bar || h.state().ui.panels.rail {
|
||||
failures.push(format!("{theme:?}, width={width}: host flags were overwritten"));
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(failures.is_empty(), "saved workspaces expose host chrome: {failures:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_select_delete_workspaces() {
|
||||
let (mut app, ctx) = app();
|
||||
|
||||
@@ -82,6 +82,11 @@ The app's top bar (`panels::title_bar`) starts with the brand mark (the app icon
|
||||
|
||||
## Menus
|
||||
|
||||
An embedding application's `panels.menu_bar` and `panels.rail` flags belong to its current
|
||||
session. Restoring a saved workspace or remembered panel layout preserves both flags, including
|
||||
when the serialized layout contains their values. Panel visibility, dock layout, tabs and Timeline
|
||||
visibility follow the saved layout.
|
||||
|
||||
The Pro status bar's Document Dimensions readout follows Preferences › Units & Rulers › Rulers,
|
||||
including changes made from a ruler's context menu. It uses the document resolution for physical
|
||||
units, each side's own extent for percentages and the selected point-size convention for points
|
||||
|
||||
Reference in new issue
Block a user