Skip to content

Commit 3549074

Browse files
authored
Merge pull request #92 from Jcparkyn/dev
Dev
2 parents 5580a53 + a1dd7f3 commit 3549074

File tree

14 files changed

+149
-181
lines changed

14 files changed

+149
-181
lines changed

Nodexr.Tests/FakeNodeOutput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class FakeNodeOutput : INodeOutput
1919

2020
public string CssColor => throw new NotImplementedException();
2121

22-
public NodeResult CachedOutput => new NodeResult(output, this);
22+
public NodeResult CachedOutput => new NodeResult(output, null);
2323

2424
public FakeNodeOutput(string output) => this.output = output;
2525
}

Nodexr/Nodexr.xml

Lines changed: 0 additions & 96 deletions
This file was deleted.

Nodexr/Shared/Components/OutputDisplay.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<h3 style="margin:6px 10px 7px 7px; display:inline-block;">Output:</h3>
1010

1111
<div class="output-regex-container">
12-
<div class="output-regex">@foreach (var segment in @NodeHandler.CachedOutput)
13-
{<OutputDisplaySegment Segment="segment" />@*This must not be surrounded by whitespace*@}</div>
12+
<div class="output-regex">@foreach (var segment in @NodeHandler.CachedOutput.Contents)
13+
{<OutputDisplaySegment Segment="segment" @key="segment"/>@*This must not be surrounded by whitespace*@}</div>
1414

1515
<button title="Copy to clipboard" class="output-regex output-regex-button" @onclick="CopyTextToClipboard"><i class="far fa-clipboard"></i></button>
1616
<button title="Edit" class="output-regex output-regex-button" @onclick="OnEditButtonClick"><i class="fas fa-pencil-alt"></i></button>
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1-
@inject INodeHandler NodeHandler
1+
@implements IDisposable
2+
@inject INodeHandler NodeHandler
23

3-
<span class="output-segment"
4+
<span class="output-segment @(NodeHandler.IsNodeSelected(Segment.Node) ? "output-segment-selected" : "")"
45
style="color:@(Segment.Node?.CssColor ?? "inherit")"
5-
@onmouseover="@(() => NodeHandler.SelectNode(Segment.Node as INode))"
6+
@onmouseover="@(() => NodeHandler.SelectNode(Segment.Node))"
7+
title="@Segment.Node.Title"
68
>@Segment.Expression</span>
79

810
@code {
911
[Parameter] public RegexSegment Segment { get; set; }
12+
13+
protected override void OnInitialized()
14+
{
15+
Segment.Node.Selected += Refresh;
16+
Segment.Node.Deselected += Refresh;
17+
}
18+
19+
private void Refresh(object sender, EventArgs e)
20+
{
21+
StateHasChanged();
22+
}
23+
24+
public void Dispose()
25+
{
26+
Segment.Node.Selected -= Refresh;
27+
Segment.Node.Deselected -= Refresh;
28+
}
1029
}

Nodexr/Shared/NodeTypes/CharSetNode.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ protected override NodeResultBuilder GetValue()
7070
InputMax.GetValue());
7171

7272
var builder = new NodeResultBuilder();
73-
builder.Append(result + suffix, this);
73+
builder.Append(result, this);
74+
builder.Append(suffix, this);
7475
return builder;
7576
}
7677
}

Nodexr/Shared/NodeTypes/WhitespaceNode.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ protected override NodeResultBuilder GetValue()
7575
InputMin.GetValue(),
7676
InputMax.GetValue());
7777

78-
return new NodeResultBuilder(ValueString() + suffix, this);
78+
var builder = new NodeResultBuilder(ValueString(), this);
79+
builder.Append(suffix, this);
80+
return builder;
7981
}
8082

8183
private string ValueString()

Nodexr/Shared/NodeTypes/WildcardNode.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ protected override NodeResultBuilder GetValue()
127127
(WildcardType.Custom, _) => GetContentsCustom(invert),
128128
_ => ".",
129129
};
130-
return new NodeResultBuilder(contents + suffix, this);
130+
131+
var builder = new NodeResultBuilder(contents, this);
132+
builder.Append(suffix, this);
133+
return builder;
131134
}
132135

133136
private string GetContentsCustom(bool invert)

Nodexr/Shared/Nodes/Node.cs

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,14 @@ public interface INode : IPositionable, INodeOutput
3838
/// Get the height of the node, in pixels. Disabled inputs do not contribute to the height.
3939
/// </summary>
4040
int GetHeight();
41-
42-
/// <summary>
43-
/// Get all of the inputs to the node, including the 'previous' input and the sub-inputs of any InputCollections.
44-
/// InputCollections themselves are not returned.
45-
/// </summary>
46-
IEnumerable<NodeInput> GetAllInputs();
41+
4742
void OnLayoutChanged(object sender, EventArgs e);
48-
bool IsDependentOn(INodeInput childInput);
43+
void OnSelected(EventArgs e);
44+
void OnDeselected(EventArgs e);
4945

