Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-09-23 15:43:21 +0300
committerJulian Eisel <julian@blender.org>2021-09-23 15:46:13 +0300
commit222fd1abf09ae65b7082f58bf2ac43422c77162c (patch)
treeaeb1c3723f8e3d80723e28660d35889c3dfdeaa9 /release
parent059d01d42e049a5d4a42f81c8b860540127efeb6 (diff)
Asset Browser: Disable metadata editing for external asset libraries
Buttons to edit asset metadata are now disabled for assets from an external library (i.e. assets not stored in the current .blend file). Their tooltips explain why they are disabled. Had to do some RNA trickery to disable the metadata properties at RNA level, not at UI script level. The basic idea is: * Local data-block assets set the data-block as owning ID for the asset metadata RNA pointer now. * That way we can use the owner ID to see where the metadata belongs to and decide if it's editable that way. * Additionaly, some Python operators needed better polling so they show as grayed out, and don't just fail. One important thing: Custom properties of the metadata can still be edited. The edits won't be saved however. Would be nice to disable that, but it's currently not supported on BPY/IDProperty/RNA level. Addresses T82943. Differential Revision: https://developer.blender.org/D12127
Diffstat (limited to 'release')
-rw-r--r--release/scripts/startup/bl_operators/assets.py42
1 files changed, 26 insertions, 16 deletions
diff --git a/release/scripts/startup/bl_operators/assets.py b/release/scripts/startup/bl_operators/assets.py
index b241e537c38..de46e5c85fb 100644
--- a/release/scripts/startup/bl_operators/assets.py
+++ b/release/scripts/startup/bl_operators/assets.py
@@ -27,17 +27,28 @@ from bpy_extras.asset_utils import (
)
-class ASSET_OT_tag_add(Operator):
+class AssetBrowserMetadataOperator:
+ @classmethod
+ def poll(cls, context):
+ if not SpaceAssetInfo.is_asset_browser_poll(context) or not context.asset_file_handle:
+ return False
+
+ if not context.asset_file_handle.local_id:
+ Operator.poll_message_set(
+ "Asset metadata from external asset libraries can't be "
+ "edited, only assets stored in the current file can"
+ )
+ return False
+ return True
+
+
+class ASSET_OT_tag_add(AssetBrowserMetadataOperator, Operator):
"""Add a new keyword tag to the active asset"""
bl_idname = "asset.tag_add"
bl_label = "Add Asset Tag"
bl_options = {'REGISTER', 'UNDO'}
- @classmethod
- def poll(cls, context):
- return SpaceAssetInfo.is_asset_browser_poll(context) and SpaceAssetInfo.get_active_asset(context)
-
def execute(self, context):
active_asset = SpaceAssetInfo.get_active_asset(context)
active_asset.tags.new("Unnamed Tag")
@@ -45,7 +56,7 @@ class ASSET_OT_tag_add(Operator):
return {'FINISHED'}
-class ASSET_OT_tag_remove(Operator):
+class ASSET_OT_tag_remove(AssetBrowserMetadataOperator, Operator):
"""Remove an existing keyword tag from the active asset"""
bl_idname = "asset.tag_remove"
@@ -54,21 +65,20 @@ class ASSET_OT_tag_remove(Operator):
@classmethod
def poll(cls, context):
- if not SpaceAssetInfo.is_asset_browser_poll(context):
+ if not super().poll(context):
return False
- active_asset = SpaceAssetInfo.get_active_asset(context)
- if not active_asset:
- return False
-
- return active_asset.active_tag in range(len(active_asset.tags))
+ active_asset_file = context.asset_file_handle
+ asset_metadata = active_asset_file.asset_data
+ return asset_metadata.active_tag in range(len(asset_metadata.tags))
def execute(self, context):
- active_asset = SpaceAssetInfo.get_active_asset(context)
- tag = active_asset.tags[active_asset.active_tag]
+ active_asset_file = context.asset_file_handle
+ asset_metadata = active_asset_file.asset_data
+ tag = asset_metadata.tags[asset_metadata.active_tag]
- active_asset.tags.remove(tag)
- active_asset.active_tag -= 1
+ asset_metadata.tags.remove(tag)
+ asset_metadata.active_tag -= 1
return {'FINISHED'}