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-09-27 16:28:16 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-09-27 19:14:21 +0300
commit10061ee18ae97968bc9e0a7d83a353b077329aca (patch)
tree322d58f7c54bed5a3b642937fff0c0dc793864e0 /source/blender/blenkernel/intern/asset_library.cc
parent90aa0a52568c629e466b6ccc513afadd0144ee1e (diff)
Asset Catalogs: write catalogs to disk when saving the blend file
The Asset Catalog Definition File is now saved whenever the blend file is saved. The location of the CDF depends on where the blend file is saved, and whether previously a CDF was already loaded, according to the following rules. The first matching rule wins: 1. Already loaded a CDF from disk? -> Always write to that file. 2. The directory containing the blend file has a `blender_assets.cats.txt` file? -> Merge with & write to that file. 3. The directory containing the blend file is part of an asset library, as per the user's preferences? -> Merge with & write to `${ASSET_LIBRARY_ROOT}/blender_assets.cats.txt` 4. Create a new file `blender_assets.cats.txt` next to the blend file.
Diffstat (limited to 'source/blender/blenkernel/intern/asset_library.cc')
-rw-r--r--source/blender/blenkernel/intern/asset_library.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/asset_library.cc b/source/blender/blenkernel/intern/asset_library.cc
index 1153e7b29f5..6fed355c41b 100644
--- a/source/blender/blenkernel/intern/asset_library.cc
+++ b/source/blender/blenkernel/intern/asset_library.cc
@@ -19,6 +19,8 @@
*/
#include "BKE_asset_library.hh"
+#include "BKE_callbacks.h"
+#include "BKE_main.h"
#include "MEM_guardedalloc.h"
@@ -31,6 +33,7 @@
struct AssetLibrary *BKE_asset_library_load(const char *library_path)
{
blender::bke::AssetLibrary *lib = new blender::bke::AssetLibrary();
+ lib->on_save_handler_register();
lib->load(library_path);
return reinterpret_cast<struct AssetLibrary *>(lib);
}
@@ -38,6 +41,7 @@ struct AssetLibrary *BKE_asset_library_load(const char *library_path)
void BKE_asset_library_free(struct AssetLibrary *asset_library)
{
blender::bke::AssetLibrary *lib = reinterpret_cast<blender::bke::AssetLibrary *>(asset_library);
+ lib->on_save_handler_unregister();
delete lib;
}
@@ -50,4 +54,42 @@ void AssetLibrary::load(StringRefNull library_root_directory)
this->catalog_service = std::move(catalog_service);
}
+namespace {
+void asset_library_on_save_post(struct Main *main,
+ struct PointerRNA **pointers,
+ const int num_pointers,
+ void *arg)
+{
+ AssetLibrary *asset_lib = static_cast<AssetLibrary *>(arg);
+ asset_lib->on_save_post(main, pointers, num_pointers);
+}
+} // namespace
+
+void AssetLibrary::on_save_handler_register()
+{
+ /* The callback system doesn't own `on_save_callback_store_`. */
+ on_save_callback_store_.alloc = false;
+
+ on_save_callback_store_.func = asset_library_on_save_post;
+ on_save_callback_store_.arg = this;
+
+ BKE_callback_add(&on_save_callback_store_, BKE_CB_EVT_SAVE_POST);
+}
+
+void AssetLibrary::on_save_handler_unregister()
+{
+ BKE_callback_remove(&on_save_callback_store_, BKE_CB_EVT_SAVE_POST);
+}
+
+void AssetLibrary::on_save_post(struct Main *main,
+ struct PointerRNA ** /*pointers*/,
+ const int /*num_pointers*/)
+{
+ if (this->catalog_service) {
+ return;
+ }
+
+ this->catalog_service->write_to_disk_on_blendfile_save(main->name);
+}
+
} // namespace blender::bke