Window: saved workspaces are listed in Window ▸ Workspace (#191)

Save as New Workspace stored the layout and `window.workspace` could
switch to it, but the Workspace submenu was a fixed list of the
built-in workspaces, so a saved one never appeared and could not be
chosen from the menu.

The submenu now has a `savedWorkspaces` dynamic node after the
built-ins (DynCtx carries the saved names), in the in-window and native
menus, with a check mark on the current one as the built-ins have.

The in-window submenu was also too short to show it. egui lays out a
new submenu in a default 400 pt area, and the scroll area inside took
that height and kept it, so Window ▸ Workspace (514 pt) opened with its
last rows (Undocked Panels and below, where saved workspaces go)
scrolled out of view. Submenus now open at their full height and scroll
only when taller than the window.

Tests: saved_workspace_is_listed_in_the_workspace_menu (picks it from
the menu bar), saved_workspaces_are_in_the_native_workspace_menu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
BFlat
2026-10-07 20:17:28 +07:00
co-authored by Claude Opus 5.5
parent f5ebe5f6c5
commit 1db3698719
5 changed files with 96 additions and 16 deletions
+19 -4
View File
@@ -135,8 +135,10 @@ pub fn build(app: &EffectcraftApp) -> NativeMenu {
match n {
MenuNode::Separator => out.push(NativeNode::Separator),
MenuNode::Dynamic { name } => {
// Recent projects / footage / presets, undo history, shortcut slots, viewers.
let (entries, empty) = effectcraft_engine::menus::dynamic(&app.session, name, &crate::menus::dyn_ctx(&app.ui.workspace));
// Recent projects / footage / presets, undo history, shortcut slots, viewers,
// saved workspaces.
let saved = app.saved_workspace_names();
let (entries, empty) = effectcraft_engine::menus::dynamic(&app.session, name, &crate::menus::dyn_ctx(&app.ui.workspace, &saved));
if entries.is_empty()
&& let Some(e) = empty
{
@@ -160,14 +162,14 @@ pub fn build(app: &EffectcraftApp) -> NativeMenu {
shortcut: None,
accelerator: None,
enabled: crate::menus::entry_enabled(app, e),
checked: None,
checked: crate::menus::entry_checked(app, e),
}));
}
}
MenuNode::Submenu { label, children } => {
let mut kids = vec![];
rec(app, children, &id, &mut kids);
let shown = effectcraft_engine::menus::submenu_label(&app.session, label, &crate::menus::dyn_ctx(&app.ui.workspace));
let shown = effectcraft_engine::menus::submenu_label(&app.session, label, &crate::menus::dyn_ctx(&app.ui.workspace, &[]));
out.push(NativeNode::Submenu { label: crate::i18n::submenu(app, label, shown), children: kids });
}
MenuNode::Item(e) => {
@@ -394,6 +396,19 @@ mod tests {
assert!(v["menus"].as_array().is_some_and(|a| a.len() >= 9));
}
/// Issue #191: saved workspaces are in the native Window ▸ Workspace menu, checked while current.
#[test]
fn saved_workspaces_are_in_the_native_workspace_menu() {
let mut app = app();
let ctx = egui::Context::default();
crate::menus::invoke(&mut app, &ctx, "window.saveWorkspaceAs", json!({"name": "My Layout"})).unwrap();
let entry = |app: &EffectcraftApp| build(app).items().into_iter().find(|i| i.label == "My Layout").cloned();
let it = entry(&app).expect("the saved workspace is listed");
assert_eq!((it.command.as_str(), &it.params, it.checked), ("window.workspace", &json!({"name": "My Layout"}), Some(true)));
crate::menus::invoke(&mut app, &ctx, "window.workspace", json!({"name": "Default"})).unwrap();
assert_eq!(entry(&app).and_then(|i| i.checked), Some(false));
}
#[test]
fn hide_items_are_predefined_on_macos() {
let spec = build(&app());