Refactor: Move node_socket_translation_context to bke

This commit is contained in:
Damien Picard
2025-09-24 00:19:32 +02:00
committed by Bastien Montagne
parent 9bd249746a
commit d064e17d7c
3 changed files with 24 additions and 19 deletions

View File

@@ -1137,6 +1137,11 @@ StringRefNull node_socket_label(const bNodeSocket &sock);
*/
std::optional<StringRefNull> node_socket_short_label(const bNodeSocket &sock);
/**
* Get node socket translation context if it is set.
*/
const char *node_socket_translation_context(const bNodeSocket &sock);
NodeColorTag node_color_tag(const bNode &node);
/**

View File

@@ -4975,6 +4975,24 @@ StringRefNull node_socket_label(const bNodeSocket &sock)
return (sock.label[0] != '\0') ? sock.label : sock.name;
}
const char *node_socket_translation_context(const bNodeSocket &sock)
{
/* The node is not explicitly defined. */
if (sock.runtime->declaration == nullptr) {
return nullptr;
}
const std::optional<std::string> &translation_context =
sock.runtime->declaration->translation_context;
/* Default context. */
if (!translation_context.has_value()) {
return nullptr;
}
return translation_context->c_str();
}
NodeColorTag node_color_tag(const bNode &node)
{
const int nclass = node.typeinfo->ui_class == nullptr ? node.typeinfo->nclass :

View File

@@ -248,24 +248,6 @@ void tag_update_id(ID *id)
}
}
static const char *node_socket_get_translation_context(const bNodeSocket &socket)
{
/* The node is not explicitly defined. */
if (socket.runtime->declaration == nullptr) {
return nullptr;
}
const std::optional<std::string> &translation_context =
socket.runtime->declaration->translation_context;
/* Default context. */
if (!translation_context.has_value()) {
return nullptr;
}
return translation_context->c_str();
}
static void node_socket_add_tooltip_in_node_editor(const bNodeSocket &sock, uiLayout &layout);
/** Return true when \a a should be behind \a b and false otherwise. */
@@ -473,7 +455,7 @@ const char *node_socket_get_label(const bNodeSocket *socket, const char *panel_l
/* Get the short label if possible. This is used when grouping sockets under panels,
* to avoid redundancy in the label. */
const std::optional<StringRefNull> socket_short_label = bke::node_socket_short_label(*socket);
const char *socket_translation_context = node_socket_get_translation_context(*socket);
const char *socket_translation_context = bke::node_socket_translation_context(*socket);
if (socket_short_label.has_value()) {
return CTX_IFACE_(socket_translation_context, socket_short_label->c_str());