diff options
-rw-r--r-- | source/blender/editors/space_node/link_drag_search.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/editors/space_node/link_drag_search.cc b/source/blender/editors/space_node/link_drag_search.cc index a2dd32b7cc6..45126e9cee0 100644 --- a/source/blender/editors/space_node/link_drag_search.cc +++ b/source/blender/editors/space_node/link_drag_search.cc @@ -105,6 +105,26 @@ static void add_group_input_node_fn(nodes::LinkSearchOpParams ¶ms) nodeAddLink(¶ms.node_tree, &group_input, socket, ¶ms.node, ¶ms.socket); } +static void add_existing_group_input_fn(nodes::LinkSearchOpParams ¶ms, + const bNodeSocket &interface_socket) +{ + const int group_input_index = BLI_findindex(¶ms.node_tree.inputs, &interface_socket); + bNode &group_input = params.add_node("NodeGroupInput"); + + LISTBASE_FOREACH (bNodeSocket *, socket, &group_input.outputs) { + socket->flag |= SOCK_HIDDEN; + } + + bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&group_input.outputs, group_input_index); + if (socket == nullptr) { + /* Adding sockets can fail in some cases. There's no good reason not to be safe here. */ + return; + } + + socket->flag &= ~SOCK_HIDDEN; + nodeAddLink(¶ms.node_tree, &group_input, socket, ¶ms.node, ¶ms.socket); +} + /** * Call the callback to gather compatible socket connections for all node types, and the operations * that will actually make the connections. Also add some custom operations like connecting a group @@ -136,6 +156,22 @@ static void gather_socket_link_operations(bNodeTree &node_tree, if (is_node_group && socket.in_out == SOCK_IN) { search_link_ops.append({IFACE_("Group Input"), add_group_input_node_fn}); + + int weight = -1; + LISTBASE_FOREACH (const bNodeSocket *, interface_socket, &node_tree.inputs) { + eNodeSocketDatatype from = (eNodeSocketDatatype)interface_socket->type; + eNodeSocketDatatype to = (eNodeSocketDatatype)socket.type; + if (node_tree.typeinfo->validate_link && !node_tree.typeinfo->validate_link(from, to)) { + continue; + } + search_link_ops.append( + {std::string(IFACE_("Group Input ")) + UI_MENU_ARROW_SEP + interface_socket->name, + [interface_socket](nodes::LinkSearchOpParams ¶ms) { + add_existing_group_input_fn(params, *interface_socket); + }, + weight}); + weight--; + } } } |