Pose Library: Add operators to context menu of poses in the asset view

Adds the following operators to the menu:
* Apply Pose
* Blend Pose
* Select Pose Bones
* Deselect Pose Bones

Note that the latter two don't work yet with the asset view template (they are
implemented based on Asset Browser context) and are grayed out. They need to be
updated to also work with the asset view context.
This commit is contained in:
Julian Eisel 2021-04-01 17:39:20 +02:00
parent c294704a0f
commit 4422b945d5
Notes: blender-bot 2023-02-13 19:06:05 +01:00
Referenced by issue blender/blender#87066: Asset View UI template: Add Pose Operators to Context Menu
Referenced by issue blender/blender#87066, Asset View UI template: Add Pose Operators to Context Menu
1 changed files with 39 additions and 1 deletions

View File

@ -61,6 +61,32 @@ class VIEW3D_PT_pose_library(Panel):
drag_op_props.release_confirm = True
def pose_library_list_item_context_menu(self, context) -> None:
def _poll(context) -> bool:
# Important: Must check context first, or the menu is added for every kind of list.
list = context.ui_list
if not list or list.bl_idname != "UI_UL_asset_view" or list.list_id != "pose_assets":
return False
if not context.asset_handle:
return False
return True
if _poll(context) == False:
return
layout = self.layout
layout.separator()
layout.operator("poselib.apply_pose_asset", text="Apply Pose")
layout.operator("poselib.blend_pose_asset", text="Blend Pose")
props = layout.operator("poselib.pose_asset_select_bones", text="Select Pose Bones")
props.select = True
props = layout.operator("poselib.pose_asset_select_bones", text="Deselect Pose Bones")
props.select = False
class ASSETBROWSER_PT_pose_library_usage(asset_utils.AssetBrowserPanel, Panel):
bl_region_type = "TOOLS"
bl_label = "Pose Library"
@ -127,4 +153,16 @@ classes = (
VIEW3D_PT_pose_library,
)
register, unregister = bpy.utils.register_classes_factory(classes)
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
bpy.types.UI_MT_list_item_context_menu.prepend(pose_library_list_item_context_menu)
def unregister():
from bpy.utils import unregister_class
for cls in classes:
unregister_class(cls)
bpy.types.UI_MT_list_item_context_menu.remove(pose_library_list_item_context_menu)