From 46a2bc63517759fd0c642aaf30228e3c2bd0ebe2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 11:07:34 -0800 Subject: [PATCH] Honor plugin command conditions in canvas context menus --- crates/ui-egui/src/dialogs/plugin.rs | 5 ++++- crates/ui-egui/src/tests/plugins.rs | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/plugin.rs b/crates/ui-egui/src/dialogs/plugin.rs index 83ab829440..8890b9dd72 100644 --- a/crates/ui-egui/src/dialogs/plugin.rs +++ b/crates/ui-egui/src/dialogs/plugin.rs @@ -248,7 +248,10 @@ pub fn context_commands(menu: ContextMenu, doc: &vectorcraft_doc::Document, ids: pub fn canvas_submenu(doc: &vectorcraft_doc::Document, ids: &[u64]) -> Option { let groups: Vec = context_commands(ContextMenu::Canvas, doc, ids) .into_iter() - .map(|(name, commands)| sub(name, commands.into_iter().map(|command| cp(command.label, command.command, json!({ "ids": ids }))).collect())) + .map(|(name, commands)| { + let items = commands.into_iter().map(|command| cp(command.label, command.command, json!({ "ids": ids })).enabled(command.enabled)).collect(); + sub(name, items) + }) .collect(); (!groups.is_empty()).then_some(sub("Plug-ins", groups)) } diff --git a/crates/ui-egui/src/tests/plugins.rs b/crates/ui-egui/src/tests/plugins.rs index e4bb835de2..d9e0233302 100644 --- a/crates/ui-egui/src/tests/plugins.rs +++ b/crates/ui-egui/src/tests/plugins.rs @@ -766,6 +766,16 @@ fn plugin_commands_are_listed_in_the_canvas_and_layers_context_menus() { assert!(listed.iter().all(|(.., p)| *p == ids), "{listed:?}"); let shown = |app: &VectorcraftApp, c: &str| menus::shown_state(app, c, &ids).map(|(enabled, _)| enabled); assert_eq!((shown(app, &command("tidy")), shown(app, &command("text"))), (Some(true), Some(false)), "no type object is selected"); + fn rendered_enabled(nodes: &[menus::Node], command: &str) -> Option { + nodes.iter().find_map(|node| match node { + menus::Node::Item(item) if item.command.id == command => Some(item.enabled), + menus::Node::Submenu { children, .. } => rendered_enabled(children, command), + _ => None, + }) + } + let rendered = menus::context_items(app); + assert_eq!(rendered_enabled(&rendered, &command("tidy")), Some(true)); + assert_eq!(rendered_enabled(&rendered, &command("text")), Some(false)); let doc = app.session.doc().unwrap().doc.clone(); let rows = |ids: &[u64]| context_commands(ContextMenu::Layers, &doc, ids);