Skip to content

Commit

Permalink
Fixed removing entire nodes when hitting the delete key while an inpu…
Browse files Browse the repository at this point in the history
…t field was focussed.
  • Loading branch information
Doppelkeks committed Jul 10, 2023
1 parent 4988abb commit 9bb0c41
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 53 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed GroupCommentNode Headline cutting off text. Fixes: [#24](https://github.com/Gentlymad-Studios/NewGraph/issues/24)
- Fixed Frame action being triggerd while in an editable VisualElement. Fixes: [#27](https://github.com/Gentlymad-Studios/NewGraph/issues/27)
### Added
- Added customization of the hierarchical layer for GroupCommentNodes. Fixes: [#25](https://github.com/Gentlymad-Studios/NewGraph/issues/25)
- Added customization of the hierarchical layer for GroupCommentNodes. Fixes: [#25](https://github.com/Gentlymad-Studios/NewGraph/issues/25)

## [0.4.0] - 2023-07-10
### Fixed
- Fixed removing entire nodes when hitting the delete key while an input field was focussed.
103 changes: 52 additions & 51 deletions Editor/Controllers/GraphController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,59 +240,60 @@ private void PositionNodesRelative(Vector2 viewPosition, List<NodeModel> nodes)
/// </summary>
/// <param name="data"></param>
public void OnDelete(object data = null) {
bool isDirty = false;

// go over every selected edge...
graphView.ForEachSelectedEdgeDo((edge) => {
isDirty = true;
// get the ouput port, this is where the referenced node sits
PortView outputPort = edge.GetOutputPort() as PortView;
outputPort.Reset();
});

// go over every selected node and build a list of nodes that should be deleted....
List<NodeModel> nodesToRemove = new List<NodeModel>();
graphView.ForEachSelectedNodeDo((node) => {
NodeView scopedNodeView = node as NodeView;
if (scopedNodeView != null) {
nodesToRemove.Add(scopedNodeView.controller.nodeItem);
isDirty = true;
}
});

// if we have nodes marked for deletion...
if (nodesToRemove.Count > 0) {
// tidy up all ports before actual deletion...
graphView.ForEachPortDo((basePort) => {
// we can ignore input ports, so check that we only operate on output ports...
if (basePort.Direction == Direction.Output) {
PortView port = basePort as PortView;
// check that the port actually is not empty...
if (port.boundProperty != null && port.boundProperty.managedReferenceValue != null) {
// loop over the list of nodes that should be removed...
foreach (NodeModel nodeToRemove in nodesToRemove) {
// if the ports actual object value is equal to a node that should be removed...
if (nodeToRemove.nodeData == port.boundProperty.managedReferenceValue) {
// reset / nullify the port value to we don't have invisible nodes in our graph...
port.Reset();
break;
}
}
}
}
});
}
if (graphView.IsFocusedElementNullOrNotBindable) {
bool isDirty = false;

// go over every selected edge...
graphView.ForEachSelectedEdgeDo((edge) => {
isDirty = true;
// get the ouput port, this is where the referenced node sits
PortView outputPort = edge.GetOutputPort() as PortView;
outputPort.Reset();
});

// if we are dirty and objects were changed....
if (isDirty) {
// unbind and reload this graph to avoid serialization issues...
graphView.Unbind();
//graphView.schedule.Execute(() => {
graphData.RemoveNodes(nodesToRemove);
Reload();
//});
}
// go over every selected node and build a list of nodes that should be deleted....
List<NodeModel> nodesToRemove = new List<NodeModel>();
graphView.ForEachSelectedNodeDo((node) => {
NodeView scopedNodeView = node as NodeView;
if (scopedNodeView != null) {
nodesToRemove.Add(scopedNodeView.controller.nodeItem);
isDirty = true;
}
});

// if we have nodes marked for deletion...
if (nodesToRemove.Count > 0) {
// tidy up all ports before actual deletion...
graphView.ForEachPortDo((basePort) => {
// we can ignore input ports, so check that we only operate on output ports...
if (basePort.Direction == Direction.Output) {
PortView port = basePort as PortView;
// check that the port actually is not empty...
if (port.boundProperty != null && port.boundProperty.managedReferenceValue != null) {
// loop over the list of nodes that should be removed...
foreach (NodeModel nodeToRemove in nodesToRemove) {
// if the ports actual object value is equal to a node that should be removed...
if (nodeToRemove.nodeData == port.boundProperty.managedReferenceValue) {
// reset / nullify the port value to we don't have invisible nodes in our graph...
port.Reset();
break;
}
}
}
}
});
}

// if we are dirty and objects were changed....
if (isDirty) {
// unbind and reload this graph to avoid serialization issues...
graphView.Unbind();
//graphView.schedule.Execute(() => {
graphData.RemoveNodes(nodesToRemove);
Reload();
//});
}
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.gentlymad.newgraph",
"version": "0.3.9",
"version": "0.4.0",
"displayName": "NewGraph",
"description": "A general data oriented node graph solution. This is build upon the idea to visualize complex data structures as graph networks without having to modify already established data classes, except adding [Node], [Port] and [SerializeReference] attributes to call classes that should show in the Graph View.",
"unity": "2022.2",
Expand Down

0 comments on commit 9bb0c41

Please sign in to comment.