5046
event EventHandler LayoutChanged;
47+
event EventHandler Selected;
48+
event EventHandler Deselected;
5149
}
5250

5351
public abstract class Node : INode
@@ -84,30 +82,32 @@ public INodeOutput PreviousNode
8482

8583
public event EventHandler OutputChanged;
8684
public event EventHandler LayoutChanged;
85+
public event EventHandler Selected;
86+
public event EventHandler Deselected;
8787

88-
protected virtual void OnOutputChanged(EventArgs e)
89-
{
90-
OutputChanged?.Invoke(this, e);
91-
}
88+
protected virtual void OnOutputChanged(EventArgs e) => OutputChanged?.Invoke(this, e);
9289

9390
public void OnLayoutChanged(object sender, EventArgs e)
9491
{
9592
CalculateInputsPos();
96-
foreach(var input in GetAllInputs().OfType<InputProcedural>())
93+
foreach(var input in this.GetAllInputs().OfType<InputProcedural>())
9794
{
9895
input.Refresh();
9996
}
10097
LayoutChanged?.Invoke(this, e);
10198
}
10299

100+
public void OnSelected(EventArgs e) => Selected?.Invoke(this, e);
101+
102+
public void OnDeselected(EventArgs e) => Deselected?.Invoke(this, e);
103+
103104
protected void OnInputsChanged(object sender, EventArgs e)
104105
{
105-
var newOutput = GetOutput();
106-
CachedOutput = newOutput;
106+
CachedOutput = GetOutput();
107107
OnOutputChanged(EventArgs.Empty);
108108
}
109109

110-
public Node()
110+
protected Node()
111111
{
112112
var inputProperties = GetType()
113113
.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
@@ -184,43 +184,7 @@ public void CalculateInputsPos()
184184
}
185185
}
186186

187-
/// <inheritdoc/>
188-
public IEnumerable<NodeInput> GetAllInputs()
189-
{
190-
yield return Previous;
191-
foreach(var input in NodeInputs)
192-
{
193-
if(input is InputCollection coll)
194-
{
195-
foreach (var subInput in coll.Inputs)
196-
yield return subInput;
197-
}
198-
else
199-
{
200-
yield return input;
201-
}
202-
}
203-
}
204-
205-
public bool IsDependentOn(INodeInput childInput)
206-
{
207-
return GetAllProceduralInputsRecursive(this).Any(input => input == childInput);
208-
209-
static IEnumerable<InputProcedural> GetAllProceduralInputsRecursive(INode parent)
210-
{
211-
foreach(var input in parent.GetAllInputs().OfType<InputProcedural>())
212-
{
213-
yield return input;
214-
215-
if (input.ConnectedNode is INode childNode)
216-
{
217-
foreach (var input2 in GetAllProceduralInputsRecursive(childNode))
218-
yield return input2;
219-
}
220-
}
221-
}
222-
}
223-
187+
224188
public int GetHeight()
225189
{
226190
const int baseHeight = 28;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Linq;
2+
using System.Collections.Generic;
3+
using Nodexr.Shared.NodeInputs;
4+
5+
namespace Nodexr.Shared.Nodes
6+
{
7+
public static class NodeExtensionMethods
8+
{
9+
/// <summary>
10+
/// Get all of the inputs to the node, including the 'previous' input and the sub-inputs of any InputCollections.
11+
/// InputCollections themselves are not returned.
12+
/// </summary>
13+
public static IEnumerable<NodeInput> GetAllInputs(this INode that)
14+
{
15+
yield return that.Previous;
16+
foreach (var input in that.NodeInputs)
17+
{
18+
if (input is InputCollection coll)
19+
{
20+
foreach (var subInput in coll.Inputs)
21+
yield return subInput;
22+
}
23+
else
24+
{
25+
yield return input;
26+
}
27+
}
28+
}
29+
30+
/// <summary>
31+
/// Checks whether the output of the node is dependent on the value of the given input.
32+
/// Used for finding cyclic dependencies.
33+
/// </summary>
34+
/// <returns>True if there is a dependency, false otherwise</returns>
35+
public static bool IsDependentOn(this INode that, INodeInput childInput)
36+
{
37+
return GetAllProceduralInputsRecursive(that).Any(input => input == childInput);
38+
39+
static IEnumerable<InputProcedural> GetAllProceduralInputsRecursive(INode parent)
40+
{
41+
foreach (var input in parent.GetAllInputs().OfType<InputProcedural>())
42+
{
43+
yield return input;
44+
45+
if (input.ConnectedNode is INode childNode)
46+
{
47+
foreach (var input2 in GetAllProceduralInputsRecursive(childNode))
48+
yield return input2;
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)