[Bf-blender-cvs] [392b67aab0f] temp-asset-browser-catalogs-ui: Port UI code to use the new catalog UUIDs

Julian Eisel noreply at git.blender.org
Tue Sep 21 17:04:11 CEST 2021


Commit: 392b67aab0f0f56f635ce1be273e3e48cd700714
Author: Julian Eisel
Date:   Tue Sep 21 17:03:42 2021 +0200
Branches: temp-asset-browser-catalogs-ui
https://developer.blender.org/rB392b67aab0f0f56f635ce1be273e3e48cd700714

Port UI code to use the new catalog UUIDs

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

M	source/blender/blenkernel/BKE_asset_catalog.hh
M	source/blender/blenkernel/intern/asset_catalog.cc
A	source/blender/blenkernel/intern/asset_catalog.cc.orig
M	source/blender/blenkernel/intern/screen.c
M	source/blender/editors/space_file/asset_catalog_tree_view.cc
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filelist.h
M	source/blender/editors/space_file/space_file.c
M	source/blender/makesdna/DNA_space_types.h

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

diff --git a/source/blender/blenkernel/BKE_asset_catalog.hh b/source/blender/blenkernel/BKE_asset_catalog.hh
index 8375960e3eb..439de88a498 100644
--- a/source/blender/blenkernel/BKE_asset_catalog.hh
+++ b/source/blender/blenkernel/BKE_asset_catalog.hh
@@ -132,11 +132,11 @@ class AssetCatalogTreeItem {
   using ItemIterFn = FunctionRef<void(const AssetCatalogTreeItem &)>;
 
   AssetCatalogTreeItem(StringRef name,
-                       StringRef catalog_id,
+                       const CatalogID &catalog_id,
                        const AssetCatalogTreeItem *parent = nullptr);
 
   AssetCatalogTreeItemIterator children();
-  StringRef get_catalog_id() const;
+  const CatalogID &get_catalog_id() const;
   StringRef get_name() const;
   /** Return the full catalog path, defined as the name of this catalog prefixed by the full
    * catalog path of its parent and a separator. */
diff --git a/source/blender/blenkernel/intern/asset_catalog.cc b/source/blender/blenkernel/intern/asset_catalog.cc
index 6417e78d964..9aa98424e4c 100644
--- a/source/blender/blenkernel/intern/asset_catalog.cc
+++ b/source/blender/blenkernel/intern/asset_catalog.cc
@@ -369,7 +369,7 @@ std::unique_ptr<AssetCatalogTree> AssetCatalogService::read_into_tree()
 /* ---------------------------------------------------------------------- */
 
 AssetCatalogTreeItem::AssetCatalogTreeItem(StringRef name,
-                                           StringRef catalog_id,
+                                           const CatalogID &catalog_id,
                                            const AssetCatalogTreeItem *parent)
     : name_(name), catalog_id_(catalog_id), parent_(parent)
 {
@@ -385,7 +385,7 @@ void AssetCatalogService::rebuild_tree()
   this->catalog_tree_ = read_into_tree();
 }
 
-StringRef AssetCatalogTreeItem::get_catalog_id() const
+const CatalogID &AssetCatalogTreeItem::get_catalog_id() const
 {
   return catalog_id_;
 }
diff --git a/source/blender/blenkernel/intern/asset_catalog.cc b/source/blender/blenkernel/intern/asset_catalog.cc.orig
similarity index 87%
copy from source/blender/blenkernel/intern/asset_catalog.cc
copy to source/blender/blenkernel/intern/asset_catalog.cc.orig
index 6417e78d964..b7eaeec86f7 100644
--- a/source/blender/blenkernel/intern/asset_catalog.cc
+++ b/source/blender/blenkernel/intern/asset_catalog.cc.orig
@@ -50,6 +50,7 @@ AssetCatalog *AssetCatalogService::find_catalog(CatalogID catalog_id)
   return catalog_uptr_ptr->get();
 }
 
