forked from bartvdbraak/blender
Node editing feature:
New operator "Find Node". Opens search menu, and allows to find a node based on name or label. On selecting name, menu selects/activates the node and moves the view to it. Shortcut: ALT+F Menu: Node editor, "Select"
This commit is contained in:
parent
03c337f61c
commit
c35dec60b5
@ -151,10 +151,17 @@ class NODE_MT_select(Menu):
|
||||
layout.operator("node.select_all", text="Inverse").action = 'INVERT'
|
||||
layout.operator("node.select_linked_from")
|
||||
layout.operator("node.select_linked_to")
|
||||
|
||||
layout.separator()
|
||||
|
||||
layout.operator("node.select_same_type")
|
||||
layout.operator("node.select_same_type_step").prev = True
|
||||
layout.operator("node.select_same_type_step").prev = False
|
||||
|
||||
layout.separator()
|
||||
|
||||
layout.operator("node.find_node")
|
||||
|
||||
|
||||
class NODE_MT_node(Menu):
|
||||
bl_label = "Node"
|
||||
|
@ -122,6 +122,7 @@ void NODE_OT_select_border(struct wmOperatorType *ot);
|
||||
void NODE_OT_select_lasso(struct wmOperatorType *ot);
|
||||
void NODE_OT_select_same_type(struct wmOperatorType *ot);
|
||||
void NODE_OT_select_same_type_step(struct wmOperatorType *ot);
|
||||
void NODE_OT_find_node(struct wmOperatorType *ot);
|
||||
|
||||
/* node_view.c */
|
||||
int space_node_view_flag(struct bContext *C, SpaceNode *snode, ARegion *ar, const int node_flag);
|
||||
|
@ -60,6 +60,8 @@ void node_operatortypes(void)
|
||||
WM_operatortype_append(NODE_OT_select_same_type);
|
||||
WM_operatortype_append(NODE_OT_select_same_type_step);
|
||||
|
||||
WM_operatortype_append(NODE_OT_find_node);
|
||||
|
||||
WM_operatortype_append(NODE_OT_view_all);
|
||||
WM_operatortype_append(NODE_OT_view_selected);
|
||||
|
||||
@ -323,6 +325,8 @@ void node_keymap(struct wmKeyConfig *keyconf)
|
||||
kmi = WM_keymap_add_item(keymap, "NODE_OT_select_same_type_step", LEFTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
|
||||
RNA_boolean_set(kmi->ptr, "prev", TRUE);
|
||||
|
||||
WM_keymap_add_item(keymap, "NODE_OT_find_node", FKEY, KM_PRESS, KM_ALT, 0);
|
||||
|
||||
node_group_operators(keymap, "ShaderNodeGroup");
|
||||
node_group_operators(keymap, "CompositorNodeGroup");
|
||||
node_group_operators(keymap, "TextureNodeGroup");
|
||||
|
@ -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", "");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user