Cleanup: Return early in node link operator, remove useless comments

This commit is contained in:
Hans Goudey 2022-12-16 13:22:34 -06:00
parent 1b24140d9f
commit 8fa664fd33
1 changed files with 21 additions and 28 deletions

View File

@ -94,8 +94,10 @@ static bNodeLink *create_drag_link(bNode &node, bNodeSocket &sock)
return oplink;
}
static void pick_link(
wmOperator &op, bNodeLinkDrag &nldrag, SpaceNode &snode, bNode *node, bNodeLink &link_to_pick)
static void pick_link(bNodeLinkDrag &nldrag,
SpaceNode &snode,
bNode *node,
bNodeLink &link_to_pick)
{
clear_picking_highlight(&snode.edittree->links);
@ -163,7 +165,7 @@ static void pick_input_link_by_link_intersect(const bContext &C,
ED_area_tag_redraw(CTX_wm_area(&C));
if (!node_find_indicated_socket(*snode, &node, &socket, cursor, SOCK_IN)) {
pick_link(op, nldrag, *snode, node, *link_to_pick);
pick_link(nldrag, *snode, node, *link_to_pick);
}
}
}
@ -1014,8 +1016,6 @@ static void node_link_find_socket(bContext &C, wmOperator &op, const float2 &cur
}
}
/* Loop that adds a node-link, called by function below. */
/* in_out = starting socket */
static int node_link_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
bNodeLinkDrag *nldrag = (bNodeLinkDrag *)op->customdata;
@ -1084,7 +1084,7 @@ static int node_link_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
static std::unique_ptr<bNodeLinkDrag> node_link_init(SpaceNode &snode,
float2 cursor,
const float2 cursor,
const bool detach)
{
/* output indicated? */
@ -1115,7 +1115,6 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(SpaceNode &snode,
else {
/* dragged links are fixed on output side */
nldrag->in_out = SOCK_OUT;
/* create a new link */
nldrag->links.append(create_drag_link(*node, *sock));
}
return nldrag;
@ -1158,7 +1157,6 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(SpaceNode &snode,
else {
/* dragged links are fixed on input side */
nldrag->in_out = SOCK_IN;
/* create a new link */
nldrag->links.append(create_drag_link(*node, *sock));
}
return nldrag;
@ -1185,23 +1183,22 @@ static int node_link_invoke(bContext *C, wmOperator *op, const wmEvent *event)
ED_preview_kill_jobs(CTX_wm_manager(C), &bmain);
std::unique_ptr<bNodeLinkDrag> nldrag = node_link_init(snode, cursor, detach);
if (nldrag) {
UI_view2d_edge_pan_operator_init(C, &nldrag->pan_data, op);
/* Add "+" icon when the link is dragged in empty space. */
if (should_create_drag_link_search_menu(*snode.edittree, *nldrag)) {
draw_draglink_tooltip_activate(*CTX_wm_region(C), *nldrag);
}
snode.runtime->linkdrag = std::move(nldrag);
op->customdata = snode.runtime->linkdrag.get();
/* add modal handler */
WM_event_add_modal_handler(C, op);
return OPERATOR_RUNNING_MODAL;
if (!nldrag) {
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
}
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
UI_view2d_edge_pan_operator_init(C, &nldrag->pan_data, op);
/* Add "+" icon when the link is dragged in empty space. */
if (should_create_drag_link_search_menu(*snode.edittree, *nldrag)) {
draw_draglink_tooltip_activate(*CTX_wm_region(C), *nldrag);
}
snode.runtime->linkdrag = std::move(nldrag);
op->customdata = snode.runtime->linkdrag.get();
WM_event_add_modal_handler(C, op);
return OPERATOR_RUNNING_MODAL;
}
static void node_link_cancel(bContext *C, wmOperator *op)
@ -1233,8 +1230,6 @@ void NODE_OT_link(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
PropertyRNA *prop;
RNA_def_boolean(ot->srna, "detach", false, "Detach", "Detach and redirect existing links");
RNA_def_float_array(ot->srna,
"drag_start",
@ -1246,8 +1241,6 @@ void NODE_OT_link(wmOperatorType *ot)
"The position of the mouse cursor at the start of the operation",
-UI_PRECISION_FLOAT_MAX,
UI_PRECISION_FLOAT_MAX);
RNA_def_property_flag(prop, PROP_HIDDEN);
RNA_def_property_flag(prop, PROP_HIDDEN);
UI_view2d_edge_pan_operator_properties_ex(ot,
NODE_EDGE_PAN_INSIDE_PAD,