From 17daca8a87acdbb6b454808151af66320138b2e1 Mon Sep 17 00:00:00 2001 From: Nathaniel Ledford Date: Wed, 7 Oct 2026 13:42:42 -0400 Subject: [PATCH] Menus: list Reshuffle once in the Sort submenu library.shuffle's registry menu path made the menu builder append it a second time after the hand-built entry. Hide it from the auto-listing; test that it appears once and is enabled only while sorting at random. Co-Authored-By: Claude Sonnet 5.5 --- crates/ui-egui/src/menubar.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/ui-egui/src/menubar.rs b/crates/ui-egui/src/menubar.rs index f47d86dea..bcd1ae4ae 100644 --- a/crates/ui-egui/src/menubar.rs +++ b/crates/ui-egui/src/menubar.rs @@ -251,6 +251,7 @@ const HIDDEN: &[&str] = &[ "photo.unflag", "photo.label", "library.sort", + "library.shuffle", "album.addPhotos", "album.create", "library.import", @@ -790,6 +791,30 @@ mod tests { }) } + /// The Sort submenu is expanded by hand: Reshuffle appears once (not again from the registry), + /// only while sorting at random, and the direction items are off for a shuffle. + #[test] + fn sort_menu_lists_reshuffle_once_and_only_enables_it_for_random() { + fn sort_children(bar: &[(String, Vec)]) -> Vec { + let view = &bar.iter().find(|(t, _)| t == "View").expect("View menu").1; + view.iter() + .find_map(|n| match n { + MenuNode::Submenu { label, children } if label == "Sort" => Some(children.clone()), + _ => None, + }) + .expect("Sort submenu") + } + let count = |nodes: &[MenuNode]| nodes.iter().filter(|n| matches!(n, MenuNode::Item { id, .. } if id == "library.shuffle")).count(); + let mut a = app(); + let kids = sort_children(&menu_bar(&a)); + assert_eq!(count(&kids), 1); + assert!(matches!(find(&kids, "library.shuffle"), Some(MenuNode::Item { enabled: false, .. })), "off until Random is chosen"); + a.session.execute("library.sort", &json!({"key": "random"})).expect("sort at random"); + let kids = sort_children(&menu_bar(&a)); + assert_eq!(count(&kids), 1); + assert!(matches!(find(&kids, "library.shuffle"), Some(MenuNode::Item { enabled: true, .. }))); + } + /// File opens with the import entry points, worded as importing (not as adding a sidebar /// folder): Import Photos… (⇧⌘I), Import from Folder…, Import from Device ▸. #[test]