diff options
author | Julian Eisel <julian@blender.org> | 2021-02-15 21:35:24 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-02-15 21:39:46 +0300 |
commit | 604e61d81d6326e665de6ec81dca2619e2cd5dbc (patch) | |
tree | 5d6bd388a0c6ed77e58dd3887bd77b0af7b93397 /source/blender/editors/space_node/space_node.c | |
parent | 45852532d55be4fc7ab4f0f3be00983a78c69dea (diff) |
UI/Nodes: Adding node groups via drag & drop (e.g. from Asset Browser)
Adds `NODE_OT_add_group` operator to add a node group from a given name, and
uses that to register a node editor drop-box.
When dropping a node-group asset, the ID will be appended. This is what we do
for other ID assets too.
Should the node group insertion fail (e.g. the group is not compatible with the
current tree, as checked by the poll), the appended data-block is removed.
Differential Revision: https://developer.blender.org/D10405
Reviewed by: Jacques Lucke
Diffstat (limited to 'source/blender/editors/space_node/space_node.c')
-rw-r--r-- | source/blender/editors/space_node/space_node.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index 74aff6a290b..6e6b0a584cf 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -659,6 +659,14 @@ static void node_main_region_draw(const bContext *C, ARegion *region) /* ************* dropboxes ************* */ +static bool node_group_drop_poll(bContext *UNUSED(C), + wmDrag *drag, + const wmEvent *UNUSED(event), + const char **UNUSED(r_tooltip)) +{ + return WM_drag_is_ID_type(drag, ID_NT); +} + static bool node_ima_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event), @@ -679,6 +687,17 @@ static bool node_mask_drop_poll(bContext *UNUSED(C), return WM_drag_is_ID_type(drag, ID_MSK); } +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) { ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0); @@ -705,6 +724,7 @@ 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); } |