Blender V5.3
interface_template_project_asset_libraries_tree.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
10#include "BKE_global.hh"
11#include "BKE_screen.hh"
12
13#include "BLI_listbase.hh"
14#include "BLI_string.hh"
15#include "BLI_string_utf8.hh"
16
17#include "BLT_translation.hh"
18
19#include "RNA_access.hh"
20#include "RNA_prototypes.hh"
21
23
24namespace blender::ui {
25
27{
29
30 for (bUserAssetLibrary &user_library : U.asset_libraries) {
31 if (!(user_library.flag & ASSET_LIBRARY_PROJECT_DEFINED)) {
32 /* Only include project defined libraries. */
33 continue;
34 }
35
36 if (!USER_EXPERIMENTAL_TEST(&U, use_remote_asset_libraries) &&
38 {
39 continue;
40 }
42 }
43
44 return result;
45}
46
48
49 /* Use the constructor from AssetLibraryListItemCommon. */
51
52 void build_row(ui::Layout &row) override
53 {
54 const bool is_remote_library = library.user_library &&
56
58 row.label(label_, is_remote_library ? ICON_INTERNET : ICON_DISK_DRIVE);
59 }
60 else {
61 row.label(label_, ICON_NONE);
62
63 ui::Layout &sub = row.row(true);
64 /* Draw text grayed out. */
65 sub.active_set(false);
67 sub.label(IFACE_("Built-In"), ICON_NONE);
68 }
69
71 is_remote_library && !library.user_library->remote_url[0])
72 {
73 row.label("", ICON_ERROR);
74 }
75
76 if (library.user_library && !is_remote_library && library.user_library->invalid_uuid) {
77 row.label("", ICON_ERROR);
78 row.enabled_set(false);
79 }
80
83 nullptr, RNA_UserAssetLibrary, library.user_library);
84 row.prop(&ptr,
85 "enabled",
87 "",
88 (library.user_library->flag & ASSET_LIBRARY_DISABLED) ? ICON_CHECKBOX_DEHLT :
89 ICON_CHECKBOX_HLT);
90 }
91 }
92
93 void on_activate(bContext &C) override
94 {
96 if (!project) {
97 return;
98 }
99 project->active_asset_library_index = index_in_list;
100 }
101 std::optional<bool> should_be_active() const override
102 {
104 if (!project) {
105 return std::nullopt;
106 }
107 return project->active_asset_library_index == index_in_list;
108 }
109};
110
112{
114 if (!project) {
115 /* The category is always shown, but there is nothing to edit without a project. */
116 return;
117 }
118
120 int active_asset_library = project->active_asset_library_index;
121
122 ui::Layout &row = layout->row(false);
123
125 *C, row, libraries, "Project Asset Library Preferences");
126
127 ui::Layout &col = row.column(true);
128 if (USER_EXPERIMENTAL_TEST(&U, use_remote_asset_libraries)) {
129 col.op_menu_enum(C, "project.asset_library_add", "type", "", ICON_ADD);
130 }
131 else {
132 PointerRNA props = col.op("project.asset_library_add", "", ICON_ADD);
133 RNA_enum_set(&props, "type", ASSET_LIBRARY_LOCAL);
134 }
135
136 ui::Layout &sub = col.row(true);
137 const bool active_idx_in_range = active_asset_library >= 0 &&
138 active_asset_library < libraries.size();
139 const bool is_custom_library = active_idx_in_range &&
140 libraries[active_asset_library].type == ASSET_LIBRARY_CUSTOM;
141 sub.enabled_set(active_idx_in_range && is_custom_library);
142 PointerRNA props = sub.op("project.asset_library_remove", "", ICON_REMOVE);
143 RNA_int_set(&props, "index", active_asset_library);
144
145 if (!active_idx_in_range) {
146 return;
147 }
148
149 layout->separator();
150
151 draw_active_library_settings(C, *layout, libraries[active_asset_library]);
152}
153
154} // namespace blender::ui
#define G_MAIN
#define IFACE_(msgid)
#define USER_EXPERIMENTAL_TEST(userdef, member)
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
void template_project_asset_libraries_tree(Layout *layout, bContext *C)
static Vector< AnyAssetLibraryDefinition > project_ui_asset_libraries()
UserDef U
Definition blender.cc:58
void draw_library_list(const bContext &C, ui::Layout &layout, Vector< AnyAssetLibraryDefinition > &libraries, StringRef view_description)
@ ASSET_LIBRARY_PROJECT_DEFINED
@ ASSET_LIBRARY_DISABLED
@ ASSET_LIBRARY_USE_REMOTE_URL
bke::BlenderProject * BKE_blender_project_get(const Main *bmain)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
@ ASSET_LIBRARY_CUSTOM
@ ASSET_LIBRARY_LOCAL
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void draw_active_library_settings(const bContext *C, ui::Layout &layout, const AnyAssetLibraryDefinition &library)
Main * CTX_data_main(const bContext *C)
AssetLibraryListItemCommon(const AnyAssetLibraryDefinition &library, const int index_in_list)
void enabled_set(bool enabled)
void alignment_set(LayoutAlign alignment)
PointerRNA op_menu_enum(const bContext *C, wmOperatorType *ot, StringRefNull propname, std::optional< StringRefNull > name, int icon)
void label(StringRef name, int icon)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
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 active_set(bool active)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
Layout & row(bool align)
AssetLibraryListItemCommon(const AnyAssetLibraryDefinition &library, const int index_in_list)