Assets: Remove appended asset when dropping operation fails

When dropping an asset somewhere, it is appended and then a drop operation is
called to actually add it to the scene based on current context. If this drop
operation fails, the appended data-block is now still in the .blend. The user
may not notice and not expect this.
Instead idea is to rollback any changes done by dropping code if the operation
fails, namely removing the appended data-block again.

Adds a new `cancel()` callback which is called if the drop operator returns
`OPERATOR_CANCELLED` to drop-boxes and a generic function to deal with assets
on drop failure.

Also removes the `free_id_on_error` property of the `NODE_OT_add_group`
operator, which was used as ad-hoc solution to get this same behavior.
This commit is contained in:
2021-02-16 15:24:22 +01:00
parent 500bc99da5
commit e81fca1ed3
15 changed files with 121 additions and 49 deletions

View File

@@ -323,9 +323,6 @@ static bNodeTree *node_add_group_get_and_poll_group_node_tree(Main *bmain,
return NULL;
}
if ((node_group->type != ntree->type) || !nodeGroupPoll(ntree, node_group)) {
if (RNA_boolean_get(op->ptr, "free_id_on_error")) {
BKE_id_delete(bmain, node_group);
}
return NULL;
}
@@ -389,8 +386,6 @@ static int node_add_group_invoke(bContext *C, wmOperator *op, const wmEvent *eve
void NODE_OT_add_group(wmOperatorType *ot)
{
PropertyRNA *prop;
/* identifiers */
ot->name = "Add Node Group";
ot->description = "Add an existing node group to the current node editor";
@@ -405,13 +400,6 @@ void NODE_OT_add_group(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
RNA_def_string(ot->srna, "name", "Mask", MAX_ID_NAME - 2, "Name", "Data-block name to assign");
prop = RNA_def_boolean(
ot->srna,
"free_id_on_error",
false,
"Free Group on Error",
"Free the named node group data-block if it could not be added to the tree");
RNA_def_property_flag(prop, PROP_HIDDEN);
}
/* ****************** Add File Node Operator ******************* */