Skip to content

Commit

Permalink
FastFlag editor: prevent duplicate additions
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Jul 24, 2023
1 parent e2c1997 commit 3c365a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</Style>
</ui:Button.Style>
</ui:Button>
<ToggleButton Content="Show preset flags" Click="ToggleButton_Click" Margin="12,0,0,0" />
<ToggleButton x:Name="TogglePresetsButton" Content="Show preset flags" Click="ToggleButton_Click" Margin="12,0,0,0" />
</StackPanel>

<DataGrid Name="DataGrid" Grid.Row="2" HeadersVisibility="Column" GridLinesVisibility="Horizontal" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CellEditEnding="DataGrid_CellEditEnding">
Expand Down
36 changes: 28 additions & 8 deletions Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,39 @@ private void AddButton_Click(object sender, RoutedEventArgs e)
if (dialog.Result != MessageBoxResult.OK)
return;

var entry = new FastFlag
string name = dialog.FlagNameTextBox.Text;

FastFlag? entry;

if (App.FastFlags.GetValue(name) is null)
{
entry = new FastFlag
{
// Enabled = true,
Name = dialog.FlagNameTextBox.Text,
Value = dialog.FlagValueTextBox.Text
};

_fastFlagList.Add(entry);

App.FastFlags.SetValue(entry.Name, entry.Value);
}
else
{
// Enabled = true,
Name = dialog.FlagNameTextBox.Text,
Value = dialog.FlagValueTextBox.Text
};
Controls.ShowMessageBox("An entry for this FastFlag already exists.", MessageBoxImage.Information);

_fastFlagList.Add(entry);
if (!_showPresets && FastFlagManager.PresetFlags.Values.Contains(dialog.FlagNameTextBox.Text))
{
_showPresets = true;
TogglePresetsButton.IsChecked = true;
ReloadList();
}

entry = _fastFlagList.Where(x => x.Name == name).FirstOrDefault();
}

DataGrid.SelectedItem = entry;
DataGrid.ScrollIntoView(entry);

App.FastFlags.SetValue(entry.Name, entry.Value);
}

private void DeleteButton_Click(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 3c365a5

Please sign in to comment.