Commit: e90a2a3f01f97e1a32f869ff63c8d80e15197860
Author: Julian Eisel
Date:   Sun Jan 24 20:57:57 2021 +0100
Branches: master
https://developer.blender.org/rBe90a2a3f01f97e1a32f869ff63c8d80e15197860

Asset Browser: Avoid appending asset data-block when drop operator will fail

For assets, the copy callback of the drop-box would append the asset
data-block. Check if the operator's poll succeeds before calling the copy
callback.
Otherwise the data-block is "secretly" appended, which the user doesn't expect
and won't notice without checking the file data in the Outliner.

For masks I had to extend the poll function, it didn't check context
sufficiently.

===================================================================

M       source/blender/editors/space_node/node_add.c
M       source/blender/windowmanager/intern/wm_event_system.c

===================================================================

diff --git a/source/blender/editors/space_node/node_add.c 
b/source/blender/editors/space_node/node_add.c
index a3e47404c80..131bacbdfef 100644
--- a/source/blender/editors/space_node/node_add.c
+++ b/source/blender/editors/space_node/node_add.c
@@ -312,6 +312,13 @@ void NODE_OT_add_reroute(wmOperatorType *ot)
 
 /* ****************** Add File Node Operator  ******************* */
 
+static bool node_add_file_poll(bContext *C)
+{
+  const SpaceNode *snode = CTX_wm_space_node(C);
+  return ED_operator_node_editable(C) &&
+         ELEM(snode->nodetree->type, NTREE_SHADER, NTREE_TEXTURE, 
NTREE_COMPOSIT);
+}
+
 static int node_add_file_exec(bContext *C, wmOperator *op)
 {
   Main *bmain = CTX_data_main(C);
@@ -396,7 +403,7 @@ void NODE_OT_add_file(wmOperatorType *ot)
   /* callbacks */
   ot->exec = node_add_file_exec;
   ot->invoke = node_add_file_invoke;
-  ot->poll = ED_operator_node_editable;
+  ot->poll = node_add_file_poll;
 
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
diff --git a/source/blender/windowmanager/intern/wm_event_system.c 
b/source/blender/windowmanager/intern/wm_event_system.c
index d08051dd5fb..67372675805 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -2806,8 +2806,10 @@ static int wm_handlers_do_intern(bContext *C, wmEvent 
*event, ListBase *handlers
               LISTBASE_FOREACH (wmDrag *, drag, lb) {
                 const char *tooltip = NULL;
                 if (drop->poll(C, drag, event, &tooltip)) {
-                  /* Optionally copy drag information to operator properties. 
*/
-                  if (drop->copy) {
+                  /* Optionally copy drag information to operator properties. 
Don't call it if the
+                   * operator fails anyway, it might do more than just set 
properties (e.g.
+                   * typically import an asset). */
+                  if (drop->copy && WM_operator_poll_context(C, drop->ot, 
drop->opcontext)) {
                     drop->copy(drag, drop);
                   }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to