[Bf-blender-cvs] [836eae0ca1c] asset-browser: Cleanup: Use helper classes to deduplicate logic, consistent naming

Julian Eisel noreply at git.blender.org
Fri Nov 20 13:50:58 CET 2020


Commit: 836eae0ca1c21451997d73f0b0ef1281e59b7e16
Author: Julian Eisel
Date:   Fri Nov 20 13:49:40 2020 +0100
Branches: asset-browser
https://developer.blender.org/rB836eae0ca1c21451997d73f0b0ef1281e59b7e16

Cleanup: Use helper classes to deduplicate logic, consistent naming

Also renamed the "Asset Tags" panel to "Tags" (redundancy).

===================================================================

M	release/scripts/modules/bpy_extras/__init__.py
M	release/scripts/modules/bpy_extras/asset_utils.py
M	release/scripts/startup/bl_ui/space_filebrowser.py

===================================================================

diff --git a/release/scripts/modules/bpy_extras/__init__.py b/release/scripts/modules/bpy_extras/__init__.py
index 1caef074d43..cb990b014a1 100644
--- a/release/scripts/modules/bpy_extras/__init__.py
+++ b/release/scripts/modules/bpy_extras/__init__.py
@@ -24,6 +24,7 @@ Utility modules associated with the bpy module.
 
 __all__ = (
     "anim_utils",
+    "asset_utils",
     "object_utils",
     "io_utils",
     "image_utils",
diff --git a/release/scripts/modules/bpy_extras/asset_utils.py b/release/scripts/modules/bpy_extras/asset_utils.py
index cf269825b59..ce18f29d812 100644
--- a/release/scripts/modules/bpy_extras/asset_utils.py
+++ b/release/scripts/modules/bpy_extras/asset_utils.py
@@ -44,4 +44,20 @@ class SpaceAssetInfo:
     def get_active_asset(cls, context: Context):
         if hasattr(context, "active_file"):
             active_file = context.active_file
-            return active_file.asset_data
\ No newline at end of file
+            return active_file.asset_data
+
+class AssetBrowserPanel:
+    bl_space_type = 'FILE_BROWSER'
+
+    @classmethod
+    def poll(cls, context):
+        return SpaceAssetInfo.is_asset_browser_poll(context)
+
+class AssetMetaDataPanel:
+    bl_space_type = 'FILE_BROWSER'
+    bl_region_type = 'TOOL_PROPS'
+
+    @classmethod
+    def poll(cls, context):
+        active_file = context.active_file
+        return SpaceAssetInfo.is_asset_browser_poll(context) and active_file and active_file.asset_data
diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index a7e2b695533..72d521dd853 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -19,6 +19,10 @@
 # <pep8 compliant>
 from bpy.types import Header, Panel, Menu, UIList
 
+from bpy_extras import (
+    asset_utils,
+)
+
 
 class FILEBROWSER_HT_header(Header):
     bl_space_type = 'FILE_BROWSER'
@@ -202,32 +206,6 @@ def panel_poll_is_asset_browsing(context):
     return SpaceAssetInfo.is_asset_browser_poll(context)
 
 
-class FILEBROWSER_PT_asset_navigation_bar(Panel):
-    bl_label = "Asset Navigation"
-    bl_space_type = 'FILE_BROWSER'
-    bl_region_type = 'TOOLS'
-    bl_options = {'HIDE_HEADER'}
-
-    @classmethod
-    def poll(cls, context):
-        return panel_poll_is_asset_browsing(context)
-
-    def draw(self, context):
-        layout = self.layout
-
-        space_file = context.space_data
-
-        col = layout.column()
-
-        col.scale_x = 1.3
-        col.scale_y = 1.3
-        col.prop(space_file.params, "asset_category", expand=True)
-
-        col.separator()
-
-        col.operator("asset.catalog_add", text="Add Catalog", icon='ADD')
-
-
 class FILEBROWSER_UL_dir(UIList):
     def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
         direntry = item
@@ -554,16 +532,32 @@ class FILEBROWSER_MT_context_menu(Menu):
         layout.prop_menu_enum(params, "sort_method")
 
 
-class ASSETBROWSER_PT_metadata(Panel):
-    bl_space_type = 'FILE_BROWSER'
+class ASSETBROWSER_PT_navigation_bar(asset_utils.AssetBrowserPanel, Panel):
+    bl_label = "Asset Navigation"
+    bl_region_type = 'TOOLS'
+    bl_options = {'HIDE_HEADER'}
+
+    def draw(self, context):
+        layout = self.layout
+
+        space_file = context.space_data
+
+        col = layout.column()
+
+        col.scale_x = 1.3
+        col.scale_y = 1.3
+        col.prop(space_file.params, "asset_category", expand=True)
+
+        col.separator()
+
+        col.operator("asset.catalog_add", text="Add Catalog", icon='ADD')
+
+
+class ASSETBROWSER_PT_metadata(asset_utils.AssetBrowserPanel, Panel):
     bl_region_type = 'TOOL_PROPS'
     bl_label = "Asset Meta-data"
     bl_options = {'HIDE_HEADER'}
 
-    @classmethod
-    def poll(cls, context):
-        return panel_poll_is_asset_browsing(context)
-
     def draw(self, context):
         layout = self.layout
         active_file = context.active_file
@@ -574,20 +568,12 @@ class ASSETBROWSER_PT_metadata(Panel):
             layout.label(text="No asset selected.")
 
 
-class ASSETBROWSER_PT_metadata_tags(Panel):
-    bl_space_type = 'FILE_BROWSER'
-    bl_region_type = 'TOOL_PROPS'
-    bl_label = "Asset Tags"
-
-    @classmethod
-    def poll(cls, context):
-        active_file = context.active_file
-        return panel_poll_is_asset_browsing(context) and active_file and active_file.asset_data
+class ASSETBROWSER_PT_metadata_tags(asset_utils.AssetMetaDataPanel, Panel):
+    bl_label = "Tags"
 
     def draw(self, context):
         layout = self.layout
-        active_file = context.active_file
-        asset_data = active_file.asset_data
+        asset_data = asset_utils.SpaceAssetInfo.get_active_asset(context)
 
         row = layout.row()
         row.template_list("ASSETBROWSER_UL_metadata_tags", "asset_tags", asset_data, "tags",
@@ -614,7 +600,6 @@ classes = (
     FILEBROWSER_HT_header,
     FILEBROWSER_PT_display,
     FILEBROWSER_PT_filter,
-    FILEBROWSER_PT_asset_navigation_bar,
     FILEBROWSER_UL_dir,
     FILEBROWSER_PT_bookmarks_volumes,
     FILEBROWSER_PT_bookmarks_system,
@@ -627,6 +612,7 @@ classes = (
     FILEBROWSER_MT_view,
     FILEBROWSER_MT_select,
     FILEBROWSER_MT_context_menu,
+    ASSETBROWSER_PT_navigation_bar,
     ASSETBROWSER_PT_metadata,
     ASSETBROWSER_PT_metadata_tags,
     ASSETBROWSER_UL_metadata_tags,



More information about the Bf-blender-cvs mailing list