Blender V5.3
node_bundle_type_search.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_context.hh"
11#include "BKE_node.hh"
12#include "BKE_node_runtime.hh"
13
14#include "BLI_string_utf8.hh"
15
16#include "ED_screen.hh"
17#include "ED_undo.hh"
18
19#include "NOD_bundle_type.hh"
21#include "NOD_sync_sockets.hh"
22
23#include "UI_interface.hh"
25#include "UI_resources.hh"
26#include "UI_string_search.hh"
27
28#include "node_intern.hh"
29
31
34
35 bNode *find_node(const bContext &C) const
36 {
37 SpaceNode *snode = CTX_wm_space_node(&C);
38 if (!snode) {
39 return nullptr;
40 }
41 bNodeTree *node_tree = snode->edittree;
42 if (!node_tree) {
43 return nullptr;
44 }
45 node_tree->ensure_topology_cache();
46 return node_tree->node_by_id(this->node_id);
47 }
48};
49/* This class must not have a destructor, since it is used by buttons and freed with #MEM_freeN. */
50static_assert(std::is_trivially_destructible_v<BundleTypeSocketSearchData>);
51
54{
55 const bNode *node = data.find_node(C);
56 if (!node) {
57 return {};
58 }
59
61}
62
64 const bContext *C, void *arg, const char *str_ptr, ui::SearchItems *items, const bool is_first)
65{
67 return;
68 }
69
70 const StringRef str = str_ptr;
71
72 const auto *data = static_cast<BundleTypeSocketSearchData *>(arg);
74
75 /* Any string is valid, so add the current search string along with the hints. */
76 if (!str.is_empty()) {
77 if (!names.contains(str)) {
78 ui::search_item_add(items, str, nullptr, ICON_NONE, 0, 0);
79 }
80 }
81
82 if (str.is_empty() && !is_first) {
83 /* Allow clearing the text field when the string is empty, but not on the first pass. */
84 ui::search_item_add(items, str, nullptr, ICON_X, 0, 0);
85 }
86
87 const StringRef search_string = is_first ? "" : str;
89 for (const std::string &name : names) {
90 search.add(name, &name);
91 }
92 const Vector<const std::string *> filtered_items = search.query(search_string);
93
94 for (const std::string *item : filtered_items) {
95 if (!ui::search_item_add(items, *item, nullptr, ICON_NONE, 0, 0)) {
96 break;
97 }
98 }
99}
100
101static void bundle_type_string_search_exec(bContext *C, void *data_v, void * /*item_v*/)
102{
104 return;
105 }
106 const auto &data = *static_cast<BundleTypeSocketSearchData *>(data_v);
107 bNode *node = data.find_node(*C);
108 if (!node) {
109 return;
110 }
111 if (!node->is_type("NodeCombineBundle"_ustr)) {
112 return;
113 }
114 const auto &storage = *static_cast<NodeCombineBundle *>(node->storage);
115 if (storage.items_num != 1) {
116 return;
117 }
118 const NodeCombineBundleItem &item = storage.items[0];
119 if (item.socket_type != SOCK_STRING) {
120 return;
121 }
122 if (item.name != nodes::Bundle::type_item_name.ustr()) {
123 return;
124 }
125 nodes::sync_node(*C, *node, nullptr);
127
128 ED_undo_push(C, "Assign Bundle Type");
129}
130
132 const bNode &node,
133 PointerRNA &socket_ptr,
134 ui::Layout &layout,
135 const StringRef placeholder)
136{
137 ui::Block *block = layout.block();
138 ui::Button *but = uiDefIconTextButR(block,
140 ICON_NONE,
141 "",
142 0,
143 0,
144 10 * UI_UNIT_X, /* Dummy value, replaced by layout system. */
145 UI_UNIT_Y,
146 &socket_ptr,
147 "default_value",
148 0,
149 "");
150 ui::button_placeholder_set(but, placeholder);
151
153 data->node_id = node.identifier;
154
158 nullptr,
160 data,
161 true,
162 nullptr,
164 nullptr);
165}
166
167} // namespace blender::ed::space_node
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_UNIT_X
bool contains(const T &value) const
static Vector< std::string > get_all_flat_type_names()
void add(const StringRef str, T *user_data, const int weight=0)
Vector< T * > query(const StringRef query) const
#define str(s)
#define storage(slot, qualifiers)
static void bundle_type_string_search(const bContext *C, void *arg, const char *str_ptr, ui::SearchItems *items, const bool is_first)
static Vector< std::string > get_type_names_from_context(const bContext &C, const BundleTypeSocketSearchData &data)
void node_bundle_type_add_string_search_button(const bContext &, const bNode &node, PointerRNA &socket_ptr, ui::Layout &layout, const StringRef placeholder)
static void bundle_type_string_search_exec(bContext *C, void *data_v, void *)
void sync_node(bContext &C, bNode &node, ReportList *reports)
void button_func_search_set_results_are_suggestions(Button *but, bool value)
void button_func_search_set_sep_string(Button *but, const char *search_sep_string)
void button_placeholder_set(Button *but, StringRef placeholder_text)
bool search_item_add(SearchItems *items, StringRef name, void *poin, int iconid, int64_t but_flag, uint8_t name_prefix_offset)
void button_func_search_set(Button *but, ButtonSearchCreateFn search_create_fn, ButtonSearchUpdateFn search_update_fn, void *arg, bool free_arg, FreeArgFunc search_arg_free_fn, ButtonHandleFunc search_exec_fn, void *active)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BMesh const char void * data
wmWindowManager * CTX_wm_manager(const bContext *C)
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
Definition ed_undo.cc:103
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
SpaceNode * CTX_wm_space_node(const bContext *C)
Main * CTX_data_main(const bContext *C)
signed int int32_t
Definition BKE_text.h:78
bScreen * ED_screen_animation_playing(const wmWindowManager *wm)
#define UI_MENU_ARROW_SEP
struct bNodeTree * edittree