+<<<<<<< HEAD
 AssetCatalog *AssetCatalogService::find_catalog_from_path(const CatalogPath &path) const
 {
   for (auto &catalog : catalogs_.values()) {
@@ -59,8 +60,7 @@ AssetCatalog *AssetCatalogService::find_catalog_from_path(const CatalogPath &pat
   }
 
   return nullptr;
-}
-
+=======
 void AssetCatalogService::delete_catalog(CatalogID catalog_id)
 {
   std::unique_ptr<AssetCatalog> *catalog_uptr_ptr = this->catalogs_.lookup_ptr(catalog_id);
@@ -80,6 +80,7 @@ void AssetCatalogService::delete_catalog(CatalogID catalog_id)
   this->catalogs_.remove(catalog_id);
 
   this->rebuild_tree();
+>>>>>>> temp-asset-browser-catalogs
 }
 
 AssetCatalog *AssetCatalogService::create_catalog(const CatalogPath &catalog_path)
@@ -360,12 +361,44 @@ std::unique_ptr<AssetCatalogTree> AssetCatalogService::read_into_tree()
 
   /* Go through the catalogs, insert each path component into the tree where needed. */
   for (auto &catalog : catalogs_.values()) {
+<<<<<<< HEAD
     tree->insert_item(*catalog);
+=======
+    const AssetCatalogTreeItem *parent = nullptr;
+    AssetCatalogTreeItem::ChildMap *insert_to_map = &tree->children_;
+
+    BLI_assert_msg(!ELEM(catalog->path[0], '/', '\\'),
+                   "Malformed catalog path: Path should be formatted like a relative path");
+
+    const char *next_slash_ptr;
+    /* Looks more complicated than it is, this just iterates over path components. E.g.
+     * "just/some/path" iterates over "just", then "some" then "path". */
+    for (const char *name_begin = catalog->path.data(); name_begin && name_begin[0];
+         /* Jump to one after the next slash if there is any. */
+         name_begin = next_slash_ptr ? next_slash_ptr + 1 : nullptr) {
+      next_slash_ptr = BLI_path_slash_find(name_begin);
+
+      /* Note that this won't be null terminated. */
+      StringRef component_name = next_slash_ptr ?
+                                     StringRef(name_begin, next_slash_ptr - name_begin) :
+                                     /* Last component in the path. */
+                                     name_begin;
+
+      /* Insert new tree element - if no matching one is there yet! */
+      auto [item, was_inserted] = insert_to_map->emplace(
+          component_name, AssetCatalogTreeItem(component_name, parent));
+
+      /* Walk further into the path (no matter if a new item was created or not). */
+      parent = &item->second;
+      insert_to_map = &item->second.children_;
+    }
+>>>>>>> temp-asset-browser-catalogs
   }
 
   return tree;
 }
 
