[Bf-blender-cvs] [9d9f205dc4a] master: Asset Browser: Initial Asset Catalog UI

Julian Eisel noreply at git.blender.org
Wed Sep 29 17:15:40 CEST 2021


Commit: 9d9f205dc4a9ddae3d654c64894eaca8443cacc0
Author: Julian Eisel
Date:   Wed Sep 29 17:01:13 2021 +0200
Branches: master
https://developer.blender.org/rB9d9f205dc4a9ddae3d654c64894eaca8443cacc0

Asset Browser: Initial Asset Catalog UI

The Asset Browser now displays a tree with asset catalogs in the left
sidebar.
This replaces the asset categories. It uses the new UI tree-view API
(https://wiki.blender.org/wiki/Source/Interface/Views#Tree-View).
Buttons are displayed for adding and removing of catalogs. Parent items
can be collapsed, but the collapsed/uncollapsed state is not stored in
files yet.
Note that edits to catalogs (e.g. new or removed catalogs) are only
written to the asset library's catalog definition files when saving a
.blend.

In the "Current File" asset library, we try to show asset catalogs from
a parent asset library, or if that fails, from the directory the file is
stored in. See adaf4f56e1ed.

There are plenty of TODOs and smaller glitches to be fixed still. Plus a
UI polishing pass should be done.

Important missing UI features:
* Dragging assets into catalogs (WIP, close to being ready).
* Renaming catalogs
* Proper handling of catalogs in the "Current File" asset library
  (currently not working well).

The "Current File" asset library is especially limited still. Since this
is the only place where you can assign assets to a catalog, this makes
the catalogs very cumbersome in general. To assign an asset to a
catalog, one has to manually copy the Catalog ID (a random hash like
number) to the asset metadata through a temporary UI in the Asset
Browser Sidebar. These limitations should be addressed over the next few
days, they are high priority.

Differential Revision: https://developer.blender.org/D12670

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

M	release/scripts/modules/bpy_extras/asset_utils.py
M	release/scripts/startup/bl_ui/space_filebrowser.py
M	source/blender/blenkernel/BKE_asset_library.hh
M	source/blender/blenkernel/intern/asset_library.cc
M	source/blender/editors/asset/CMakeLists.txt
A	source/blender/editors/asset/ED_asset_catalog.hh
A	source/blender/editors/asset/intern/asset_catalog.cc
M	source/blender/editors/asset/intern/asset_ops.cc
M	source/blender/editors/include/ED_fileselect.h
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/include/UI_tree_view.hh
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/tree_view.cc
M	source/blender/editors/space_file/CMakeLists.txt
A	source/blender/editors/space_file/asset_catalog_tree_view.cc
M	source/blender/editors/space_file/file_intern.h
M	source/blender/editors/space_file/file_panels.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filelist.h
M	source/blender/editors/space_file/filesel.c
M	source/blender/editors/space_file/space_file.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/modules/bpy_extras/asset_utils.py b/release/scripts/modules/bpy_extras/asset_utils.py
index 2cd5dddefbc..c7ebdc1d5e1 100644
--- a/release/scripts/modules/bpy_extras/asset_utils.py
+++ b/release/scripts/modules/bpy_extras/asset_utils.py
@@ -52,19 +52,12 @@ class AssetBrowserPanel:
     bl_space_type = 'FILE_BROWSER'
 
     @classmethod
-    def poll(cls, context):
+    def asset_browser_panel_poll(cls, context):
         return SpaceAssetInfo.is_asset_browser_poll(context)
 
-
-class AssetBrowserSpecificCategoryPanel(AssetBrowserPanel):
-    asset_categories = set()  # Set of strings like 'ANIMATIONS', see `asset_category_items` in rna_space.c
-
     @classmethod
     def poll(cls, context):
-        return (
-            SpaceAssetInfo.is_asset_browser_poll(context)
-            and context.space_data.params.asset_category in cls.asset_categories
-        )
+        return cls.asset_browser_panel_poll(context)
 
 
 class AssetMetaDataPanel:
diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index b47404fd727..5dd8c69f3d5 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -648,30 +648,6 @@ class ASSETBROWSER_MT_select(AssetBrowserMenu, Menu):
         layout.operator("file.select_box")
 
 
-class ASSETBROWSER_PT_navigation_bar(asset_utils.AssetBrowserPanel, Panel):
-    bl_label = "Asset Navigation"
-    bl_region_type = 'TOOLS'
-    bl_options = {'HIDE_HEADER'}
-
-    @classmethod
-    def poll(cls, context):
-        return (
-            asset_utils.AssetBrowserPanel.poll(context) and
-            context.preferences.experimental.use_extended_asset_browser
-        )
-
-    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)
-
-
 class ASSETBROWSER_PT_metadata(asset_utils.AssetBrowserPanel, Panel):
     bl_region_type = 'TOOL_PROPS'
     bl_label = "Asset Metadata"
