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:
authorJulian Eisel <julian@blender.org>2021-07-21 20:30:31 +0300
committerJulian Eisel <julian@blender.org>2021-07-21 20:35:39 +0300
commite850c2b06d18e4292110d3fe9cdf5ebc7c281daa (patch)
tree6a29c978067573d2e99049f9056a6cf310650d67 /source/blender/makesrna/intern/rna_asset.c
parent10e28bd27017664064b1fb93f1ed347d6b404ae6 (diff)
Cleanup: Centralize/unify asset library reference from/to enum code
This was an open TODO, I wanted to have code for translating asset library references from and to enum values in a central place, and access that in the same way from both the Asset Browser and the Workspace RNA code. * Adds own file for the related functions. * Adds doxygen comments. * Updates RNA callbacks to properly use these functions. * Let these functions call each other, avoid duplicating logic.
Diffstat (limited to 'source/blender/makesrna/intern/rna_asset.c')
-rw-r--r--source/blender/makesrna/intern/rna_asset.c61
1 files changed, 4 insertions, 57 deletions
diff --git a/source/blender/makesrna/intern/rna_asset.c b/source/blender/makesrna/intern/rna_asset.c
index f9658586f5f..484b7593812 100644
--- a/source/blender/makesrna/intern/rna_asset.c
+++ b/source/blender/makesrna/intern/rna_asset.c
@@ -160,71 +160,18 @@ static PointerRNA rna_AssetHandle_local_id_get(PointerRNA *ptr)
return rna_pointer_inherit_refine(ptr, &RNA_ID, id);
}
-int rna_asset_library_reference_get(const AssetLibraryReference *library)
-{
- return ED_asset_library_reference_to_enum_value(library);
-}
-
-void rna_asset_library_reference_set(AssetLibraryReference *library, int value)
-{
- *library = ED_asset_library_reference_from_enum_value(value);
-}
-
const EnumPropertyItem *rna_asset_library_reference_itemf(bContext *UNUSED(C),
PointerRNA *UNUSED(ptr),
PropertyRNA *UNUSED(prop),
bool *r_free)
{
- const EnumPropertyItem predefined_items[] = {
- /* For the future. */
- // {ASSET_REPO_BUNDLED, "BUNDLED", 0, "Bundled", "Show the default user assets"},
- {ASSET_LIBRARY_LOCAL,
- "LOCAL",
- ICON_BLENDER,
- "Current File",
- "Show the assets currently available in this Blender session"},
- {0, NULL, 0, NULL, NULL},
- };
-
- EnumPropertyItem *item = NULL;
- int totitem = 0;
-
- /* Add separator if needed. */
- if (!BLI_listbase_is_empty(&U.asset_libraries)) {
- const EnumPropertyItem sepr = {0, "", 0, "Custom", NULL};
- RNA_enum_item_add(&item, &totitem, &sepr);
+ const EnumPropertyItem *items = ED_asset_library_reference_to_rna_enum_itemf();
+ if (!items) {
+ *r_free = false;
}
- int i = 0;
- for (bUserAssetLibrary *user_library = U.asset_libraries.first; user_library;
- user_library = user_library->next, i++) {
- /* Note that the path itself isn't checked for validity here. If an invalid library path is
- * used, the Asset Browser can give a nice hint on what's wrong. */
- const bool is_valid = (user_library->name[0] && user_library->path[0]);
- if (!is_valid) {
- continue;
- }
-
- /* Use library path as description, it's a nice hint for users. */
- EnumPropertyItem tmp = {ASSET_LIBRARY_CUSTOM + i,
- user_library->name,
- ICON_NONE,
- user_library->name,
- user_library->path};
- RNA_enum_item_add(&item, &totitem, &tmp);
- }
-
- if (totitem) {
- const EnumPropertyItem sepr = {0, "", 0, "Built-in", NULL};
- RNA_enum_item_add(&item, &totitem, &sepr);
- }
-
- /* Add predefined items. */
- RNA_enum_items_add(&item, &totitem, predefined_items);
-
- RNA_enum_item_end(&item, &totitem);
*r_free = true;
- return item;
+ return items;
}
#else