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:
authorSybren A. Stüvel <sybren@blender.org>2021-10-12 12:28:16 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-12 12:28:16 +0300
commitad1735f8ede966b7d49423928ad05cca25119949 (patch)
tree27c351114b6f66ef50418445fb35e16c9edbf6e1 /source/blender/blenkernel/intern/asset_catalog.cc
parentac657bee0142f96fcd3fa5d56455658834a19b19 (diff)
Asset Catalogs: recursive deletion of catalogs & children
Recursively delete asset catalogs with `AssetCatalogService:prune_...` functions. This deletes the catalog and all of its children. The old `delete_catalog` function has been renamed to `delete_catalog_by_id()`, and is now a lower-level function (no deletion of children, no rebuilding of the tree). The `prune_catalogs_by_path()` and `prune_catalogs_by_id()` do delete children and do rebuild the catalog tree. Manifest task: T91634
Diffstat (limited to 'source/blender/blenkernel/intern/asset_catalog.cc')
-rw-r--r--source/blender/blenkernel/intern/asset_catalog.cc31
1 files changed, 29 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/asset_catalog.cc b/source/blender/blenkernel/intern/asset_catalog.cc
index ab7d8eafb8b..4531dabf0cf 100644
--- a/source/blender/blenkernel/intern/asset_catalog.cc
+++ b/source/blender/blenkernel/intern/asset_catalog.cc
@@ -112,7 +112,7 @@ AssetCatalogFilter AssetCatalogService::create_catalog_filter(
return AssetCatalogFilter(std::move(matching_catalog_ids));
}
-void AssetCatalogService::delete_catalog(CatalogID catalog_id)
+void AssetCatalogService::delete_catalog_by_id(const CatalogID catalog_id)
{
std::unique_ptr<AssetCatalog> *catalog_uptr_ptr = this->catalogs_.lookup_ptr(catalog_id);
if (catalog_uptr_ptr == nullptr) {
@@ -129,11 +129,38 @@ void AssetCatalogService::delete_catalog(CatalogID catalog_id)
/* The catalog can now be removed from the map without freeing the actual AssetCatalog. */
this->catalogs_.remove(catalog_id);
+}
+
+void AssetCatalogService::prune_catalogs_by_path(const AssetCatalogPath &path)
+{
+ /* Build a collection of catalog IDs to delete. */
+ Set<CatalogID> catalogs_to_delete;
+ for (const auto &catalog_uptr : this->catalogs_.values()) {
+ const AssetCatalog *cat = catalog_uptr.get();
+ if (cat->path.is_contained_in(path)) {
+ catalogs_to_delete.add(cat->catalog_id);
+ }
+ }
+
+ /* Delete the catalogs. */
+ for (const CatalogID cat_id : catalogs_to_delete) {
+ this->delete_catalog_by_id(cat_id);
+ }
this->rebuild_tree();
}
-void AssetCatalogService::update_catalog_path(CatalogID catalog_id,
+void AssetCatalogService::prune_catalogs_by_id(const CatalogID catalog_id)
+{
+ const AssetCatalog *catalog = find_catalog(catalog_id);
+ BLI_assert_msg(catalog, "trying to prune asset catalogs by the path of a non-existent catalog");
+ if (!catalog) {
+ return;
+ }
+ this->prune_catalogs_by_path(catalog->path);
+}
+
+void AssetCatalogService::update_catalog_path(const CatalogID catalog_id,
const AssetCatalogPath &new_catalog_path)
{
AssetCatalog *renamed_cat = this->find_catalog(catalog_id);