mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 10:51:11 +01:00
Honor plugin command conditions in canvas context menus
This commit is contained in:
2 files changed
+14
-1
No files matched your search
@@ -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<Node> {
|
||||
let groups: Vec<Node> = 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))
|
||||
}
|
||||
|
||||
@@ -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<bool> {
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user