implemented function edit and alllows the edit in input and output now
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<Window x:Class="Nodify.Calculator.CreateFunctionDialog"
|
<Window x:Class="Nodify.Calculator.CreateFunctionDialog"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
Title="Create New Function"
|
Title="{Binding DialogTitle, RelativeSource={RelativeSource Self}, FallbackValue='Create New Function'}"
|
||||||
Width="500"
|
Width="500"
|
||||||
Height="520"
|
Height="520"
|
||||||
WindowStartupLocation="CenterOwner"
|
WindowStartupLocation="CenterOwner"
|
||||||
@@ -36,8 +36,32 @@
|
|||||||
AlternatingRowBackground="#333337" GridLinesVisibility="None"
|
AlternatingRowBackground="#333337" GridLinesVisibility="None"
|
||||||
HeadersVisibility="Column" BorderBrush="#555">
|
HeadersVisibility="Column" BorderBrush="#555">
|
||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
<DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="*" />
|
<DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="*">
|
||||||
|
<DataGridTextColumn.ElementStyle>
|
||||||
|
<Style TargetType="TextBlock">
|
||||||
|
<Setter Property="Foreground" Value="White" />
|
||||||
|
</Style>
|
||||||
|
</DataGridTextColumn.ElementStyle>
|
||||||
|
<DataGridTextColumn.EditingElementStyle>
|
||||||
|
<Style TargetType="TextBox">
|
||||||
|
<Setter Property="Foreground" Value="Black" />
|
||||||
|
<Setter Property="Background" Value="White" />
|
||||||
|
</Style>
|
||||||
|
</DataGridTextColumn.EditingElementStyle>
|
||||||
|
</DataGridTextColumn>
|
||||||
<DataGridComboBoxColumn Header="Type" SelectedItemBinding="{Binding Type}" Width="120">
|
<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>
|
<DataGridComboBoxColumn.ItemsSource>
|
||||||
<x:Array Type="sys:String" xmlns:sys="clr-namespace:System;assembly=System.Runtime">
|
<x:Array Type="sys:String" xmlns:sys="clr-namespace:System;assembly=System.Runtime">
|
||||||
<sys:String>string</sys:String>
|
<sys:String>string</sys:String>
|
||||||
@@ -67,8 +91,32 @@
|
|||||||
AlternatingRowBackground="#333337" GridLinesVisibility="None"
|
AlternatingRowBackground="#333337" GridLinesVisibility="None"
|
||||||
HeadersVisibility="Column" BorderBrush="#555">
|
HeadersVisibility="Column" BorderBrush="#555">
|
||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
<DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="*" />
|
<DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="*">
|
||||||
|
<DataGridTextColumn.ElementStyle>
|
||||||
|
<Style TargetType="TextBlock">
|
||||||
|
<Setter Property="Foreground" Value="White" />
|
||||||
|
</Style>
|
||||||
|
</DataGridTextColumn.ElementStyle>
|
||||||
|
<DataGridTextColumn.EditingElementStyle>
|
||||||
|
<Style TargetType="TextBox">
|
||||||
|
<Setter Property="Foreground" Value="Black" />
|
||||||
|
<Setter Property="Background" Value="White" />
|
||||||
|
</Style>
|
||||||
|
</DataGridTextColumn.EditingElementStyle>
|
||||||
|
</DataGridTextColumn>
|
||||||
<DataGridComboBoxColumn Header="Type" SelectedItemBinding="{Binding Type}" Width="120">
|
<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>
|
<DataGridComboBoxColumn.ItemsSource>
|
||||||
<x:Array Type="sys:String" xmlns:sys="clr-namespace:System;assembly=System.Runtime">
|
<x:Array Type="sys:String" xmlns:sys="clr-namespace:System;assembly=System.Runtime">
|
||||||
<sys:String>string</sys:String>
|
<sys:String>string</sys:String>
|
||||||
@@ -88,7 +136,7 @@
|
|||||||
|
|
||||||
<!-- Buttons -->
|
<!-- Buttons -->
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="6">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="6">
|
||||||
<Button Content="Create" Width="80" Margin="0 0 10 0" Padding="4"
|
<Button x:Name="CreateButton" Content="Create" Width="80" Margin="0 0 10 0" Padding="4"
|
||||||
Click="OnCreateClick" IsDefault="True" />
|
Click="OnCreateClick" IsDefault="True" />
|
||||||
<Button Content="Cancel" Width="80" Padding="4"
|
<Button Content="Cancel" Width="80" Padding="4"
|
||||||
Click="OnCancelClick" IsCancel="True" />
|
Click="OnCancelClick" IsCancel="True" />
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ namespace Nodify.Calculator
|
|||||||
private readonly ObservableCollection<FunctionParameterInfo> _inputs = new ObservableCollection<FunctionParameterInfo>();
|
private readonly ObservableCollection<FunctionParameterInfo> _inputs = new ObservableCollection<FunctionParameterInfo>();
|
||||||
private readonly ObservableCollection<FunctionParameterInfo> _outputs = new ObservableCollection<FunctionParameterInfo>();
|
private readonly ObservableCollection<FunctionParameterInfo> _outputs = new ObservableCollection<FunctionParameterInfo>();
|
||||||
|
|
||||||
|
public bool IsEditMode { get; private set; }
|
||||||
|
|
||||||
|
public string DialogTitle => IsEditMode ? "Edit Function" : "Create New Function";
|
||||||
|
|
||||||
public CreateFunctionDialog()
|
public CreateFunctionDialog()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -20,6 +24,19 @@ namespace Nodify.Calculator
|
|||||||
OutputParamsGrid.ItemsSource = _outputs;
|
OutputParamsGrid.ItemsSource = _outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CreateFunctionDialog(string functionName, IEnumerable<FunctionParameterInfo> inputs, IEnumerable<FunctionParameterInfo> outputs)
|
||||||
|
: this()
|
||||||
|
{
|
||||||
|
IsEditMode = true;
|
||||||
|
Title = "Edit Function";
|
||||||
|
CreateButton.Content = "Save";
|
||||||
|
FunctionNameBox.Text = functionName;
|
||||||
|
foreach (var p in inputs)
|
||||||
|
_inputs.Add(new FunctionParameterInfo { Name = p.Name, Type = p.Type });
|
||||||
|
foreach (var p in outputs)
|
||||||
|
_outputs.Add(new FunctionParameterInfo { Name = p.Name, Type = p.Type });
|
||||||
|
}
|
||||||
|
|
||||||
private void AddInput_Click(object sender, RoutedEventArgs e)
|
private void AddInput_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
_inputs.Add(new FunctionParameterInfo { Name = $"param{_inputs.Count + 1}", Type = "string" });
|
_inputs.Add(new FunctionParameterInfo { Name = $"param{_inputs.Count + 1}", Type = "string" });
|
||||||
|
|||||||
@@ -983,6 +983,11 @@
|
|||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<TextBlock Text="ƒ " Foreground="#FF9800" FontWeight="Bold" />
|
<TextBlock Text="ƒ " Foreground="#FF9800" FontWeight="Bold" />
|
||||||
<TextBlock Text="{Binding Title}" Foreground="Orange" FontWeight="SemiBold" />
|
<TextBlock Text="{Binding Title}" Foreground="Orange" FontWeight="SemiBold" />
|
||||||
|
<Button Content="✏️" Margin="6 0 0 0" Padding="2 0"
|
||||||
|
Background="Transparent" Foreground="White" BorderThickness="0"
|
||||||
|
Cursor="Hand" ToolTip="Edit Function"
|
||||||
|
Command="{Binding DataContext.Calculator.OperationsMenu.EditFunctionCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||||
|
CommandParameter="{Binding}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ namespace Nodify.Calculator
|
|||||||
ImportSwaggerCommand = new DelegateCommand(ImportSwagger);
|
ImportSwaggerCommand = new DelegateCommand(ImportSwagger);
|
||||||
AddVariableCommand = new DelegateCommand(AddVariable);
|
AddVariableCommand = new DelegateCommand(AddVariable);
|
||||||
CreateFunctionCommand = new DelegateCommand(CreateFunction);
|
CreateFunctionCommand = new DelegateCommand(CreateFunction);
|
||||||
|
EditFunctionCommand = new DelegateCommand<OperationInfoViewModel>(EditFunction);
|
||||||
CreateModelCommand = new DelegateCommand(CreateModel);
|
CreateModelCommand = new DelegateCommand(CreateModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,6 +197,7 @@ namespace Nodify.Calculator
|
|||||||
public INodifyCommand ImportSwaggerCommand { get; }
|
public INodifyCommand ImportSwaggerCommand { get; }
|
||||||
public INodifyCommand AddVariableCommand { get; }
|
public INodifyCommand AddVariableCommand { get; }
|
||||||
public INodifyCommand CreateFunctionCommand { get; }
|
public INodifyCommand CreateFunctionCommand { get; }
|
||||||
|
public INodifyCommand EditFunctionCommand { get; }
|
||||||
public INodifyCommand CreateModelCommand { get; }
|
public INodifyCommand CreateModelCommand { get; }
|
||||||
|
|
||||||
private void CreateModel()
|
private void CreateModel()
|
||||||
@@ -267,6 +269,27 @@ namespace Nodify.Calculator
|
|||||||
AvailableOperations.Add(funcInfo);
|
AvailableOperations.Add(funcInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void EditFunction(OperationInfoViewModel funcInfo)
|
||||||
|
{
|
||||||
|
if (funcInfo == null) return;
|
||||||
|
|
||||||
|
var dialog = new CreateFunctionDialog(funcInfo.Title, funcInfo.FunctionInputs, funcInfo.FunctionOutputs);
|
||||||
|
dialog.Owner = System.Windows.Application.Current.MainWindow;
|
||||||
|
if (dialog.ShowDialog() != true)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var newName = dialog.FunctionName;
|
||||||
|
if (newName != funcInfo.Title && AvailableFunctions.Any(f => f.Title == newName))
|
||||||
|
{
|
||||||
|
MessageBox.Show($"A function named '{newName}' already exists.", "Duplicate Function", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
funcInfo.Title = newName;
|
||||||
|
funcInfo.FunctionInputs = new System.Collections.Generic.List<FunctionParameterInfo>(dialog.InputParameters);
|
||||||
|
funcInfo.FunctionOutputs = new System.Collections.Generic.List<FunctionParameterInfo>(dialog.OutputParameters);
|
||||||
|
}
|
||||||
|
|
||||||
private void AddVariable()
|
private void AddVariable()
|
||||||
{
|
{
|
||||||
var dialog = new AddVariableDialog();
|
var dialog = new AddVariableDialog();
|
||||||
|
|||||||
Reference in New Issue
Block a user