Added model in the create function dialog and fix issues in the header color
This commit is contained in:
@@ -35,6 +35,15 @@
|
||||
Background="#3E3E42" Foreground="White" RowBackground="#3E3E42"
|
||||
AlternatingRowBackground="#333337" GridLinesVisibility="None"
|
||||
HeadersVisibility="Column" BorderBrush="#555">
|
||||
<DataGrid.ColumnHeaderStyle>
|
||||
<Style TargetType="DataGridColumnHeader">
|
||||
<Setter Property="Background" Value="#2D2D30" />
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
<Setter Property="Padding" Value="6 4" />
|
||||
<Setter Property="BorderBrush" Value="#555" />
|
||||
<Setter Property="BorderThickness" Value="0 0 1 1" />
|
||||
</Style>
|
||||
</DataGrid.ColumnHeaderStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="*">
|
||||
<DataGridTextColumn.ElementStyle>
|
||||
@@ -49,33 +58,22 @@
|
||||
</Style>
|
||||
</DataGridTextColumn.EditingElementStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridComboBoxColumn Header="Type" SelectedItemBinding="{Binding Type}" Width="120">
|
||||
<DataGridComboBoxColumn.ElementStyle>
|
||||
<Style TargetType="ComboBox">
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
<Setter Property="Background" Value="#3E3E42" />
|
||||
</Style>
|
||||
</DataGridComboBoxColumn.ElementStyle>
|
||||
<DataGridComboBoxColumn.EditingElementStyle>
|
||||
<Style TargetType="ComboBox">
|
||||
<Setter Property="Foreground" Value="Black" />
|
||||
<Setter Property="Background" Value="White" />
|
||||
</Style>
|
||||
</DataGridComboBoxColumn.EditingElementStyle>
|
||||
<DataGridComboBoxColumn.ItemsSource>
|
||||
<x:Array Type="sys:String" xmlns:sys="clr-namespace:System;assembly=System.Runtime">
|
||||
<sys:String>string</sys:String>
|
||||
<sys:String>int</sys:String>
|
||||
<sys:String>double</sys:String>
|
||||
<sys:String>bool</sys:String>
|
||||
<sys:String>float</sys:String>
|
||||
<sys:String>decimal</sys:String>
|
||||
<sys:String>long</sys:String>
|
||||
<sys:String>DateTime</sys:String>
|
||||
<sys:String>object</sys:String>
|
||||
</x:Array>
|
||||
</DataGridComboBoxColumn.ItemsSource>
|
||||
</DataGridComboBoxColumn>
|
||||
<DataGridTemplateColumn Header="Type" Width="180">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Type}" Foreground="White" Padding="4 2" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
<DataGridTemplateColumn.CellEditingTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox ItemsSource="{Binding AvailableTypes, RelativeSource={RelativeSource AncestorType=Window}}"
|
||||
SelectedItem="{Binding Type, UpdateSourceTrigger=PropertyChanged}"
|
||||
IsEditable="True"
|
||||
Text="{Binding Type, UpdateSourceTrigger=LostFocus}"
|
||||
Foreground="Black" Background="White" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellEditingTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
@@ -90,6 +88,15 @@
|
||||
Background="#3E3E42" Foreground="White" RowBackground="#3E3E42"
|
||||
AlternatingRowBackground="#333337" GridLinesVisibility="None"
|
||||
HeadersVisibility="Column" BorderBrush="#555">
|
||||
<DataGrid.ColumnHeaderStyle>
|
||||
<Style TargetType="DataGridColumnHeader">
|
||||
<Setter Property="Background" Value="#2D2D30" />
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
<Setter Property="Padding" Value="6 4" />
|
||||
<Setter Property="BorderBrush" Value="#555" />
|
||||
<Setter Property="BorderThickness" Value="0 0 1 1" />
|
||||
</Style>
|
||||
</DataGrid.ColumnHeaderStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="*">
|
||||
<DataGridTextColumn.ElementStyle>
|
||||
@@ -104,33 +111,22 @@
|
||||
</Style>
|
||||
</DataGridTextColumn.EditingElementStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridComboBoxColumn Header="Type" SelectedItemBinding="{Binding Type}" Width="120">
|
||||
<DataGridComboBoxColumn.ElementStyle>
|
||||
<Style TargetType="ComboBox">
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
<Setter Property="Background" Value="#3E3E42" />
|
||||
</Style>
|
||||
</DataGridComboBoxColumn.ElementStyle>
|
||||
<DataGridComboBoxColumn.EditingElementStyle>
|
||||
<Style TargetType="ComboBox">
|
||||
<Setter Property="Foreground" Value="Black" />
|
||||
<Setter Property="Background" Value="White" />
|
||||
</Style>
|
||||
</DataGridComboBoxColumn.EditingElementStyle>
|
||||
<DataGridComboBoxColumn.ItemsSource>
|
||||
<x:Array Type="sys:String" xmlns:sys="clr-namespace:System;assembly=System.Runtime">
|
||||
<sys:String>string</sys:String>
|
||||
<sys:String>int</sys:String>
|
||||
<sys:String>double</sys:String>
|
||||
<sys:String>bool</sys:String>
|
||||
<sys:String>float</sys:String>
|
||||
<sys:String>decimal</sys:String>
|
||||
<sys:String>long</sys:String>
|
||||
<sys:String>DateTime</sys:String>
|
||||
<sys:String>object</sys:String>
|
||||
</x:Array>
|
||||
</DataGridComboBoxColumn.ItemsSource>
|
||||
</DataGridComboBoxColumn>
|
||||
<DataGridTemplateColumn Header="Type" Width="180">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Type}" Foreground="White" Padding="4 2" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
<DataGridTemplateColumn.CellEditingTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox ItemsSource="{Binding AvailableTypes, RelativeSource={RelativeSource AncestorType=Window}}"
|
||||
SelectedItem="{Binding Type, UpdateSourceTrigger=PropertyChanged}"
|
||||
IsEditable="True"
|
||||
Text="{Binding Type, UpdateSourceTrigger=LostFocus}"
|
||||
Foreground="Black" Background="White" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellEditingTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace Nodify.Calculator
|
||||
@@ -17,9 +19,12 @@ namespace Nodify.Calculator
|
||||
|
||||
public string DialogTitle => IsEditMode ? "Edit Function" : "Create New Function";
|
||||
|
||||
/// <summary>All available types for parameter dropdowns (system + custom models + List variants).</summary>
|
||||
public List<string> AvailableTypes { get; } = new List<string>();
|
||||
|
||||
public CreateFunctionDialog()
|
||||
{
|
||||
BuildAvailableTypes();
|
||||
InitializeComponent();
|
||||
InputParamsGrid.ItemsSource = _inputs;
|
||||
OutputParamsGrid.ItemsSource = _outputs;
|
||||
@@ -38,6 +43,46 @@ namespace Nodify.Calculator
|
||||
_outputs.Add(new FunctionParameterInfo { Name = p.Name, Type = p.Type });
|
||||
}
|
||||
|
||||
private void BuildAvailableTypes()
|
||||
{
|
||||
// System / primitive types
|
||||
var systemTypes = new[]
|
||||
{
|
||||
"string", "int", "double", "bool", "float",
|
||||
"decimal", "long", "DateTime", "object"
|
||||
};
|
||||
|
||||
AvailableTypes.AddRange(systemTypes);
|
||||
|
||||
// List<> wrappers for system types
|
||||
foreach (var t in systemTypes)
|
||||
AvailableTypes.Add($"List<{t}>");
|
||||
|
||||
// Custom model types from the project's CustomModels folder
|
||||
try
|
||||
{
|
||||
var customModelDir = Path.Combine(ProjectManager.ProjectDirectory, "CustomModels");
|
||||
if (Directory.Exists(customModelDir))
|
||||
{
|
||||
var modelNames = Directory.GetFiles(customModelDir, "*.cs")
|
||||
.Select(f => Path.GetFileNameWithoutExtension(f))
|
||||
.Where(n => !string.IsNullOrEmpty(n))
|
||||
.OrderBy(n => n)
|
||||
.ToList();
|
||||
|
||||
foreach (var model in modelNames)
|
||||
{
|
||||
AvailableTypes.Add(model);
|
||||
AvailableTypes.Add($"List<{model}>");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// If project directory is not set yet, just use system types
|
||||
}
|
||||
}
|
||||
|
||||
private void AddInput_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_inputs.Add(new FunctionParameterInfo { Name = $"param{_inputs.Count + 1}", Type = "string" });
|
||||
|
||||
@@ -71,30 +71,40 @@ namespace Nodify.Calculator
|
||||
// Add data output connectors to InnerBegin (these feed the inner flow with input values)
|
||||
foreach (var inp in inputs)
|
||||
{
|
||||
var shape = GetShapeForType(inp.Type);
|
||||
var color = ConnectorViewModel.GetColorForType(inp.Type);
|
||||
|
||||
InnerBegin.Output.Add(new ConnectorViewModel
|
||||
{
|
||||
Title = $"{inp.Name} ({inp.Type})",
|
||||
Shape = ConnectorShape.Circle,
|
||||
Shape = shape,
|
||||
IsInput = false,
|
||||
ConnectorColor = System.Drawing.Color.Gold
|
||||
ConnectorColor = color,
|
||||
DataType = inp.Type
|
||||
});
|
||||
|
||||
// Also add an outer input connector on the function node
|
||||
Input.Add(new ConnectorViewModel
|
||||
{
|
||||
Title = $"{inp.Name} ({inp.Type})",
|
||||
ConnectorColor = System.Drawing.Color.Gold
|
||||
Shape = shape,
|
||||
ConnectorColor = color,
|
||||
DataType = inp.Type
|
||||
});
|
||||
}
|
||||
|
||||
// Add data input connectors to InnerEnd (these collect inner flow results)
|
||||
foreach (var outp in outputs)
|
||||
{
|
||||
var shape = GetShapeForType(outp.Type);
|
||||
var color = ConnectorViewModel.GetColorForType(outp.Type);
|
||||
|
||||
InnerEnd.Input.Add(new ConnectorViewModel
|
||||
{
|
||||
Title = $"{outp.Name} ({outp.Type})",
|
||||
Shape = ConnectorShape.Circle,
|
||||
ConnectorColor = System.Drawing.Color.Gold
|
||||
Shape = shape,
|
||||
ConnectorColor = color,
|
||||
DataType = outp.Type
|
||||
});
|
||||
|
||||
// Also add an outer output connector on the function node
|
||||
@@ -102,11 +112,29 @@ namespace Nodify.Calculator
|
||||
{
|
||||
Title = $"{outp.Name} ({outp.Type})",
|
||||
IsInput = false,
|
||||
ConnectorColor = System.Drawing.Color.Gold
|
||||
Shape = shape,
|
||||
ConnectorColor = color,
|
||||
DataType = outp.Type
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the appropriate connector shape based on the type name.
|
||||
/// List/array types use Grid, custom model types use Square, primitives use Circle.
|
||||
/// </summary>
|
||||
private static ConnectorShape GetShapeForType(string typeName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(typeName)) return ConnectorShape.Circle;
|
||||
if (typeName.StartsWith("List<") && typeName.EndsWith(">"))
|
||||
return ConnectorShape.Grid;
|
||||
var primitives = new[] { "string", "int", "double", "bool", "float", "decimal", "long", "datetime", "object" };
|
||||
if (primitives.Contains(typeName.ToLower()))
|
||||
return ConnectorShape.Circle;
|
||||
// Assume it's a custom model type
|
||||
return ConnectorShape.Square;
|
||||
}
|
||||
|
||||
protected override void OnInputValueChanged()
|
||||
{
|
||||
PropagateInputsToInner();
|
||||
|
||||
Reference in New Issue
Block a user