Blender V5.3
custom_asset_library_list_ui.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_global.hh"
10#include "BKE_preferences.h"
11
12#include "BLT_translation.hh"
13
14#include "DNA_screen_types.h"
15
17#include "UI_tree_view.hh"
18
19#include "RNA_access.hh"
20#include "RNA_enum_types.hh"
21#include "RNA_prototypes.hh"
22
24
25namespace blender {
26
28 const int index_in_list)
30{
31
33 label_ = library.user_library->name;
34 }
36 label_ = library.extension_repo->name;
37 }
38 else {
39 const char *name_cstr;
40 RNA_enum_name_gettexted(
41 rna_enum_asset_library_type_items, library.type, BLT_I18NCONTEXT_DEFAULT, &name_cstr);
42 label_ = name_cstr;
43 }
44}
45
47{
48 return library.user_library != nullptr;
49}
50
52{
54 nullptr, RNA_UserAssetLibrary, library.user_library);
55 PropertyRNA *prop = RNA_struct_find_property(&ptr, "name");
56 RNA_property_string_set(&ptr, prop, new_name.c_str());
57 RNA_property_update(&const_cast<bContext &>(C), &ptr, prop);
58 return true;
59}
60
62 ui::Layout &layout,
64{
66 PointerRNA prefs_ptr = RNA_pointer_create_discrete(nullptr, RNA_PreferencesAssetLibraries, &U);
67
68 ui::Layout &row = layout.row(false);
69 row.active_set((G.f & G_FLAG_INTERNET_ALLOW) != 0);
70 row.prop(&prefs_ptr,
71 "use_online_essentials",
73 IFACE_("Include Online Essentials"),
74 ICON_NONE);
75 }
76
77 if (library.user_library) {
79 nullptr, RNA_UserAssetLibrary, library.user_library);
80
81 if (library.user_library->flag & ASSET_LIBRARY_USE_REMOTE_URL) {
82 if (USER_EXPERIMENTAL_TEST(&U, use_remote_asset_libraries)) {
83 ui::Layout &row = layout.row(false);
84 row.red_alert_set(!library.user_library->remote_url[0]);
85 /* The URL is defined by the extension. */
86 row.enabled_set(!library.user_library->extension_id[0]);
87 row.prop(&library_ptr,
88 RNA_struct_find_property(&library_ptr, "remote_url"),
90 0,
92 "",
93 ICON_INTERNET,
94 IFACE_("Repository URL"));
95 }
96 layout.prop(&library_ptr, "import_method", UI_ITEM_NONE, IFACE_("Import Method"), ICON_NONE);
97
98 /* Disable auth token for project remote libraries until we have figured out what to do with
99 * them. */
100 if (library.user_library->flag & ASSET_LIBRARY_PROJECT_DEFINED) {
101 return;
102 }
103
104 if (ui::Layout *panel = layout.panel(C, "advanced", true, IFACE_("Advanced"))) {
105 panel->use_property_split_set(true);
106
108 &U, library.user_library);
110
111 {
112 ui::Layout &row = panel->row(false);
114 row.label(IFACE_("Defined by the extension repository"), ICON_STATUS_INFO);
115 }
116
117 ui::Layout &col = panel->column(true, IFACE_("Authentication"));
118
119 /* The repository defines the token for its libraries, show it read-only. */
120 PointerRNA repo_ptr = RNA_pointer_create_discrete(nullptr, RNA_UserExtensionRepo, repo);
121 col.enabled_set(false);
122 col.prop(&repo_ptr, "use_access_token", UI_ITEM_NONE, std::nullopt, ICON_NONE);
124 col.prop(&repo_ptr,
125 RNA_struct_find_property(&repo_ptr, "access_token"),
127 0,
129 IFACE_("Secret"),
130 repo->access_token ? ICON_LOCKED : ICON_UNLOCKED,
131 std::nullopt);
132 }
133 }
134 else {
135 ui::Layout &col = panel->column(true, IFACE_("Authentication"));
136
137 col.prop(&library_ptr, "use_auth_token", UI_ITEM_NONE, std::nullopt, ICON_NONE);
138
139 if (library.user_library->flag & ASSET_LIBRARY_USE_AUTH_TOKEN) {
140 if (!library.user_library->auth_token) {
141 col.red_alert_set(true);
142 }
143 col.prop(&library_ptr,
144 RNA_struct_find_property(&library_ptr, "auth_token"),
146 0,
148 IFACE_("Secret"),
149 library.user_library->auth_token ? ICON_LOCKED : ICON_UNLOCKED,
150 std::nullopt);
151 }
152 }
153 }
154 }
155 else {
156 if (library.user_library->invalid_uuid) {
157 ui::Layout &row = layout.row(false);
158 row.red_alert_set(true);
159 row.label_multiline(
160 "Asset Library has an invalid identifier (invalid UUID). Either manually edit the "
161 "configuration file or regenerate it here.",
162 ICON_ERROR,
164 7);
165 ui::Layout &row2 = row.row(false);
167 row2.red_alert_set(false);
168 row2.button("Regenerate UUID", 0, [library](blender::bContext & /*C*/) {
169 MEM_delete(library.user_library->invalid_uuid);
170 library.user_library->invalid_uuid = nullptr;
171 });
172 }
173
174 layout.prop(&library_ptr, "path", UI_ITEM_NONE, std::nullopt, ICON_NONE);
175 layout.prop(&library_ptr, "import_method", UI_ITEM_NONE, IFACE_("Import Method"), ICON_NONE);
176 layout.prop(&library_ptr, "use_relative_path", UI_ITEM_NONE, std::nullopt, ICON_NONE);
177 }
178 }
179}
180
181} // namespace blender
#define IFACE_(msgid)
#define USER_EXPERIMENTAL_TEST(userdef, member)
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define RNA_NO_INDEX
constexpr const char * c_str() const
BMesh Iterators.
UserDef U
Definition blender.cc:58
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
@ ASSET_LIBRARY_USE_AUTH_TOKEN
@ ASSET_LIBRARY_PROJECT_DEFINED
@ ASSET_LIBRARY_USE_REMOTE_URL
@ ASSET_LIBRARY_ESSENTIALS
Global G
Definition blender.cc:57
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
struct bUserExtensionRepo * BKE_preferences_extension_asset_library_repo_get(const struct UserDef *userdef, const struct bUserAssetLibrary *library) ATTR_NONNULL()
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
@ USER_EXTENSION_REPO_FLAG_USE_ACCESS_TOKEN_ASSET_LIBRARIES
@ USER_EXTENSION_REPO_FLAG_USE_ACCESS_TOKEN
void draw_active_library_settings(const bContext *C, ui::Layout &layout, const AnyAssetLibraryDefinition &library)
@ G_FLAG_INTERNET_ALLOW
bool rename(const bContext &C, StringRefNull new_name) override
AssetLibraryListItemCommon(const AnyAssetLibraryDefinition &library, const int index_in_list)
eUserExtensionRepo_Flag flag
void enabled_set(bool enabled)
void alignment_set(LayoutAlign alignment)
void label_multiline(StringRefNull label, int icon, FontStyleAlign align=UI_STYLE_TEXT_LEFT, int max_lines=0)
void label(StringRef name, int icon)
PanelLayout panel(const bContext *C, StringRef idname, bool default_closed)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void red_alert_set(bool red_alert)
void active_set(bool active)
Layout & column(bool align)
Layout & row(bool align)
Button * button(StringRef name, int icon, std::function< void(bContext &)> func, std::optional< StringRef > tooltip=std::nullopt)