[Bf-blender-cvs] [4254810e502] master: Cleanup: Slightly refactor cancelling link drag operator
Hans Goudey
noreply at git.blender.org
Fri Dec 16 21:47:28 CET 2022
Commit: 4254810e5028c6ebd745bb53c4cfa8c97483af8b
Author: Hans Goudey
Date: Fri Dec 16 14:03:49 2022 -0600
Branches: master
https://developer.blender.org/rB4254810e5028c6ebd745bb53c4cfa8c97483af8b
Cleanup: Slightly refactor cancelling link drag operator
Clarify that the dragged links aren't stored in the tree, use a
separate function for cancelling vs. applying the links to the tree.
===================================================================
M source/blender/editors/space_node/node_relationships.cc
===================================================================
diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc
index c4c3924ec6a..360f713e1a7 100644
--- a/source/blender/editors/space_node/node_relationships.cc
+++ b/source/blender/editors/space_node/node_relationships.cc
@@ -894,42 +894,41 @@ static void node_remove_extra_links(SpaceNode &snode, bNodeLink &link)
}
}
-static void node_link_exit(bContext &C, wmOperator &op, const bool apply_links)
+static void add_dragged_links_to_tree(bContext &C, bNodeLinkDrag &nldrag)
{
Main *bmain = CTX_data_main(&C);
ARegion ®ion = *CTX_wm_region(&C);
SpaceNode &snode = *CTX_wm_space_node(&C);
bNodeTree &ntree = *snode.edittree;
- bNodeLinkDrag *nldrag = (bNodeLinkDrag *)op.customdata;
-
- for (bNodeLink *link : nldrag->links) {
- if (apply_links && link->tosock && link->fromsock) {
- /* before actually adding the link,
- * let nodes perform special link insertion handling
- */
- if (link->fromnode->typeinfo->insert_link) {
- link->fromnode->typeinfo->insert_link(&ntree, link->fromnode, link);
- }
- if (link->tonode->typeinfo->insert_link) {
- link->tonode->typeinfo->insert_link(&ntree, link->tonode, link);
- }
- /* add link to the node tree */
- BLI_addtail(&ntree.links, link);
- BKE_ntree_update_tag_link_added(&ntree, link);
+ for (bNodeLink *link : nldrag.links) {
+ if (!link->tosock || !link->fromsock) {
+ MEM_freeN(link);
+ continue;
+ }
- /* we might need to remove a link */
- node_remove_extra_links(snode, *link);
+ /* before actually adding the link,
+ * let nodes perform special link insertion handling
+ */
+ if (link->fromnode->typeinfo->insert_link) {
+ link->fromnode->typeinfo->insert_link(&ntree, link->fromnode, link);
}
- else {
- nodeRemLink(&ntree, link);
+ if (link->tonode->typeinfo->insert_link) {
+ link->tonode->typeinfo->insert_link(&ntree, link->tonode, link);
}
+
+ /* add link to the node tree */
+ BLI_addtail(&ntree.links, link);
+ BKE_ntree_update_tag_link_added(&ntree, link);
+
+ /* we might need to remove a link */
+ node_remove_extra_links(snode, *link);
}
ED_node_tree_propagate_change(&C, bmain, &ntree);
/* Ensure drag-link tool-tip is disabled. */
- draw_draglink_tooltip_deactivate(*CTX_wm_region(&C), *nldrag);
+ draw_draglink_tooltip_deactivate(region, nldrag);
ED_workspace_status_text(&C, nullptr);
ED_region_tag_redraw(®ion);
@@ -938,6 +937,19 @@ static void node_link_exit(bContext &C, wmOperator &op, const bool apply_links)
snode.runtime->linkdrag.reset();
}
+static void node_link_cancel(bContext *C, wmOperator *op)
+{
+ SpaceNode *snode = CTX_wm_space_node(C);
+ bNodeLinkDrag *nldrag = (bNodeLinkDrag *)op->customdata;
+ draw_draglink_tooltip_deactivate(*CTX_wm_region(C), *nldrag);
+ UI_view2d_edge_pan_cancel(C, &nldrag->pan_data);
+ for (bNodeLink *link : nldrag->links) {
+ MEM_freeN(link);
+ }
+ snode->runtime->linkdrag.reset();
+ clear_picking_highlight(&snode->edittree->links);
+}
+
static void node_link_find_socket(bContext &C, wmOperator &op, const float2 &cursor)
{
SpaceNode &snode = *CTX_wm_space_node(&C);
@@ -1061,22 +1073,21 @@ static int node_link_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
}
- /* Finish link. */
- node_link_exit(*C, *op, true);
+ add_dragged_links_to_tree(*C, *nldrag);
return OPERATOR_FINISHED;
}
break;
case RIGHTMOUSE:
case MIDDLEMOUSE: {
if (event->val == KM_RELEASE) {
- node_link_exit(*C, *op, true);
- return OPERATOR_FINISHED;
+ node_link_cancel(C, op);
+ return OPERATOR_CANCELLED;
}
break;
}
case EVT_ESCKEY: {
- node_link_exit(*C, *op, true);
- return OPERATOR_FINISHED;
+ node_link_cancel(C, op);
+ return OPERATOR_CANCELLED;
}
}
@@ -1201,18 +1212,6 @@ static int node_link_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_RUNNING_MODAL;
}
-static void node_link_cancel(bContext *C, wmOperator *op)
-{
- SpaceNode *snode = CTX_wm_space_node(C);
- bNodeLinkDrag *nldrag = (bNodeLinkDrag *)op->customdata;
-
- UI_view2d_edge_pan_cancel(C, &nldrag->pan_data);
-
- snode->runtime->linkdrag.reset();
-
- clear_picking_highlight(&snode->edittree->links);
-}
-
void NODE_OT_link(wmOperatorType *ot)
{
/* identifiers */
More information about the Bf-blender-cvs
mailing list