From e81fca1ed38ea447a1023dae3841f8980def28e4 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 16 Feb 2021 15:24:22 +0100 Subject: 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. --- source/blender/editors/space_node/space_node.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'source/blender/editors/space_node/space_node.c') 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 *********** */ -- cgit v1.2.3