Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-04-12 19:43:23 +0300
committerJulian Eisel <julian@blender.org>2021-04-12 19:48:22 +0300
commit2bd9f9d976560c55a15ed297032f7d73c2f101cc (patch)
treed109e1131272c799f16825ce1818aac1e79fe1fc /source/blender/makesrna
parentcbd193261969c9b4e1f14297d5888bad2946600e (diff)
UI/Nodes: Improve feedback when adding node fails (e.g. on drag & drop)
This is especially useful when trying to add a node group instance, e.g. via drag & drop from the Outliner or Asset Browser. Previously this would just silently fail, with no information why. This is a source of confusion, e.g. earlier, it took me a moment to realize I was dragging a node group into itself, which failed of course. Blender should always try to help the user with useful error messages. Adds error messages like: "Nesting a node group inside of itself is not allowed", "Not a compositor node tree", etc. Adds a disabled hint return argument to node and node tree polling functions. On error the hint is reported, or could even be shown in advance (e.g. if checked via an operator poll option). Differential Revision: https://developer.blender.org/D10422 Reviewed by: Jacques Lucke
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c52
1 files changed, 36 insertions, 16 deletions
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index b79381ac26f..1016d31f11b 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -1085,13 +1085,25 @@ static bNode *rna_NodeTree_node_new(bNodeTree *ntree,
return NULL;
}
- if (ntype->poll && !ntype->poll(ntype, ntree)) {
- BKE_reportf(reports,
- RPT_ERROR,
- "Cannot add node of type %s to node tree '%s'",
- type,
- ntree->id.name + 2);
- return NULL;
+ const char *disabled_hint = NULL;
+ if (ntype->poll && !ntype->poll(ntype, ntree, &disabled_hint)) {
+ if (disabled_hint) {
+ BKE_reportf(reports,
+ RPT_ERROR,
+ "Cannot add node of type %s to node tree '%s'\n %s",
+ type,
+ ntree->id.name + 2,
+ disabled_hint);
+ return NULL;
+ }
+ else {
+ BKE_reportf(reports,
+ RPT_ERROR,
+ "Cannot add node of type %s to node tree '%s'",
+ type,
+ ntree->id.name + 2);
+ return NULL;
+ }
}
node = nodeAddNode(C, ntree, type);
@@ -1531,7 +1543,7 @@ char *rna_Node_ImageUser_path(PointerRNA *ptr)
return NULL;
}
-static bool rna_Node_poll(bNodeType *ntype, bNodeTree *ntree)
+static bool rna_Node_poll(bNodeType *ntype, bNodeTree *ntree, const char **UNUSED(r_disabled_hint))
{
extern FunctionRNA rna_Node_poll_func;
@@ -1556,7 +1568,9 @@ static bool rna_Node_poll(bNodeType *ntype, bNodeTree *ntree)
return visible;
}
-static bool rna_Node_poll_instance(bNode *node, bNodeTree *ntree)
+static bool rna_Node_poll_instance(bNode *node,
+ bNodeTree *ntree,
+ const char **UNUSED(disabled_info))
{
extern FunctionRNA rna_Node_poll_instance_func;
@@ -1581,10 +1595,12 @@ static bool rna_Node_poll_instance(bNode *node, bNodeTree *ntree)
return visible;
}
-static bool rna_Node_poll_instance_default(bNode *node, bNodeTree *ntree)
+static bool rna_Node_poll_instance_default(bNode *node,
+ bNodeTree *ntree,
+ const char **disabled_info)
{
/* use the basic poll function */
- return rna_Node_poll(node->typeinfo, ntree);
+ return rna_Node_poll(node->typeinfo, ntree, disabled_info);
}
static void rna_Node_update_reg(bNodeTree *ntree, bNode *node)
@@ -3214,18 +3230,20 @@ static PointerRNA rna_NodeInternal_output_template(StructRNA *srna, int index)
static bool rna_NodeInternal_poll(StructRNA *srna, bNodeTree *ntree)
{
bNodeType *ntype = RNA_struct_blender_type_get(srna);
- return ntype && (!ntype->poll || ntype->poll(ntype, ntree));
+ const char *disabled_hint;
+ return ntype && (!ntype->poll || ntype->poll(ntype, ntree, &disabled_hint));
}
static bool rna_NodeInternal_poll_instance(bNode *node, bNodeTree *ntree)
{
bNodeType *ntype = node->typeinfo;
+ const char *disabled_hint;
if (ntype->poll_instance) {
- return ntype->poll_instance(node, ntree);
+ return ntype->poll_instance(node, ntree, &disabled_hint);
}
else {
/* fall back to basic poll function */
- return !ntype->poll || ntype->poll(ntype, ntree);
+ return !ntype->poll || ntype->poll(ntype, ntree, &disabled_hint);
}
}
@@ -3408,7 +3426,8 @@ static void rna_NodeGroup_node_tree_set(PointerRNA *ptr,
bNode *node = ptr->data;
bNodeTree *ngroup = value.data;
- if (nodeGroupPoll(ntree, ngroup)) {
+ const char *disabled_hint = NULL;
+ if (nodeGroupPoll(ntree, ngroup, &disabled_hint)) {
if (node->id) {
id_us_min(node->id);
}
@@ -3430,7 +3449,8 @@ static bool rna_NodeGroup_node_tree_poll(PointerRNA *ptr, const PointerRNA value
return false;
}
- return nodeGroupPoll(ntree, ngroup);
+ const char *disabled_hint = NULL;
+ return nodeGroupPoll(ntree, ngroup, &disabled_hint);
}
static StructRNA *rna_NodeGroup_interface_typef(PointerRNA *ptr)