From 5b8207fa97e449190b49574f83d4d7a90055dfcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 9 Jan 2024 10:23:23 +0100 Subject: [PATCH] Anim: bone collection context menu, prevent operations on linked Prevent operating on linked bone collections via the tree view context menu. --- .../startup/bl_ui/properties_data_armature.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/startup/bl_ui/properties_data_armature.py b/scripts/startup/bl_ui/properties_data_armature.py index 9ff22cf778f..e262516d601 100644 --- a/scripts/startup/bl_ui/properties_data_armature.py +++ b/scripts/startup/bl_ui/properties_data_armature.py @@ -158,11 +158,18 @@ class ARMATURE_MT_collection_tree_context_menu(Menu): layout = self.layout arm = context.armature - props = layout.operator( + active_bcoll_is_locked = arm.collections.active and not arm.collections.active.is_editable + + # The poll function doesn't have access to the parent index property, so + # it cannot disable this operator depending on whether the parent is + # editable or not. That means this menu has to do the disabling for it. + sub = layout.column() + sub.enabled = not active_bcoll_is_locked + props = sub.operator( "armature.collection_add", text="Add Child Collection" ) props.parent_index = arm.collections.active_index - layout.operator("armature.collection_remove") + sub.operator("armature.collection_remove") layout.separator() @@ -171,8 +178,13 @@ class ARMATURE_MT_collection_tree_context_menu(Menu): layout.separator() - layout.operator("armature.collection_assign", text="Assign Selected Bones") - layout.operator("armature.collection_unassign", text="Remove Selected Bones") + # These operators can be used to assign to a named collection as well, and + # don't necessarily always use the active bone collection. That means that + # they have the same limitation as described above. + sub = layout.column() + sub.enabled = not active_bcoll_is_locked + sub.operator("armature.collection_assign", text="Assign Selected Bones") + sub.operator("armature.collection_unassign", text="Remove Selected Bones") layout.separator()