diff options
author | Hans Goudey <h.goudey@me.com> | 2022-09-19 19:57:10 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-09-19 19:57:10 +0300 |
commit | bdb57541475f20ccc4f6e5f8fc075ac424becc19 (patch) | |
tree | b09f860cedf50ccbf6b1234d0b1d414944ff1525 /source/blender/editors/space_node/node_add.cc | |
parent | 862de9187f1b914358c33dd9700e338f0174bbf0 (diff) |
Nodes: Add node group assets to search menus
Currently node group assets are supported, but using them by dragging
from the asset browser is cumbersome. This patch adds all node group
assets from user asset libraries and the current file libraries to the
add node search menu and the link drag search menu.
Node groups added through the search will have their "options" hidden,
meaning the data-block selector is displayed. This helps keep the UI
clean, and the selector shouldn't be necessary anyway.
To make that possible, metadata like the node tree type and its inputs
and outputs has to be saved in the file. This requires re-saving the
files that contain the assets with the patch applied.
The node add search operator is moved from Python to C++ to ease
development and allow more flexibility. It supports a tooltip that
gives the description of assets.
Currently the node groups are added with the asset system's existing
"Append & Reuse" behavior. It's likely that linking should be possible
in the future too, but for now the idea is to use the more foolproof
option that doesn't create dependencies between files.
Because loading assets can potentially take a long time, the search
menu refreshes its items as new assets are loaded. However, changing
the search field is necessary to see the update.
Differential Revision: https://developer.blender.org/D15568
Diffstat (limited to 'source/blender/editors/space_node/node_add.cc')
-rw-r--r-- | source/blender/editors/space_node/node_add.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/editors/space_node/node_add.cc b/source/blender/editors/space_node/node_add.cc index 9949037479e..efe53fd6f14 100644 --- a/source/blender/editors/space_node/node_add.cc +++ b/source/blender/editors/space_node/node_add.cc @@ -810,4 +810,37 @@ void NODE_OT_new_node_tree(wmOperatorType *ot) /** \} */ +/* -------------------------------------------------------------------- */ +/** \name Add Node Search + * \{ */ + +static int node_add_search_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + const ARegion ®ion = *CTX_wm_region(C); + + float2 cursor; + UI_view2d_region_to_view(®ion.v2d, event->mval[0], event->mval[1], &cursor.x, &cursor.y); + + invoke_add_node_search_menu(*C, cursor, RNA_boolean_get(op->ptr, "use_transform")); + + return OPERATOR_FINISHED; +} + +void NODE_OT_add_search(wmOperatorType *ot) +{ + ot->name = "Search and Add Node"; + ot->idname = "NODE_OT_add_search"; + ot->description = "Search for nodes and add one to the active tree"; + + ot->invoke = node_add_search_invoke; + ot->poll = ED_operator_node_editable; + + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_boolean( + ot->srna, "use_transform", true, "Use Transform", "Start moving the node after adding it"); +} + +/** \} */ + } // namespace blender::ed::space_node |