diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-10-05 16:27:16 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-10-05 16:27:16 +0300 |
commit | ccb5b1c064c098b4d4279d38847908a203099327 (patch) | |
tree | dcb64e71f14fb92f0f5af8321c254ccf2a80818c | |
parent | 2fee3336a85ac5d5fb7c7765cd8ae2aa4e7621ac (diff) |
Pose Library: only allow pasting assets when in Current File library
Only allow the Paste Asset button to work when the asset browser is set
to the "Current File" library. This ensures that the pasted asset can
actually be seen.
Without this change, an artist is likely to assume the asset will be
pasted into the shown library. This is not the case, though -- pasted
assets always go into the current blend file.
-rw-r--r-- | pose_library/operators.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/pose_library/operators.py b/pose_library/operators.py index 3b038709..4b03d270 100644 --- a/pose_library/operators.py +++ b/pose_library/operators.py @@ -45,6 +45,7 @@ from bpy.types import ( Object, Operator, ) +from bpy_extras import asset_utils class PoseAssetCreator: @@ -256,11 +257,28 @@ class POSELIB_OT_paste_asset(Operator): @classmethod def poll(cls, context: Context) -> bool: + if not asset_utils.SpaceAssetInfo.is_asset_browser(context.space_data): + cls.poll_message_set("Current editor is not an asset browser") + return False + + asset_lib_ref = context.space_data.params.asset_library_ref + if asset_lib_ref != 'LOCAL': + cls.poll_message_set("Asset Browser must be set to the Current File library") + return False + + # Delay checking the clipboard as much as possible, as it's CPU-heavier than the other checks. clipboard: str = context.window_manager.clipboard if not clipboard: + cls.poll_message_set("Clipboard is empty") return False + marker = POSELIB_OT_copy_as_asset.CLIPBOARD_ASSET_MARKER - return clipboard.startswith(marker) + if not clipboard.startswith(marker): + cls.poll_message_set("Clipboard does not contain an asset") + return False + + return True + def execute(self, context: Context) -> Set[str]: clipboard = context.window_manager.clipboard |