diff options
Diffstat (limited to 'source/blender/editors/space_node/node_select.c')
-rw-r--r-- | source/blender/editors/space_node/node_select.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c index 62537fb713f..b9d87fd56de 100644 --- a/source/blender/editors/space_node/node_select.c +++ b/source/blender/editors/space_node/node_select.c @@ -32,6 +32,7 @@ #include "BLI_rect.h" #include "BLI_lasso.h" +#include "BLI_string.h" #include "BLI_utildefines.h" #include "BKE_context.h" @@ -48,6 +49,8 @@ #include "WM_api.h" #include "WM_types.h" +#include "UI_interface.h" +#include "UI_resources.h" #include "UI_view2d.h" #include "MEM_guardedalloc.h" @@ -853,3 +856,104 @@ void NODE_OT_select_same_type_step(wmOperatorType *ot) } +/* *************** find a node **************** */ + +/* generic search invoke */ +static void node_find_cb(const struct bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; + + for (node = snode->edittree->nodes.first; node; node = node->next) { + + if (BLI_strcasestr(node->name, str) || BLI_strcasestr(node->label, str)) { + char name[256]; + + if (node->label[0]) + BLI_snprintf(name, 256, "%s (%s)", node->name, node->label); + else + BLI_strncpy(name, node->name, 256); + if (0 == uiSearchItemAdd(items, name, node, 0)) + break; + } + } +} + +static void node_find_call_cb(struct bContext *C, void *UNUSED(arg1), void *arg2) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNode *active = arg2; + + if (active) { + ARegion *ar = CTX_wm_region(C); + node_select_single(C, active); + + /* is note outside view? */ + if (active->totr.xmax < ar->v2d.cur.xmin || active->totr.xmin > ar->v2d.cur.xmax || + active->totr.ymax < ar->v2d.cur.ymin || active->totr.ymin > ar->v2d.cur.ymax) + { + space_node_view_flag(C, snode, ar, NODE_SELECT); + } + + } +} + +static uiBlock *node_find_menu(bContext *C, ARegion *ar, void *arg_op) +{ + static char search[256] = ""; + wmEvent event; + wmWindow *win = CTX_wm_window(C); + uiBlock *block; + uiBut *but; + wmOperator *op = (wmOperator *)arg_op; + + block = uiBeginBlock(C, ar, "_popup", UI_EMBOSS); + uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU); + + but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 10, 9 * UI_UNIT_X, UI_UNIT_Y, 0, 0, ""); + uiButSetSearchFunc(but, node_find_cb, op->type, node_find_call_cb, NULL); + + /* fake button, it holds space for search items */ + uiDefBut(block, LABEL, 0, "", 10, 10 - uiSearchBoxHeight(), uiSearchBoxWidth(), uiSearchBoxHeight(), NULL, 0, 0, 0, 0, NULL); + + uiPopupBoundsBlock(block, 6, 0, -UI_UNIT_Y); /* move it downwards, mouse over button */ + uiEndBlock(C, block); + + // uiButActiveOnly(C, ar, block, but); XXX using this here makes Blender hang - investigate + event = *(win->eventstate); /* XXX huh huh? make api call */ + event.type = EVT_BUT_OPEN; + event.val = KM_PRESS; + event.customdata = but; + event.customdatafree = FALSE; + wm_event_add(win, &event); + + return block; +} + + +static int node_find_node_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) +{ + uiPupBlock(C, node_find_menu, op); + return OPERATOR_CANCELLED; +} + + +void NODE_OT_find_node(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Find Node"; + ot->description = "Search for named node and allow to select and activate it"; + ot->idname = "NODE_OT_find_node"; + + /* api callbacks */ + ot->invoke = node_find_node_invoke; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_boolean(ot->srna, "prev", 0, "Previous", ""); + +} + + |