Skip to content

Commit

Permalink
Re-add FastFlag struct class
Browse files Browse the repository at this point in the history
forgot keyvaluepairs arent editable :(
  • Loading branch information
pizzaboxer committed Jul 23, 2023
1 parent b3b174e commit 52b6a60
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
9 changes: 9 additions & 0 deletions Bloxstrap/Models/FastFlag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Bloxstrap.Models
{
public class FastFlag
{
// public bool Enabled { get; set; }
public string Name { get; set; } = null!;
public string Value { get; set; } = null!;
}
}
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 @@ -75,7 +75,7 @@
</DataGrid.CellStyle>

<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Key}" IsReadOnly="True" />
<DataGridTextColumn Header="Name" Binding="{Binding Name}" IsReadOnly="True" />
<DataGridTextColumn Header="Value" Binding="{Binding Value}" Width="*" />
</DataGrid.Columns>
</DataGrid>
Expand Down
58 changes: 46 additions & 12 deletions Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class FastFlagEditorPage
// believe me when i say there is absolutely zero point to using mvvm for this
// using a datagrid is a codebehind thing only and thats it theres literally no way around it

private readonly ObservableCollection<KeyValuePair<string, string>> _fastFlagList = new();
private readonly ObservableCollection<FastFlag> _fastFlagList = new();
private bool _showPresets = false;

public FastFlagEditorPage()
Expand All @@ -31,11 +31,24 @@ private void ReloadList()

var presetFlags = FastFlagManager.PresetFlags.Values;

foreach (var entry in App.FastFlags.Prop)
foreach (var pair in App.FastFlags.Prop)
{
if (!_showPresets && presetFlags.Contains(entry.Key))
if (!_showPresets && presetFlags.Contains(pair.Key))
continue;

var entry = new FastFlag
{
// Enabled = true,
Name = pair.Key,
Value = pair.Value
};

/* if (entry.Name.StartsWith("Disable"))
{
entry.Enabled = false;
entry.Name = entry.Name[7..];
} */

_fastFlagList.Add(entry);
}

Expand All @@ -48,22 +61,38 @@ private void ReloadList()
private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
int index = e.Row.GetIndex();
var entry = _fastFlagList[index];
FastFlag entry = _fastFlagList[index];

switch (e.Column.Header)
{
/* case "Enabled":
bool enabled = (bool)((CheckBox)e.EditingElement).IsChecked!;
if (enabled)
{
App.FastFlags.SetValue(entry.Name, entry.Value);
App.FastFlags.SetValue($"Disable{entry.Name}", null);
}
else
{
App.FastFlags.SetValue(entry.Name, null);
App.FastFlags.SetValue($"Disable{entry.Name}", entry.Value);
}
break; */

case "Name":
string newName = ((TextBox)e.EditingElement).Text;

App.FastFlags.SetValue(entry.Key, null);
App.FastFlags.SetValue(entry.Name, null);
App.FastFlags.SetValue(newName, entry.Value);

break;

case "Value":
string newValue = ((TextBox)e.EditingElement).Text;

App.FastFlags.SetValue(entry.Key, newValue);
App.FastFlags.SetValue(entry.Name, newValue);

break;
}
Expand All @@ -83,24 +112,29 @@ private void AddButton_Click(object sender, RoutedEventArgs e)
if (dialog.Result != MessageBoxResult.OK)
return;

var entry = new KeyValuePair<string, string>(dialog.FlagNameTextBox.Text, dialog.FlagValueTextBox.Text);
var entry = new FastFlag
{
// Enabled = true,
Name = dialog.FlagNameTextBox.Text,
Value = dialog.FlagValueTextBox.Text
};

_fastFlagList.Add(entry);

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

private void DeleteButton_Click(object sender, RoutedEventArgs e)
{
var tempList = new List<KeyValuePair<string, string>>();
var tempList = new List<FastFlag>();

foreach (KeyValuePair<string, string> entry in DataGrid.SelectedItems)
foreach (FastFlag entry in DataGrid.SelectedItems)
tempList.Add(entry);

foreach (var entry in tempList)
foreach (FastFlag entry in tempList)
{
_fastFlagList.Remove(entry);
App.FastFlags.SetValue(entry.Key, null);
App.FastFlags.SetValue(entry.Name, null);
}
}

Expand Down

0 comments on commit 52b6a60

Please sign in to comment.