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-02-16 17:24:22 +0300
committerJulian Eisel <julian@blender.org>2021-02-16 17:34:32 +0300
commite81fca1ed38ea447a1023dae3841f8980def28e4 (patch)
treed0d07de23c839fa147850fdc728d512eb17a6141 /source/blender/editors/space_node
parent500bc99da5dbcdf7c728833326fc29babaf529e0 (diff)
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.
Diffstat (limited to 'source/blender/editors/space_node')
-rw-r--r--source/blender/editors/space_node/node_add.c12
-rw-r--r--source/blender/editors/space_node/space_node.c22
2 files changed, 15 insertions, 19 deletions
diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c
index 74fa5cdeb9d..699e5c1d165 100644
--- a/source/blender/editors/space_node/node_add.c
+++ b/source/blender/editors/space_node/node_add.c
@@ -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 ******************* */
diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c
index 6e6b0a584cf..289b7d9efa1 100644
--- a/source/blender/editors/space_node/space_node.c
+++ b/source/blender/editors/space_node/space_node.c
@@ -692,10 +692,6 @@ static void node_group_drop_copy(wmDrag *drag, wmDropBox *drop)
ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0);
RNA_string_set(drop->ptr, "name", id->name + 2);
- if (drag->type == WM_DRAG_ASSET) {
- /* ID just appended, so free it when dropping fails. */
- RNA_boolean_set(drop->ptr, "free_id_on_error", true);
- }
}
static void node_id_drop_copy(wmDrag *drag, wmDropBox *drop)
@@ -724,9 +720,21 @@ static void node_dropboxes(void)
{
ListBase *lb = WM_dropboxmap_find("Node Editor", SPACE_NODE, RGN_TYPE_WINDOW);
- WM_dropbox_add(lb, "NODE_OT_add_group", node_group_drop_poll, node_group_drop_copy);
- WM_dropbox_add(lb, "NODE_OT_add_file", node_ima_drop_poll, node_id_path_drop_copy);
- WM_dropbox_add(lb, "NODE_OT_add_mask", node_mask_drop_poll, node_id_drop_copy);
+ WM_dropbox_add(lb,
+ "NODE_OT_add_group",
+ node_group_drop_poll,
+ node_group_drop_copy,
+ WM_drag_free_imported_drag_ID);
+ WM_dropbox_add(lb,
+ "NODE_OT_add_file",
+ node_ima_drop_poll,
+ node_id_path_drop_copy,
+ WM_drag_free_imported_drag_ID);
+ WM_dropbox_add(lb,
+ "NODE_OT_add_mask",
+ node_mask_drop_poll,
+ node_id_drop_copy,
+ WM_drag_free_imported_drag_ID);
}
/* ************* end drop *********** */