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
This commit is contained in:
2021-02-15 19:35:24 +01:00
parent 45852532d5
commit 604e61d81d
5 changed files with 133 additions and 5 deletions

View File

@@ -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);
}