@@ -821,7 +797,6 @@ classes = (
     ASSETBROWSER_MT_editor_menus,
     ASSETBROWSER_MT_view,
     ASSETBROWSER_MT_select,
-    ASSETBROWSER_PT_navigation_bar,
     ASSETBROWSER_PT_metadata,
     ASSETBROWSER_PT_metadata_preview,
     ASSETBROWSER_PT_metadata_details,
diff --git a/source/blender/blenkernel/BKE_asset_library.hh b/source/blender/blenkernel/BKE_asset_library.hh
index fc5e137dd3e..1dc02f7aa9b 100644
--- a/source/blender/blenkernel/BKE_asset_library.hh
+++ b/source/blender/blenkernel/BKE_asset_library.hh
@@ -48,3 +48,7 @@ struct AssetLibrary {
 };
 
 }  // namespace blender::bke
+
+blender::bke::AssetCatalogService *BKE_asset_library_get_catalog_service(
+    const ::AssetLibrary *library);
+blender::bke::AssetCatalogTree *BKE_asset_library_get_catalog_tree(const ::AssetLibrary *library);
diff --git a/source/blender/blenkernel/intern/asset_library.cc b/source/blender/blenkernel/intern/asset_library.cc
index 1086efe45fd..27e66ee5725 100644
--- a/source/blender/blenkernel/intern/asset_library.cc
+++ b/source/blender/blenkernel/intern/asset_library.cc
@@ -68,6 +68,29 @@ bool BKE_asset_library_find_suitable_root_path_from_main(const Main *bmain, char
   return BKE_asset_library_find_suitable_root_path_from_path(bmain->name, r_library_path);
 }
 
