diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu.rs b/crates/ui-egui/src/canvas/canvas_tool_menu.rs index 2fa4dba674a..5eb20e9a9ec 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu.rs @@ -753,6 +753,15 @@ fn several_layers_selected(app: &PhotocraftApp) -> bool { app.session.active().is_some_and(|st| st.selected_layers().len() > 1) } +/// Several layers are selected in the front document, every one a pixel layer: the case #12358 +/// measured on the Count tool's layer menu. +fn several_pixel_layers_selected(app: &PhotocraftApp) -> bool { + app.session.active().is_some_and(|st| { + let selected = st.selected_layers(); + selected.len() > 1 && selected.iter().all(|id| st.doc.layer(*id).is_some_and(|l| matches!(l.content, LayerContent::Raster(_)))) + }) +} + /// Is a path with at least two points being drawn with the Pen? pub(crate) fn pen_pending(app: &PhotocraftApp) -> bool { app.ui.pen.as_ref().is_some_and(|p| p.draft.knots.len() >= 2) @@ -1372,12 +1381,13 @@ pub fn entry_enabled(app: &PhotocraftApp, menu: &CanvasToolMenu, command: &str) if inside_selection(menu) && command == "select.loadSelection" { return app.session.active().is_some_and(|st| st.doc.channels.iter().any(|c| c.spot.is_none())) && crate::menus::is_enabled(app, command); } - // #12358, measured on the Count tool's layer menu: with several layers selected, Blending - // Options…, Color Range… and Load Selection… work on one layer, so they are greyed. The other - // tools' layer menus weren't measured with several layers and keep `menus::is_enabled`. + // #12358, measured on the Count tool's layer menu: with several pixel layers selected, + // Blending Options…, Color Range… and Load Selection… work on one layer, so they are greyed. + // Other layer kinds and the other tools' layer menus weren't measured with several layers and + // keep `menus::is_enabled`. if menu.tool == Tool::Count && matches!(command, "layer.layerStyle.blendingOptions" | "select.colorRange" | "select.loadSelection") - && several_layers_selected(app) + && several_pixel_layers_selected(app) { return false; } diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu/layer_plural_tests.rs b/crates/ui-egui/src/canvas/canvas_tool_menu/layer_plural_tests.rs index 472a2015b61..935fe827868 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu/layer_plural_tests.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/layer_plural_tests.rs @@ -169,3 +169,30 @@ fn delete_layers_still_deletes_the_selected_layers() { assert!(st.doc.layer(photocraft_doc::LayerId(id)).is_none(), "layer {id} deleted"); } } + +/// The greying is limited to the measured case, several pixel layers: with two shape layers +/// selected, Blending Options…, Color Range… and Load Selection… follow `menus::is_enabled`. +#[test] +fn with_two_shape_layers_selected_the_one_layer_rows_follow_the_menu_bar() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 64, "height": 48})).unwrap(); + let shape = |app: &mut PhotocraftApp, rect: [u32; 4]| { + app.run("shape.create", json!({"kind": "rect", "rect": rect, "fill": "#3070c0"})).unwrap()["layer"].as_u64().unwrap() + }; + let first = shape(&mut app, [4, 4, 10, 10]); + shape(&mut app, [30, 20, 10, 10]); + app.run("layer.select", json!({"layer": first, "mode": "add"})).unwrap(); + app.sync_views(); + app.ui.tool = Tool::Count; + let ctx = app.ctx().clone(); + assert_eq!(selected(&app), 2); + right_click(&mut app, 50.0, 40.0); + let entries = inspected(&mut app, &ctx); + assert!(!entries.is_empty(), "the Count tool's layer menu is open"); + let rows = ["layer.layerStyle.blendingOptions", "select.colorRange", "select.loadSelection"]; + for id in rows { + let enabled = entries.iter().find(|e| e.0 == id).map(|e| e.2); + assert_eq!(enabled, Some(crate::menus::is_enabled(&app, id)), "{id}"); + } + assert!(rows.iter().any(|id| crate::menus::is_enabled(&app, id)), "the menu bar enables one of them, so the case tells the rules apart"); +}