Blender V4.3
asset_library_reference_enum.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
14#include "BLI_listbase.h"
15
16#include "BKE_preferences.h"
17
18#include "DNA_userdef_types.h"
19
20#include "UI_resources.hh"
21
22#include "RNA_define.hh"
23#include "RNA_enum_types.hh"
24
25#include "ED_asset_library.hh"
26
27namespace blender::ed::asset {
28
30{
31 /* Simple case: Predefined repository, just set the value. */
32 if (library->type < ASSET_LIBRARY_CUSTOM) {
33 return library->type;
34 }
35
36 /* Note that the path isn't checked for validity here. If an invalid library path is used, the
37 * Asset Browser can give a nice hint on what's wrong. */
39 &U, library->custom_library_index);
40 if (user_library) {
42 }
43
45}
46
48{
50
51 /* Simple case: Predefined repository, just set the value. */
52 if (value < ASSET_LIBRARY_CUSTOM) {
53 library.type = value;
54 library.custom_library_index = -1;
56 return library;
57 }
58
60 &U, value - ASSET_LIBRARY_CUSTOM);
61
62 /* Note that there is no check if the path exists here. If an invalid library path is used, the
63 * Asset Browser can give a nice hint on what's wrong. */
64 if (!user_library) {
65 library.type = ASSET_LIBRARY_ALL;
66 library.custom_library_index = -1;
67 }
68 else {
69 const bool is_valid = (user_library->name[0] && user_library->dirpath[0]);
70 if (is_valid) {
72 library.type = ASSET_LIBRARY_CUSTOM;
73 }
74 }
75 return library;
76}
77
78const EnumPropertyItem *library_reference_to_rna_enum_itemf(const bool include_generated)
79{
80 EnumPropertyItem *item = nullptr;
81 int totitem = 0;
82
83 if (include_generated) {
84 /* Add predefined libraries that are generated and not simple directories that can be written
85 * to. */
88 RNA_enum_item_add_separator(&item, &totitem);
89
94 }
95
96 /* Add separator if needed. */
97 if (!BLI_listbase_is_empty(&U.asset_libraries)) {
98 RNA_enum_item_add_separator(&item, &totitem);
99 }
100
101 int i;
102 LISTBASE_FOREACH_INDEX (bUserAssetLibrary *, user_library, &U.asset_libraries, i) {
103 /* Note that the path itself isn't checked for validity here. If an invalid library path is
104 * used, the Asset Browser can give a nice hint on what's wrong. */
105 const bool is_valid = (user_library->name[0] && user_library->dirpath[0]);
106 if (!is_valid) {
107 continue;
108 }
109
110 AssetLibraryReference library_reference;
111 library_reference.type = ASSET_LIBRARY_CUSTOM;
112 library_reference.custom_library_index = i;
113
114 const int enum_value = library_reference_to_enum_value(&library_reference);
115 /* Use library path as description, it's a nice hint for users. */
116 EnumPropertyItem tmp = {
117 enum_value, user_library->name, ICON_NONE, user_library->name, user_library->dirpath};
118 RNA_enum_item_add(&item, &totitem, &tmp);
119 }
120
121 RNA_enum_item_end(&item, &totitem);
122 return item;
123}
124
125} // namespace blender::ed::asset
struct bUserAssetLibrary * BKE_preferences_asset_library_find_index(const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
#define BLI_assert(a)
Definition BLI_assert.h:50
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
#define ELEM(...)
@ ASSET_LIBRARY_CUSTOM
@ ASSET_LIBRARY_ESSENTIALS
@ ASSET_LIBRARY_LOCAL
@ ASSET_LIBRARY_ALL
unsigned int U
Definition btGjkEpa3.h:78
int library_reference_to_enum_value(const AssetLibraryReference *library)
AssetLibraryReference library_reference_from_enum_value(int value)
const EnumPropertyItem * library_reference_to_rna_enum_itemf(bool include_generated)
const EnumPropertyItem rna_enum_asset_library_type_items[]
Definition rna_asset.cc:22
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
void RNA_enum_item_add_separator(EnumPropertyItem **items, int *totitem)
const char * name
Definition RNA_types.hh:510