+<<<<<<< HEAD
 /* ---------------------------------------------------------------------- */
 
 AssetCatalogTreeItem::AssetCatalogTreeItem(StringRef name,
@@ -376,13 +409,17 @@ AssetCatalogTreeItem::AssetCatalogTreeItem(StringRef name,
 }
 
 AssetCatalogTreeItemIterator AssetCatalogTreeItem::children()
+=======
+void AssetCatalogService::rebuild_tree()
 {
-  return AssetCatalogTreeItemIterator(children_.begin(), children_.end());
+  this->catalog_tree_ = read_into_tree();
 }
 
-void AssetCatalogService::rebuild_tree()
+AssetCatalogTreeItem::AssetCatalogTreeItem(StringRef name, const AssetCatalogTreeItem *parent)
+    : name_(name), parent_(parent)
+>>>>>>> temp-asset-browser-catalogs
 {
-  this->catalog_tree_ = read_into_tree();
+  return AssetCatalogTreeItemIterator(children_.begin(), children_.end());
 }
 
 StringRef AssetCatalogTreeItem::get_catalog_id() const
@@ -470,29 +507,28 @@ bool operator!=(AssetCatalogTreeItemIterator a, AssetCatalogTreeItemIterator b)
 
 void AssetCatalogTree::insert_item(AssetCatalog &catalog)
 {
+  /* #fs::path adds useful behavior to the path. Remember that on Windows it uses "\" as
+   * separator! For catalogs it should always be "/". Use #fs::path::generic_string if needed. */
+  fs::path catalog_path = catalog.path;
+
   const AssetCatalogTreeItem *parent = nullptr;
   AssetCatalogTreeItem::ChildMap *insert_to_map = &children_;
 
-  BLI_assert_msg(!ELEM(catalog.path[0], '/', '\\'),
-                 "Malformed catalog path: Path should be formatted like a relative path");
-
-  const char *next_slash_ptr;
-  /* Looks more complicated than it is, this just iterates over path components. E.g.
-   * "just/some/path" iterates over "just", then "some" then "path". */
-  for (const char *name_begin = catalog.path.data(); name_begin && name_begin[0];
-       /* Jump to one after the next slash if there is any. */
-       name_begin = next_slash_ptr ? next_slash_ptr + 1 : nullptr) {
-    next_slash_ptr = BLI_path_slash_find(name_begin);
-
-    /* Note that this won't be null terminated. */
-    StringRef component_name = next_slash_ptr ?
-                                   StringRef(name_begin, next_slash_ptr - name_begin) :
-                                   /* Last component in the path. */
-                                   name_begin;
+  BLI_assert_msg(catalog_path.is_relative() && !catalog_path.has_root_path(),
+                 "Malformed catalog path: Path should be a relative path, with no root-name or "
+                 "root-directory as defined by std::filesystem::path.");
+  for (const fs::path &component : catalog_path) {
+    std::string component_name = component.string();
 
     /* Insert new tree element - if no matching one is there yet! */
     auto [item, was_inserted] = insert_to_map->emplace(
-        component_name, AssetCatalogTreeItem(component_name, catalog.catalog_id, parent));
+        component_name,
+        AssetCatalogTreeItem(
+            component_name,
+            /* TODO There may be components that don't relate to an actual
+               catalog, i.e. there's no catalog ID to set. This should be changed. */
+            catalog_path.filename() == component_name ? catalog.catalog_id : "",
+            parent));
 
     /* Walk further into the path (no matter if a new item was created or not). */
     parent = &item->second;
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 212477cb9f4..0474c2b81cb 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -1680,7 +1680,6 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area)
       sseq->scopes.vector_ibuf = NULL;
       sseq->scopes.histogram_ibuf = NULL;
       memset(&sseq->runtime, 0x0, sizeof(sseq->runtime));
-
     }
     else if (sl->spacetype == SPACE_PROPERTIES) {
       SpaceProperties *sbuts = (SpaceProperties *)sl;
@@ -1733,7 +1732,6 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area)
       }
       if (sfile->asset_params) {
         sfile->asset_params->base_params.rename_id = NULL;
-        BLO_read_data_address(reader, &sfile->asset_params->catalog_id);
       }
     }
     else if (sl->spacetype == SPACE_ACTION) {
diff --git a/source/blender/editors/space_file/asset_catalog_tree_view.cc b/source/blender/editors/space_file/asset_catalog_tree_view.cc
index a93511c9ee1..f5fa94c1cba 100644
--- a/source/blender/editors/space_file/asset_catalog_tree_view.cc
+++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc
@@ -79,7 +79,7 @@ class AssetCatalogTreeViewItem : public uiBasicTreeViewItem {
     const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>(
         get_tree_view());
     tree_view.params_->asset_catalog_visibility = FILE_SHOW_ASSETS_FROM_CATALOG;
-    tree_view.params_->catalog_id = catalog_.get_catalog_id().data();
+    tree_view.params_->catalog_id = catalog_.get_catalog_id();
     WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, NULL);
   }
 
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index f91566c35e0..cda4ccdd786 100644
--- a/source/blender/editors

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list