From b6dee9c772956db58355a6d47b8e96b254dcb883 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Thu, 24 Aug 2023 22:22:41 +0100 Subject: [PATCH] Allow for flag names to be editable --- .../Menu/Pages/FastFlagEditorPage.xaml | 4 ++-- .../Menu/Pages/FastFlagEditorPage.xaml.cs | 22 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml index f66edba0..d2447c8d 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml +++ b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml @@ -17,7 +17,7 @@ - + @@ -87,7 +87,7 @@ - + diff --git a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs index 8b88fdf3..01d37b6c 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs +++ b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs @@ -8,6 +8,7 @@ using Wpf.Ui.Mvvm.Contracts; using Bloxstrap.UI.Elements.Dialogs; +using System.Xml.Linq; namespace Bloxstrap.UI.Elements.Menu.Pages { @@ -111,11 +112,28 @@ private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventA break; */ case "Name": - string newName = ((TextBox)e.EditingElement).Text; + var textbox = e.EditingElement as TextBox; - App.FastFlags.SetValue(entry.Name, null); + string oldName = entry.Name; + string newName = textbox!.Text; + + if (newName == oldName) + return; + + if (App.FastFlags.GetValue(newName) is not null) + { + Controls.ShowMessageBox("A FastFlag with this name already exists.", MessageBoxImage.Information); + e.Cancel = true; + textbox.Text = oldName; + return; + } + + App.FastFlags.SetValue(oldName, null); App.FastFlags.SetValue(newName, entry.Value); + if (!newName.Contains(_searchFilter)) + ClearSearch(); + break; case "Value":