diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu.rs b/crates/ui-egui/src/canvas/canvas_tool_menu.rs index 3468795b9a5..ff45431f9a1 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu.rs @@ -153,7 +153,17 @@ pub fn transform_app_rows() -> [Entry; 2] { /// Photoshop's pasteboard menu (right-click outside the image): the pasteboard colour, the choice /// Preferences › Interface also offers. The ids are this menu's own: [`choose`] turns them into /// `prefs.set` (`pasteboard.`) or opens the Color Picker. -pub const PASTEBOARD_MENU: &[Row] = &[ +pub const PASTEBOARD_MENU: &[Row] = PASTEBOARD_MOVE_MENU.split_at(2).1; + +/// The Window item the Move tool's pasteboard menu toggles the contextual task bar with (#16757). +pub const PASTEBOARD_TASK_BAR: &str = "window.panel.contextualTaskBar"; + +/// The Move tool's pasteboard menu, as measured (#16757): Hide Contextual Task Bar (Show… while the +/// bar is off, [`row_label`]) and a separator above the colour rows. Other tools weren't measured and +/// keep [`PASTEBOARD_MENU`]. +pub const PASTEBOARD_MOVE_MENU: &[Row] = &[ + Some(("Hide Contextual Task Bar", PASTEBOARD_TASK_BAR)), + None, Some(("Default", "pasteboard.default")), Some(("Black", "pasteboard.black")), Some(("Dark Gray", "pasteboard.darkGray")), @@ -903,6 +913,9 @@ pub(crate) fn row_label(app: &PhotocraftApp, menu: &CanvasToolMenu, label: &'sta if menu.tool == Tool::AddAnchorPoint { return add_anchor_row_label(app, menu, label, command); } + if command == PASTEBOARD_TASK_BAR && !app.ui.panels.context_task_bar { + return "Show Contextual Task Bar"; + } if command != "path.transform" || !matches!(menu.tool, Tool::Pen | Tool::FreeformPen | Tool::CurvaturePen) { return label; } @@ -1189,6 +1202,7 @@ pub fn rows(menu: &CanvasToolMenu) -> &'static [Row] { match &menu.kind { MenuKind::Crop { .. } | MenuKind::Layers { .. } | MenuKind::BrushMode { .. } => &[], MenuKind::Guide => GUIDE_MENU, + MenuKind::Pasteboard if menu.tool == Tool::Move => PASTEBOARD_MOVE_MENU, MenuKind::Pasteboard => PASTEBOARD_MENU, MenuKind::View => { if menu.tool == Tool::Hand { @@ -1428,8 +1442,13 @@ fn choose_guide(app: &mut PhotocraftApp, ctx: &Context, command: &str) -> Result crate::menus::invoke(app, ctx, command, json!({})).map(|_| ()) } -/// A pasteboard row: set the colour, or open the Color Picker on the custom one. +/// A pasteboard row: set the colour, open the Color Picker on the custom one, or run the Window +/// item that hides or shows the contextual task bar. fn choose_pasteboard(app: &mut PhotocraftApp, menu: &CanvasToolMenu, command: &str) -> Result<(), String> { + if command == PASTEBOARD_TASK_BAR { + let ctx = app.ctx().clone(); + return crate::menus::invoke(app, &ctx, command, json!({})).map(|_| ()); + } if command == PASTEBOARD_PICK { let rgb = prefs::parse_hex(&app.session.prefs().interface.canvas_custom_color).map_or([0.5; 3], |c| c.map(|v| f32::from(v) / 255.0)); crate::color_picker_ui::open_for_target(app, "pasteboard", "Color Picker (Custom Canvas Color)", rgb)?; @@ -1448,7 +1467,7 @@ pub fn entry_enabled(app: &PhotocraftApp, menu: &CanvasToolMenu, command: &str) _ => GUIDE_MENU.iter().flatten().any(|(_, id)| *id == command) && crate::menus::is_enabled(app, command), }; } - MenuKind::Pasteboard => return PASTEBOARD_MENU.iter().flatten().any(|(_, id)| *id == command), + MenuKind::Pasteboard => return rows(menu).iter().flatten().any(|(_, id)| *id == command), MenuKind::View if command == "view.fillScreen" => return app.session.active().is_some(), MenuKind::View => return crate::menus::is_enabled(app, command), MenuKind::TypeEdit { .. } => { @@ -1935,6 +1954,8 @@ pub fn entries(app: &PhotocraftApp, menu: &CanvasToolMenu) -> Vec> "Duplicate Layers…" => tl!("Duplicate Layers…"), "Delete Layers" => tl!("Delete Layers"), "Rasterize Layers" => tl!("Rasterize Layers"), + "Hide Contextual Task Bar" => tl!("Hide Contextual Task Bar"), + "Show Contextual Task Bar" => tl!("Show Contextual Task Bar"), key => tl!(key), }; out.push(Entry::new(command.to_string(), text.to_string()).enabled(entry_enabled(app, menu, command)).checked(mode_checked(app, menu, command))); @@ -2017,6 +2038,10 @@ mod cam_menu_tests; #[cfg(test)] pub(crate) mod tests; +#[cfg(test)] +#[path = "../task_bar_pasteboard_entry_tests.rs"] +mod task_bar_pasteboard_entry_tests; + #[cfg(test)] pub(crate) mod count_tests; diff --git a/crates/ui-egui/src/task_bar_pasteboard_entry_tests.rs b/crates/ui-egui/src/task_bar_pasteboard_entry_tests.rs new file mode 100644 index 00000000000..f88e7fdbbbd --- /dev/null +++ b/crates/ui-egui/src/task_bar_pasteboard_entry_tests.rs @@ -0,0 +1,66 @@ +//! #16757: with the Move tool, the pasteboard's right-click menu starts with Hide Contextual Task Bar +//! (Show Contextual Task Bar while the bar is off) and a separator, and the row toggles the same flag +//! as Window › Contextual Task Bar. + +use egui::{Modifiers, vec2}; +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::canvas_tool_menu::tests::{harness, right_click}; +use crate::state::Tool; + +fn app(tool: Tool) -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 32, "height": 32})).unwrap(); + app.ui.tool = tool; + app +} + +/// Right-clicks the pasteboard and returns the open menu's rows, a separator as `None`. +fn pasteboard_rows(h: &mut Harness<'static, Box>) -> Vec> { + let pasteboard = h.state().last_canvas_rect.min + vec2(5.0, 5.0); + right_click(h, pasteboard, Modifiers::NONE); + let inspected = crate::control::inspect(h.state(), &h.ctx); + assert_eq!(inspected["canvasToolMenu"]["pasteboard"], json!(true), "the pasteboard menu opens"); + let entries = inspected["canvasToolMenu"]["entries"].as_array().expect("pasteboard menu entries"); + entries.iter().map(|e| if e["separator"] == json!(true) { None } else { e["label"].as_str().map(str::to_owned) }).collect() +} + +#[test] +fn the_move_tools_pasteboard_menu_starts_with_the_task_bar_row() { + let mut marquee = harness(app(Tool::RectMarquee)); + let today = pasteboard_rows(&mut marquee); + assert!(!today.iter().flatten().any(|label| label.contains("Contextual Task Bar")), "other tools keep today's menu: {today:?}"); + + let mut h = harness(app(Tool::Move)); + let rows = pasteboard_rows(&mut h); + assert_eq!(rows.first(), Some(&Some("Hide Contextual Task Bar".to_owned())), "{rows:?}"); + assert_eq!(rows.get(1), Some(&None), "a separator under it: {rows:?}"); + assert_eq!(rows[2..], today[..], "then today's colour rows"); +} + +#[test] +fn the_task_bar_row_hides_and_shows_the_bar_as_the_window_item_does() { + let mut h = harness(app(Tool::Move)); + assert!(h.state().ui.panels.context_task_bar); + + pasteboard_rows(&mut h); + h.get_by_label("Hide Contextual Task Bar").click(); + h.run_steps(2); + assert!(!h.state().ui.panels.context_task_bar, "the row hides the bar"); + assert!(h.state().ui.canvas_tool_menu.is_none(), "and closes the menu"); + // The Window item toggles the same flag: one press turns the bar back on, and off again. + let ctx = h.ctx.clone(); + let window_item = + |h: &mut Harness<'static, Box>| crate::menus::invoke(h.state_mut(), &ctx, "window.panel.contextualTaskBar", json!({})).unwrap(); + assert_eq!(window_item(&mut h), json!(true)); + assert_eq!(window_item(&mut h), json!(false)); + + let rows = pasteboard_rows(&mut h); + assert_eq!(rows.first(), Some(&Some("Show Contextual Task Bar".to_owned())), "{rows:?}"); + h.get_by_label("Show Contextual Task Bar").click(); + h.run_steps(2); + assert!(h.state().ui.panels.context_task_bar, "the row shows the bar again"); +}