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-18 13:33:53 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-18 15:21:41 +0300
commitf9113c4be836691ba599aab9b2f43e26333f8133 (patch)
tree6fa8fc9c1021538478f173e247d932c63929f15b /source/blender/blenkernel/intern/asset_library.cc
parent1f510376764debe3e91f736aec6b3af70567243f (diff)
Assets: add global `bke::AssetLibraryService` class
Add `blender::bke::AssetLibraryService` class that acts like a blendfile-scoped singleton. It's allocated upon the first call to `BKE_asset_library_load` and destroyed in the LOAD-PRE handler. The `AssetLibraryService` ensures that edits to asset catalogs are not lost when the asset browser editor closes (or even reloads). Instead, the `AssetLibrary` pointers it owns are kept around as long as the blend file is open. Reviewed By: Severin Maniphest Tasks: T92151 Differential Revision: https://developer.blender.org/D12885
Diffstat (limited to 'source/blender/blenkernel/intern/asset_library.cc')
-rw-r--r--source/blender/blenkernel/intern/asset_library.cc29
1 files changed, 19 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/asset_library.cc b/source/blender/blenkernel/intern/asset_library.cc
index 5956a4af0cb..48ace8efea1 100644
--- a/source/blender/blenkernel/intern/asset_library.cc
+++ b/source/blender/blenkernel/intern/asset_library.cc
@@ -31,6 +31,8 @@
#include "MEM_guardedalloc.h"
+#include "asset_library_service.hh"
+
#include <memory>
/**
@@ -39,19 +41,17 @@
*/
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);
+ blender::bke::AssetLibraryService *service = blender::bke::AssetLibraryService::get();
+ blender::bke::AssetLibrary *lib;
+ if (library_path == nullptr || library_path[0] == '\0') {
+ lib = service->get_asset_library_current_file();
+ }
+ else {
+ lib = service->get_asset_library_on_disk(library_path);
+ }
return reinterpret_cast<struct AssetLibrary *>(lib);
}
-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;
-}
-
bool BKE_asset_library_find_suitable_root_path_from_path(const char *input_path,
char *r_library_path)
{
@@ -102,6 +102,13 @@ void BKE_asset_library_refresh_catalog_simplename(struct AssetLibrary *asset_lib
namespace blender::bke {
+AssetLibrary::~AssetLibrary()
+{
+ if (on_save_callback_store_.func) {
+ on_save_handler_unregister();
+ }
+}
+
void AssetLibrary::load(StringRefNull library_root_directory)
{
auto catalog_service = std::make_unique<AssetCatalogService>(library_root_directory);
@@ -134,6 +141,8 @@ void AssetLibrary::on_save_handler_register()
void AssetLibrary::on_save_handler_unregister()
{
BKE_callback_remove(&on_save_callback_store_, BKE_CB_EVT_SAVE_POST);
+ on_save_callback_store_.func = nullptr;
+ on_save_callback_store_.arg = nullptr;
}
void AssetLibrary::on_save_post(struct Main *main,