Browse Source

Use index for env vars remove

pull/55/head
Ionite 1 year ago
parent
commit
90aa0efa91
No known key found for this signature in database
  1. 16
      StabilityMatrix.Avalonia/ViewModels/Dialogs/EnvVarsViewModel.cs
  2. 41
      StabilityMatrix.Avalonia/Views/Dialogs/EnvVarsDialog.axaml

16
StabilityMatrix.Avalonia/ViewModels/Dialogs/EnvVarsViewModel.cs

@ -1,5 +1,6 @@
using System.Collections.Generic; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics;
using Avalonia.Collections; using Avalonia.Collections;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
@ -26,10 +27,15 @@ public partial class EnvVarsViewModel : ContentDialogViewModelBase
} }
[RelayCommand] [RelayCommand]
private void RemoveSelectedRow() private void RemoveSelectedRow(int selectedIndex)
{ {
if (EnvVarsView.CurrentItem is not EnvVarKeyPair envVar) return; try
{
EnvVars.Remove(envVar); EnvVars.RemoveAt(selectedIndex);
}
catch (ArgumentOutOfRangeException)
{
Debug.WriteLine($"RemoveSelectedRow: Index {selectedIndex} out of range");
}
} }
} }

41
StabilityMatrix.Avalonia/Views/Dialogs/EnvVarsDialog.axaml

@ -12,10 +12,19 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="StabilityMatrix.Avalonia.Views.Dialogs.EnvVarsDialog"> x:Class="StabilityMatrix.Avalonia.Views.Dialogs.EnvVarsDialog">
<controls:UserControlBase.Resources> <controls:UserControlBase.Styles>
<Style Selector="DataGridCell /template/ Border#CellBorder"> <Style Selector="DataGridRow:not(:selected) /template/ Rectangle#BackgroundRectangle">
<Setter Property="Background" Value="Aqua"/> <Setter Property="Fill" Value="{DynamicResource ComboBoxItemBackgroundSelected}"/>
</Style>
<Style Selector="DataGridRow:selected /template/ Rectangle#BackgroundRectangle">
<Setter Property="Fill" Value="{DynamicResource ComboBoxItemBackgroundPointerOver}"/>
</Style> </Style>
</controls:UserControlBase.Styles>
<controls:UserControlBase.Resources>
<DataTemplate x:Key="DataGridCellDividerTemplate">
<Rectangle VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Fill="#08ffffff"/>
</DataTemplate>
</controls:UserControlBase.Resources> </controls:UserControlBase.Resources>
<Grid RowDefinitions="Auto,Auto,*" MinHeight="300" Margin="8"> <Grid RowDefinitions="Auto,Auto,*" MinHeight="300" Margin="8">
@ -34,12 +43,26 @@
</StackPanel> </StackPanel>
<Panel Grid.Row="1"> <Panel Grid.Row="1">
<ui:CommandBar > <ui:CommandBar>
<ui:CommandBar.PrimaryCommands> <ui:CommandBar.PrimaryCommands>
<ui:CommandBarButton IconSource="Add" Label="Save" Command="{Binding AddRowCommand}"/> <ui:CommandBarButton Width="45" Height="50"
<ui:CommandBarButton IconSource="Remove" Label="Undo" Command="{Binding RemoveSelectedRowCommand}"/> IconSource="Add"
Label="Save"
Command="{Binding AddRowCommand}"/>
<ui:CommandBarButton Width="45" Height="50"
IconSource="Remove"
Label="Undo"
CommandParameter="{Binding #EnvVarsGrid.SelectedIndex}"
Command="{Binding RemoveSelectedRowCommand}">
<ui:CommandBarButton.IsEnabled>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="!EnvVarsView.IsEmpty" />
<Binding ElementName="EnvVarsGrid" Path="SelectedItem" Converter="{x:Static ObjectConverters.IsNotNull}" />
</MultiBinding>
</ui:CommandBarButton.IsEnabled>
</ui:CommandBarButton>
<ui:CommandBarSeparator /> <ui:CommandBarSeparator />
<ui:CommandBarButton IconSource="Copy" Label="Bold" /> <ui:CommandBarButton Width="45" Height="50" FontSize="5" IconSource="Copy" Label="Bold" />
</ui:CommandBar.PrimaryCommands> </ui:CommandBar.PrimaryCommands>
</ui:CommandBar> </ui:CommandBar>
</Panel> </Panel>
@ -50,15 +73,19 @@
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
VerticalContentAlignment="Stretch"> VerticalContentAlignment="Stretch">
<DataGrid <DataGrid
x:Name="EnvVarsGrid"
MinHeight="200" MinHeight="200"
ItemsSource="{Binding EnvVarsView}" > ItemsSource="{Binding EnvVarsView}" >
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn x:DataType="models:EnvVarKeyPair" <DataGridTextColumn x:DataType="models:EnvVarKeyPair"
Width="5*" Width="5*"
FontFamily="Cascadia Code,Consolas,Menlo,Monospace"
Header="Name" Header="Name"
Binding="{Binding Key}" /> Binding="{Binding Key}" />
<DataGridTemplateColumn MinWidth="0" Width="1" CellTemplate="{StaticResource DataGridCellDividerTemplate}"/>
<DataGridTextColumn x:DataType="models:EnvVarKeyPair" <DataGridTextColumn x:DataType="models:EnvVarKeyPair"
Width="5*" Width="5*"
FontFamily="Cascadia Code,Consolas,Menlo,Monospace"
Header="Value" Header="Value"
Binding="{Binding Value}" /> Binding="{Binding Value}" />
</DataGrid.Columns> </DataGrid.Columns>

Loading…
Cancel
Save