Skip to content

Commit d4c45d6

Browse files
committed
NodeRemoved/ConnectionRemoved is now NodeRemoving/ConnectionRemoving and added new NodeRemoving/ConnectionRemoving that's called at the end of removing a node/connection (thanks Zyxil for the suggestion)
1 parent 24d3a04 commit d4c45d6

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

Graph/GraphControl.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ public GraphControl()
4545

4646
public event EventHandler<ElementEventArgs> FocusChanged;
4747
public event EventHandler<AcceptNodeEventArgs> NodeAdded;
48-
public event EventHandler<AcceptNodeEventArgs> NodeRemoved;
48+
public event EventHandler<AcceptNodeEventArgs> NodeRemoving;
49+
public event EventHandler<NodeEventArgs> NodeRemoved;
4950
public event EventHandler<AcceptNodeConnectionEventArgs> ConnectionAdded;
50-
public event EventHandler<AcceptNodeConnectionEventArgs> ConnectionRemoved;
51+
public event EventHandler<AcceptNodeConnectionEventArgs> ConnectionRemoving;
52+
public event EventHandler<NodeConnectionEventArgs> ConnectionRemoved;
5153

5254

5355
#region DragElement
@@ -477,10 +479,10 @@ public void RemoveNode(Node node)
477479
if (node == null)
478480
return;
479481

480-
if (NodeRemoved != null)
482+
if (NodeRemoving != null)
481483
{
482484
var eventArgs = new AcceptNodeEventArgs(node);
483-
NodeRemoved(this, eventArgs);
485+
NodeRemoving(this, eventArgs);
484486
if (eventArgs.Cancel)
485487
return;
486488
}
@@ -490,6 +492,9 @@ public void RemoveNode(Node node)
490492
DisconnectAll(node);
491493
graphNodes.Remove(node);
492494
this.Invalidate();
495+
496+
if (NodeRemoved != null)
497+
NodeRemoved(this, new NodeEventArgs(node));
493498
}
494499
#endregion
495500

@@ -504,10 +509,10 @@ public bool RemoveNodes(IEnumerable<Node> nodes)
504509
{
505510
if (node == null)
506511
continue;
507-
if (NodeRemoved != null)
512+
if (NodeRemoving != null)
508513
{
509514
var eventArgs = new AcceptNodeEventArgs(node);
510-
NodeRemoved(this, eventArgs);
515+
NodeRemoving(this, eventArgs);
511516
if (eventArgs.Cancel)
512517
continue;
513518
}
@@ -518,6 +523,9 @@ public bool RemoveNodes(IEnumerable<Node> nodes)
518523
DisconnectAll(node);
519524
graphNodes.Remove(node);
520525
modified = true;
526+
527+
if (NodeRemoved != null)
528+
NodeRemoved(this, new NodeEventArgs(node));
521529
}
522530
if (modified)
523531
this.Invalidate();
@@ -581,10 +589,10 @@ public bool Disconnect(NodeConnection connection)
581589
if (connection == null)
582590
return false;
583591

584-
if (ConnectionRemoved != null)
592+
if (ConnectionRemoving != null)
585593
{
586594
var eventArgs = new AcceptNodeConnectionEventArgs(connection);
587-
ConnectionRemoved(this, eventArgs);
595+
ConnectionRemoving(this, eventArgs);
588596
if (eventArgs.Cancel)
589597
return false;
590598
}
@@ -603,6 +611,9 @@ public bool Disconnect(NodeConnection connection)
603611
connection.From = null;
604612
connection.To = null;
605613

614+
if (ConnectionRemoved != null)
615+
ConnectionRemoved(this, new NodeConnectionEventArgs(from, to, connection));
616+
606617
this.Invalidate();
607618
return true;
608619
}

Graph/NodeConnection.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ namespace Graph
3232
{
3333
public sealed class NodeConnectionEventArgs : EventArgs
3434
{
35-
public NodeConnectionEventArgs(NodeConnection connection) { Connection = connection; }
35+
public NodeConnectionEventArgs(NodeConnection connection) { Connection = connection; From = connection.From; To = connection.To; }
36+
public NodeConnectionEventArgs(NodeConnector from, NodeConnector to, NodeConnection connection) { Connection = connection; From = from; To = to; }
37+
public NodeConnector From { get; set; }
38+
public NodeConnector To { get; set; }
3639
public NodeConnection Connection { get; private set; }
3740
}
3841

GraphExample/ExampleForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public ExampleForm()
6161
graphControl.AddNode(textureNode);
6262

6363
graphControl.ConnectionAdded += new EventHandler<AcceptNodeConnectionEventArgs>(OnConnectionAdded);
64-
graphControl.ConnectionRemoved += new EventHandler<AcceptNodeConnectionEventArgs>(OnConnectionRemoved);
64+
graphControl.ConnectionRemoving += new EventHandler<AcceptNodeConnectionEventArgs>(OnConnectionRemoved);
6565

6666
graphControl.Connect(colorItem, check1Item);
6767
}

0 commit comments

Comments
 (0)