This commit is contained in:
@@ -483,6 +483,28 @@
|
|||||||
</nodify:Node>
|
</nodify:Node>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
|
<DataTemplate DataType="{x:Type local:StringConcatOperationViewModel}">
|
||||||
|
<nodify:Node Header="{Binding Title}"
|
||||||
|
Content="{Binding}"
|
||||||
|
Input="{Binding Input}"
|
||||||
|
Output="{Binding Output}">
|
||||||
|
<nodify:Node.ContentTemplate>
|
||||||
|
<DataTemplate DataType="{x:Type local:StringConcatOperationViewModel}">
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Button Style="{StaticResource IconButton}"
|
||||||
|
Content="{StaticResource PlusIcon}"
|
||||||
|
FocusVisualStyle="{StaticResource {x:Static SystemParameters.FocusVisualStyleKey}}"
|
||||||
|
Command="{Binding AddInputCommand}" />
|
||||||
|
<Button Style="{StaticResource IconButton}"
|
||||||
|
Content="{StaticResource RemoveKeyIcon}"
|
||||||
|
FocusVisualStyle="{StaticResource {x:Static SystemParameters.FocusVisualStyleKey}}"
|
||||||
|
Command="{Binding RemoveInputCommand}" />
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</nodify:Node.ContentTemplate>
|
||||||
|
</nodify:Node>
|
||||||
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="{x:Type local:APIOperationViewModel}">
|
<DataTemplate DataType="{x:Type local:APIOperationViewModel}">
|
||||||
<nodify:Node Header="{Binding Title}"
|
<nodify:Node Header="{Binding Title}"
|
||||||
Content="{Binding}"
|
Content="{Binding}"
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace Nodify.Calculator.NodeHandlers
|
|||||||
// Register all handlers — order matters for CanCreate/CanRestore matching.
|
// Register all handlers — order matters for CanCreate/CanRestore matching.
|
||||||
// More specific handlers first (e.g. TakeHandler before generic SystemHandler).
|
// More specific handlers first (e.g. TakeHandler before generic SystemHandler).
|
||||||
_handlers.Add(new KnotHandler());
|
_handlers.Add(new KnotHandler());
|
||||||
|
_handlers.Add(new StringConcatHandler());
|
||||||
_handlers.Add(new FunctionHandler());
|
_handlers.Add(new FunctionHandler());
|
||||||
_handlers.Add(new AuthHandler());
|
_handlers.Add(new AuthHandler());
|
||||||
_handlers.Add(new TakeHandler());
|
_handlers.Add(new TakeHandler());
|
||||||
@@ -79,6 +80,7 @@ namespace Nodify.Calculator.NodeHandlers
|
|||||||
return vm switch
|
return vm switch
|
||||||
{
|
{
|
||||||
KnotOperationViewModel => _handlers.OfType<KnotHandler>().FirstOrDefault(),
|
KnotOperationViewModel => _handlers.OfType<KnotHandler>().FirstOrDefault(),
|
||||||
|
StringConcatOperationViewModel => _handlers.OfType<StringConcatHandler>().FirstOrDefault(),
|
||||||
FunctionOperationViewModel => _handlers.OfType<FunctionHandler>().FirstOrDefault(),
|
FunctionOperationViewModel => _handlers.OfType<FunctionHandler>().FirstOrDefault(),
|
||||||
AuthOperationViewModel => _handlers.OfType<AuthHandler>().FirstOrDefault(),
|
AuthOperationViewModel => _handlers.OfType<AuthHandler>().FirstOrDefault(),
|
||||||
TakeOperationViewModel => _handlers.OfType<TakeHandler>().FirstOrDefault(),
|
TakeOperationViewModel => _handlers.OfType<TakeHandler>().FirstOrDefault(),
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
using Nodify.Calculator.Models;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Nodify.Calculator.NodeHandlers
|
||||||
|
{
|
||||||
|
public class StringConcatHandler : INodeHandler
|
||||||
|
{
|
||||||
|
public string NodeTypeKey => "System";
|
||||||
|
|
||||||
|
public bool CanCreate(OperationInfoViewModel info)
|
||||||
|
=> info.Type == OperationType.System && info.sysOp == SystemOperations.STRING_CONCAT;
|
||||||
|
|
||||||
|
public bool CanRestore(NodeData data)
|
||||||
|
=> data.NodeType == "System" && data.SystemOp == nameof(SystemOperations.STRING_CONCAT);
|
||||||
|
|
||||||
|
public OperationViewModel Create(OperationInfoViewModel info)
|
||||||
|
{
|
||||||
|
var strColor = ConnectorViewModel.GetColorForType("string");
|
||||||
|
var op = new StringConcatOperationViewModel();
|
||||||
|
|
||||||
|
// Default two string inputs
|
||||||
|
op.Input.Add(new ConnectorViewModel { Title = "Str 1", Shape = ConnectorShape.Circle, ConnectorColor = strColor, DataType = "string" });
|
||||||
|
op.Input.Add(new ConnectorViewModel { Title = "Str 2", Shape = ConnectorShape.Circle, ConnectorColor = strColor, DataType = "string" });
|
||||||
|
|
||||||
|
// Single string output
|
||||||
|
op.Output.Add(new ConnectorViewModel
|
||||||
|
{
|
||||||
|
Title = "Result",
|
||||||
|
IsInput = false,
|
||||||
|
Shape = ConnectorShape.Circle,
|
||||||
|
ConnectorColor = strColor,
|
||||||
|
DataType = "string"
|
||||||
|
});
|
||||||
|
|
||||||
|
return op;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationViewModel Restore(NodeData data)
|
||||||
|
{
|
||||||
|
var strColor = ConnectorViewModel.GetColorForType("string");
|
||||||
|
var op = new StringConcatOperationViewModel();
|
||||||
|
|
||||||
|
// Restore inputs from saved connectors
|
||||||
|
foreach (var ic in data.InputConnectors)
|
||||||
|
op.Input.Add(NodeHandlerRegistry.DeserializeConnector(ic, true));
|
||||||
|
|
||||||
|
// Restore output
|
||||||
|
foreach (var oc in data.OutputConnectors)
|
||||||
|
op.Output.Add(NodeHandlerRegistry.DeserializeConnector(oc, false));
|
||||||
|
|
||||||
|
op.Title = data.Title;
|
||||||
|
return op;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Save(OperationViewModel vm, NodeData data)
|
||||||
|
{
|
||||||
|
data.NodeType = "System";
|
||||||
|
data.SystemOp = nameof(SystemOperations.STRING_CONCAT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -136,6 +136,14 @@ namespace Nodify.Calculator
|
|||||||
assertNode.Input.Add("Actual");
|
assertNode.Input.Add("Actual");
|
||||||
assertNode.Input.Add("Expected");
|
assertNode.Input.Add("Expected");
|
||||||
|
|
||||||
|
var stringConcatNode = new OperationInfoViewModel()
|
||||||
|
{
|
||||||
|
Title = "String Concat",
|
||||||
|
Type = OperationType.System,
|
||||||
|
sysOp = SystemOperations.STRING_CONCAT,
|
||||||
|
IsFlowNode = false
|
||||||
|
};
|
||||||
|
|
||||||
systemNodes.Add(authNode);
|
systemNodes.Add(authNode);
|
||||||
systemNodes.Add(copynode);
|
systemNodes.Add(copynode);
|
||||||
systemNodes.Add(debugNode);
|
systemNodes.Add(debugNode);
|
||||||
@@ -148,6 +156,7 @@ namespace Nodify.Calculator
|
|||||||
systemNodes.Add(takeNode);
|
systemNodes.Add(takeNode);
|
||||||
systemNodes.Add(forEachNode);
|
systemNodes.Add(forEachNode);
|
||||||
systemNodes.Add(assertNode);
|
systemNodes.Add(assertNode);
|
||||||
|
systemNodes.Add(stringConcatNode);
|
||||||
return systemNodes;
|
return systemNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
32
Examples/Nodify.Calculator/StringConcatOperationViewModel.cs
Normal file
32
Examples/Nodify.Calculator/StringConcatOperationViewModel.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace Nodify.Calculator
|
||||||
|
{
|
||||||
|
public class StringConcatOperationViewModel : SystemOperationViewModel
|
||||||
|
{
|
||||||
|
private const uint DefaultMinInput = 2;
|
||||||
|
|
||||||
|
public INodifyCommand AddInputCommand { get; }
|
||||||
|
public INodifyCommand RemoveInputCommand { get; }
|
||||||
|
|
||||||
|
public StringConcatOperationViewModel()
|
||||||
|
{
|
||||||
|
Title = "String Concat";
|
||||||
|
SystemOperationType = SystemOperations.STRING_CONCAT;
|
||||||
|
|
||||||
|
AddInputCommand = new RequeryCommand(
|
||||||
|
() => Input.Add(new ConnectorViewModel
|
||||||
|
{
|
||||||
|
Title = $"Str {Input.Count + 1}",
|
||||||
|
Shape = ConnectorShape.Circle,
|
||||||
|
ConnectorColor = ConnectorViewModel.GetColorForType("string"),
|
||||||
|
DataType = "string"
|
||||||
|
}),
|
||||||
|
() => true);
|
||||||
|
|
||||||
|
RemoveInputCommand = new RequeryCommand(
|
||||||
|
() => Input.RemoveAt(Input.Count - 1),
|
||||||
|
() => Input.Count > DefaultMinInput);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,8 @@ namespace Nodify.Calculator
|
|||||||
NEW_OBJECT,
|
NEW_OBJECT,
|
||||||
FOREACH,
|
FOREACH,
|
||||||
ASSERT,
|
ASSERT,
|
||||||
KNOT
|
KNOT,
|
||||||
|
STRING_CONCAT
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SystemOperationViewModel : OperationViewModel
|
public class SystemOperationViewModel : OperationViewModel
|
||||||
|
|||||||
Reference in New Issue
Block a user