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
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_asset_library.h4
-rw-r--r--source/blender/blenkernel/BKE_asset_library.hh8
-rw-r--r--source/blender/blenkernel/intern/asset_library.cc26
-rw-r--r--source/blender/makesrna/intern/rna_asset.c20
4 files changed, 58 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_asset_library.h b/source/blender/blenkernel/BKE_asset_library.h
index 3ddfbb1415e..70949f40430 100644
--- a/source/blender/blenkernel/BKE_asset_library.h
+++ b/source/blender/blenkernel/BKE_asset_library.h
@@ -69,6 +69,10 @@ bool BKE_asset_library_find_suitable_root_path_from_path(
bool BKE_asset_library_find_suitable_root_path_from_main(
const struct Main *bmain, char r_library_path[768 /* FILE_MAXDIR */]);
+/** Look up the asset's catalog and copy its simple name into #asset_data. */
+void BKE_asset_library_refresh_catalog_simplename(struct AssetLibrary *asset_library,
+ struct AssetMetaData *asset_data);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_asset_library.hh b/source/blender/blenkernel/BKE_asset_library.hh
index 1dc02f7aa9b..419df2a1061 100644
--- a/source/blender/blenkernel/BKE_asset_library.hh
+++ b/source/blender/blenkernel/BKE_asset_library.hh
@@ -38,6 +38,14 @@ struct AssetLibrary {
void load(StringRefNull library_root_directory);
+ /**
+ * Update `catalog_simple_name` by looking up the asset's catalog by its ID.
+ *
+ * No-op if the catalog cannot be found. This could be the kind of "the
+ * catalog definition file is corrupt/lost" scenario that the simple name is
+ * meant to help recover from. */
+ void refresh_catalog_simplename(struct AssetMetaData *asset_data);
+
void on_save_handler_register();
void on_save_handler_unregister();
diff --git a/source/blender/blenkernel/intern/asset_library.cc b/source/blender/blenkernel/intern/asset_library.cc
index 27e66ee5725..5956a4af0cb 100644
--- a/source/blender/blenkernel/intern/asset_library.cc
+++ b/source/blender/blenkernel/intern/asset_library.cc
@@ -18,6 +18,7 @@
* \ingroup bke
*/
+#include "BKE_asset_catalog.hh"
#include "BKE_asset_library.hh"
#include "BKE_callbacks.h"
#include "BKE_main.h"
@@ -25,6 +26,7 @@
#include "BLI_path_util.h"
+#include "DNA_asset_types.h"
#include "DNA_userdef_types.h"
#include "MEM_guardedalloc.h"
@@ -91,6 +93,13 @@ blender::bke::AssetCatalogTree *BKE_asset_library_get_catalog_tree(const ::Asset
return catalog_service->get_catalog_tree();
}
+void BKE_asset_library_refresh_catalog_simplename(struct AssetLibrary *asset_library,
+ struct AssetMetaData *asset_data)
+{
+ blender::bke::AssetLibrary *lib = reinterpret_cast<blender::bke::AssetLibrary *>(asset_library);
+ lib->refresh_catalog_simplename(asset_data);
+}
+
namespace blender::bke {
void AssetLibrary::load(StringRefNull library_root_directory)
@@ -138,4 +147,21 @@ void AssetLibrary::on_save_post(struct Main *main,
this->catalog_service->write_to_disk_on_blendfile_save(main->name);
}
+void AssetLibrary::refresh_catalog_simplename(struct AssetMetaData *asset_data)
+{
+ if (BLI_uuid_is_nil(asset_data->catalog_id)) {
+ asset_data->catalog_simple_name[0] = '\0';
+ return;
+ }
+
+ const AssetCatalog *catalog = this->catalog_service->find_catalog(asset_data->catalog_id);
+ if (catalog == nullptr) {
+ /* No-op if the catalog cannot be found. This could be the kind of "the catalog definition file
+ * is corrupt/lost" scenario that the simple name is meant to help recover from. */
+ return;
+ }
+
+ STRNCPY(asset_data->catalog_simple_name, catalog->simple_name.c_str());
+}
+
} // namespace blender::bke
diff --git a/source/blender/makesrna/intern/rna_asset.c b/source/blender/makesrna/intern/rna_asset.c
index 80824df1bc8..979d0882dd5 100644
--- a/source/blender/makesrna/intern/rna_asset.c
+++ b/source/blender/makesrna/intern/rna_asset.c
@@ -215,6 +215,25 @@ static void rna_AssetMetaData_catalog_id_set(PointerRNA *ptr, const char *value)
BKE_asset_metadata_catalog_id_set(asset_data, new_uuid, "");
}
+void rna_AssetMetaData_catalog_id_update(struct bContext *C, struct PointerRNA *ptr)
+{
+ SpaceFile *sfile = CTX_wm_space_file(C);
+ if (sfile == NULL) {
+ /* Until there is a proper Asset Service available, it's only possible to get the asset library
+ * from within the asset browser context. */
+ return;
+ }
+
+ AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile);
+ if (asset_library == NULL) {
+ /* The SpaceFile may not be an asset browser but a regular file browser. */
+ return;
+ }
+
+ AssetMetaData *asset_data = ptr->data;
+ BKE_asset_library_refresh_catalog_simplename(asset_library, asset_data);
+}
+
static PointerRNA rna_AssetHandle_file_data_get(PointerRNA *ptr)
{
AssetHandle *asset_handle = ptr->data;
@@ -356,6 +375,7 @@ static void rna_def_asset_data(BlenderRNA *brna)
"rna_AssetMetaData_catalog_id_length",
"rna_AssetMetaData_catalog_id_set");
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_AssetMetaData_catalog_id_update");
RNA_def_property_ui_text(prop,
"Catalog UUID",
"Identifier for the asset's catalog, used by Blender to look up the "