+blender::bke::AssetCatalogService *BKE_asset_library_get_catalog_service(
+    const ::AssetLibrary *library_c)
+{
+  if (library_c == nullptr) {
+    return nullptr;
+  }
+
+  const blender::bke::AssetLibrary &library = reinterpret_cast<const blender::bke::AssetLibrary &>(
+      *library_c);
+  return library.catalog_service.get();
+}
+
+blender::bke::AssetCatalogTree *BKE_asset_library_get_catalog_tree(const ::AssetLibrary *library)
+{
+  blender::bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(
+      library);
+  if (catalog_service == nullptr) {
+    return nullptr;
+  }
+
+  return catalog_service->get_catalog_tree();
+}
+
 namespace blender::bke {
 
 void AssetLibrary::load(StringRefNull library_root_directory)
diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt
index 31c07580570..b6657bfca63 100644
--- a/source/blender/editors/asset/CMakeLists.txt
+++ b/source/blender/editors/asset/CMakeLists.txt
@@ -31,6 +31,7 @@ set(INC_SYS
 )
 
 set(SRC
+  intern/asset_catalog.cc
   intern/asset_filter.cc
   intern/asset_handle.cc
   intern/asset_library_reference.cc
@@ -40,6 +41,7 @@ set(SRC
   intern/asset_ops.cc
   intern/asset_temp_id_consumer.cc
 
+  ED_asset_catalog.hh
   ED_asset_filter.h
   ED_asset_handle.h
   ED_asset_library.h
diff --git a/source/blender/blenkernel/BKE_asset_library.hh b/source/blender/editors/asset/ED_asset_catalog.hh
similarity index 60%
copy from source/blender/blenkernel/BKE_asset_library.hh
copy to source/blender/editors/asset/ED_asset_catalog.hh
index fc5e137dd3e..cffd7728a60 100644
--- a/source/blender/blenkernel/BKE_asset_library.hh
+++ b/source/blender/editors/asset/ED_asset_catalog.hh
@@ -15,36 +15,21 @@
  */
 
 /** \file
- * \ingroup bke
+ * \ingroup edasset
  */
 
 #pragma once
 
-#ifndef __cplusplus
-#  error This is a C++-only header file. Use BKE_asset_library.h instead.
-#endif
-
-#include "BKE_asset_library.h"
-
 #include "BKE_asset_catalog.hh"
-#include "BKE_callbacks.h"
 
-#include <memory>
+#include "BLI_string_ref.hh"
 
+struct AssetLibrary;
 namespace blender::bke {
-
-struct AssetLibrary {
-  std::unique_ptr<AssetCatalogService> catalog_service;
-
-  void load(StringRefNull library_root_directory);
-
-  void on_save_handler_register();
-  void on_save_handler_unregister();
-
-  void on_save_post(struct Main *, struct PointerRNA **pointers, const int num_pointers);
-
- private:
-  bCallbackFuncStore on_save_callback_store_;
-};
-
+class AssetCatalog;
 }  // namespace blender::bke
+
+blender::bke::AssetCatalog *ED_asset_catalog_add(AssetLibrary *library,
+                                                 blender::StringRefNull name,
+                                                 blender::StringRef parent_path = nullptr);
+void ED_asset_catalog_remove(AssetLibrary *library, const blender::bke::CatalogID &catalog_id);
diff --git a/source/blender/editors/asset/intern/asset_catalog.cc b/source/blender/editors/asset/intern/asset_catalog.cc
new file mode 100644
index 00000000000..202d4234051
--- /dev/null
+++ b/source/blender/editors/asset/intern/asset_catalog.cc
@@ -0,0 +1,87 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup edasset
+ */
+
+#include "BKE_asset_catalog.hh"
+#include "BKE_asset_library.hh"
+
+#include "BLI_string_utils.h"
+
+#include "ED_asset_catalog.hh"
+
+using namespace blender;
+using namespace blender::bke;
+
+struct CatalogUniqueNameFnData {
+  const AssetCatalogService &catalog_service;
+  StringRef parent_path;
+};
+
+static std::string to_full_path(StringRef parent_path, StringRef name)
+{
+  return parent_path.is_empty() ?
+             std::string(name) :
+             std::string(parent_path) + AssetCatalogService::PATH_SEPARATOR + name;
+}
+
+static bool catalog_name_exists_fn(void *arg, const char *name)
+{
+  CatalogUniqueNameFnData &fn_data = *static_cast<CatalogUniqueNameFnData *>(arg);
+  std::string fullpath = to_full_path(fn_data.parent_path, name);
+  return fn_data.catalog_service.find_catalog_by_path(fullpath);
+}
+
+static std::string catalog_name_ensure_unique(AssetCatalogService &catalog_service,
+                                              StringRefNull name,
+                                              StringRef parent_path)
+{
+  CatalogUniqueNameFnData fn_data = {catalog_service, parent_path};
+
+  char unique_name[NAME_MAX] = "";
+  BLI_uniquename_cb(
+      catalog_name_exists_fn, &fn_data, name.c_str(), '.', unique_name, sizeof(unique_name));
+
+  return unique_name;
+}
+
+AssetCatalog *ED_asset_catalog_add(::AssetLibrary *library,
+                                   StringRefNull name,
+                                   StringRef parent_path)
+{
+  bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library);
+  if (!catalog_service) {
+    return nullptr;
+  }
+
+  std::string unique_name = catalog_name_ensure_unique(*catalog_service, name, parent_path);
+  std::string fullpath = to_full_path(parent_path, unique_name);
+
+  return catalog_service->create_catalog(fullpath);
+}
+
+void ED_asset_catalog_remove(::AssetLibrary *library, const CatalogID &catalog_id)
+{
+  bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library);
+  if (!catalog_service) {
+    BLI_assert_unreachable();
+    return;
+  }
+
+  catalog_service->delete_catalog(catalog_id);
+}
diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc
index a18b7649060..5424bae77b4 100644
--- a/source/blender/editors/asset/intern/asset_ops.cc
+++ b/source/blender/editors/asset/intern/asset_ops.cc
@@ -18,13 +18,18 @@
  * \ingroup edasset
  */
 
+#include "BKE_asset_catalog.hh"
 #include "BKE_context.h"
 #include "BKE_lib_id.h"
 #include "BKE_report.h"
 
+#include "BLI_string_ref.hh"
 #include "BLI_vector.hh"
 
 #include "ED_asset.h"
+#include "ED_asset_catalog.hh"
+/* XXX needs access to the file list, should all be done via the asset system in future. */
+#include "ED_fileselect.h"
 
 #include "RNA_access.h"
 #in

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list