Skip to content

Commit

Permalink
Remove option to enable/disable flags
Browse files Browse the repository at this point in the history
:(
  • Loading branch information
pizzaboxer committed Jul 23, 2023
1 parent 1b3049f commit 500b21d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 74 deletions.
15 changes: 0 additions & 15 deletions Bloxstrap/Models/FastFlag.cs

This file was deleted.

26 changes: 13 additions & 13 deletions Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,33 @@

<TextBlock Grid.Row="0" Margin="0,0,0,16" Text="Manage your own FastFlags. Double click the value column to edit." FontSize="14" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />

<ui:DataGrid Name="DataGrid" Grid.Row="1" HeadersVisibility="Column" GridLinesVisibility="Horizontal" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CellEditEnding="DataGrid_CellEditEnding">
<ui:DataGrid.Style>
<Style TargetType="ui:DataGrid" BasedOn="{StaticResource {x:Type ui:DataGrid}}">
<DataGrid Name="DataGrid" Grid.Row="1" HeadersVisibility="Column" GridLinesVisibility="Horizontal" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CellEditEnding="DataGrid_CellEditEnding">
<DataGrid.Style>
<Style TargetType="DataGrid" BasedOn="{StaticResource {x:Type DataGrid}}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
</Style>
</ui:DataGrid.Style>
</DataGrid.Style>

<ui:DataGrid.ColumnHeaderStyle>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="{DynamicResource ControlFillColorTertiaryBrush}" />
<Setter Property="Height" Value="32" />
<Setter Property="Padding" Value="8,0,8,0" />
<Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
<Setter Property="BorderThickness" Value="1" />
</Style>
</ui:DataGrid.ColumnHeaderStyle>
</DataGrid.ColumnHeaderStyle>

<ui:DataGrid.CellStyle>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="{DynamicResource PaletteDeepPurpleBrush}" />
</Trigger>
</Style.Triggers>
<Setter Property="Height" Value="32" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridCell">
Expand All @@ -54,14 +55,13 @@
</Setter.Value>
</Setter>
</Style>
</ui:DataGrid.CellStyle>
</DataGrid.CellStyle>

<ui:DataGrid.Columns>
<DataGridCheckBoxColumn Header="Enabled" Binding="{Binding Enabled}" Width="68" />
<DataGridTextColumn Header="Name" Binding="{Binding Name}" IsReadOnly="True" />
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Key}" IsReadOnly="True" />
<DataGridTextColumn Header="Value" Binding="{Binding Value}" Width="*" />
</ui:DataGrid.Columns>
</ui:DataGrid>
</DataGrid.Columns>
</DataGrid>

<StackPanel Grid.Row="2" Margin="0,16,0,0" Orientation="Horizontal">
<ui:Button Icon="Add28" Content="Add new" Click="AddButton_Click" />
Expand Down
58 changes: 12 additions & 46 deletions Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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<FastFlag> _fastFlagList = new();
private readonly ObservableCollection<KeyValuePair<string, string>> _fastFlagList = new();
private bool _showPresets = false;

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

var presetFlags = FastFlagManager.PresetFlags.Values;

foreach (var pair in App.FastFlags.Prop)
foreach (var entry in App.FastFlags.Prop)
{
if (!_showPresets && presetFlags.Contains(pair.Key))
if (!_showPresets && presetFlags.Contains(entry.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 @@ -59,38 +46,22 @@ private void ReloadList()
private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
int index = e.Row.GetIndex();
FastFlag entry = _fastFlagList[index];
var 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.Name, null);
App.FastFlags.SetValue(entry.Key, null);
App.FastFlags.SetValue(newName, entry.Value);

break;

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

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

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

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

_fastFlagList.Add(entry);

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

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

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

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

Expand Down

0 comments on commit 500b21d

Please sign in to comment.