-
-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Graphical FastFlag editor - initial prototype
- Loading branch information
1 parent
049b340
commit cc39ee6
Showing
8 changed files
with
306 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Bloxstrap.Models | ||
{ | ||
public class FastFlag | ||
{ | ||
public bool Enabled { get; set; } | ||
public string Name { get; set; } = null!; | ||
public string Value { get; set; } = null!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<ui:UiWindow x:Class="Bloxstrap.UI.Elements.Dialogs.AddFastFlagDialog" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" | ||
xmlns:local="clr-namespace:Bloxstrap.UI.Elements.Dialogs" | ||
mc:Ignorable="d" | ||
Title="Add FastFlag" | ||
MinHeight="0" | ||
Width="480" | ||
SizeToContent="Height" | ||
ResizeMode="NoResize" | ||
Background="{ui:ThemeResource ApplicationBackgroundBrush}" | ||
ExtendsContentIntoTitleBar="True" | ||
WindowStartupLocation="CenterScreen"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="*" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
|
||
<ui:TitleBar Grid.Row="0" Grid.ColumnSpan="2" Padding="8" Title="Add FastFlag" ShowMinimize="False" ShowMaximize="False" CanMaximize="False" KeyboardNavigation.TabNavigation="None" /> | ||
|
||
<Grid Grid.Row="1" Margin="15"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" MinWidth="100" Text="Flag name" Margin="0,0,0,12" /> | ||
<TextBox Grid.Row="0" Grid.Column="1" Name="FlagNameTextBox" Margin="0,0,0,12" /> | ||
|
||
<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" MinWidth="100" Text="Flag value" /> | ||
<TextBox Grid.Row="1" Grid.Column="1" Name="FlagValueTextBox" /> | ||
</Grid> | ||
|
||
<Border Grid.Row="2" Margin="0,10,0,0" Padding="15" Background="{ui:ThemeResource SolidBackgroundFillColorSecondaryBrush}"> | ||
<StackPanel Orientation="Horizontal" FlowDirection="LeftToRight" HorizontalAlignment="Right"> | ||
<Button MinWidth="100" Content="OK" Click="OKButton_Click"> | ||
<Button.Style> | ||
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}"> | ||
<Style.Triggers> | ||
<DataTrigger Binding="{Binding ElementName=FlagNameTextBox, Path=Text.Length}" Value="0"> | ||
<Setter Property="IsEnabled" Value="False" /> | ||
</DataTrigger> | ||
</Style.Triggers> | ||
</Style> | ||
</Button.Style> | ||
</Button> | ||
<Button MinWidth="100" Margin="12,0,0,0" Content="Cancel" IsCancel="True" /> | ||
</StackPanel> | ||
</Border> | ||
</Grid> | ||
</ui:UiWindow> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Shapes; | ||
|
||
namespace Bloxstrap.UI.Elements.Dialogs | ||
{ | ||
/// <summary> | ||
/// Interaction logic for AddFlagDialog.xaml | ||
/// </summary> | ||
public partial class AddFastFlagDialog | ||
{ | ||
public MessageBoxResult Result = MessageBoxResult.Cancel; | ||
|
||
public AddFastFlagDialog() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void OKButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
Result = MessageBoxResult.OK; | ||
Close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<ui:UiPage x:Class="Bloxstrap.UI.Elements.Menu.Pages.FastFlagEditorPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" | ||
xmlns:local="clr-namespace:Bloxstrap.UI.Elements.Menu.Pages" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" d:DesignWidth="800" | ||
Title="FastFlagEditorPage" | ||
Loaded="Page_Loaded"> | ||
<Grid Margin="0,0,14,14"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="*" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
|
||
<TextBlock Grid.Row="0" Margin="0,0,0,16" Text="Manage your own FastFlags. Press the delete key to delete a selected entry." FontSize="14" Foreground="{DynamicResource TextFillColorSecondaryBrush}" /> | ||
|
||
<DataGrid Name="DataGrid" Grid.Row="1" Style="{x:Null}" HeadersVisibility="Column" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CellEditEnding="DataGrid_CellEditEnding"> | ||
<DataGrid.Columns> | ||
<DataGridCheckBoxColumn Header="Enabled" Binding="{Binding Enabled}" /> | ||
<DataGridTextColumn Header="Name" Binding="{Binding Name}" IsReadOnly="True" /> | ||
<DataGridTextColumn Header="Value" Binding="{Binding Value}" /> | ||
</DataGrid.Columns> | ||
</DataGrid> | ||
|
||
<StackPanel Grid.Row="2" Margin="0,16,0,0" Orientation="Horizontal"> | ||
<ui:Button Icon="Add28" Content="Add new" Click="AddButton_Click" /> | ||
<ui:Button Icon="Delete48" Content="Delete selected" Click="DeleteButton_Click" Appearance="Danger" Margin="12,0,0,0"> | ||
<ui:Button.Style> | ||
<Style TargetType="ui:Button" BasedOn="{StaticResource {x:Type ui:Button}}"> | ||
<Style.Triggers> | ||
<DataTrigger Binding="{Binding ElementName=DataGrid, Path=SelectedItems.Count}" Value="0"> | ||
<Setter Property="IsEnabled" Value="False" /> | ||
</DataTrigger> | ||
</Style.Triggers> | ||
</Style> | ||
</ui:Button.Style> | ||
</ui:Button> | ||
</StackPanel> | ||
</Grid> | ||
</ui:UiPage> |
142 changes: 142 additions & 0 deletions
142
Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Collections.Specialized; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
using Bloxstrap.UI.Elements.Dialogs; | ||
|
||
namespace Bloxstrap.UI.Elements.Menu.Pages | ||
{ | ||
/// <summary> | ||
/// Interaction logic for FastFlagEditorPage.xaml | ||
/// </summary> | ||
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(); | ||
|
||
public FastFlagEditorPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void Page_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
_fastFlagList.Clear(); | ||
|
||
foreach (string flagName in App.FastFlags.Prop.Keys) | ||
{ | ||
string? flagValue = App.FastFlags.GetValue(flagName); | ||
|
||
if (flagValue is null) | ||
continue; | ||
|
||
var entry = new FastFlag | ||
{ | ||
Enabled = true, | ||
Name = flagName, | ||
Value = flagValue | ||
}; | ||
|
||
if (entry.Name.StartsWith("Disable")) | ||
{ | ||
entry.Enabled = false; | ||
entry.Name = entry.Name[7..]; | ||
} | ||
|
||
_fastFlagList.Add(entry); | ||
} | ||
|
||
DataGrid.ItemsSource = _fastFlagList; | ||
} | ||
|
||
private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) | ||
{ | ||
int index = e.Row.GetIndex(); | ||
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.Name, null); | ||
App.FastFlags.SetValue(newName, entry.Value); | ||
|
||
break; | ||
|
||
case "Value": | ||
string newValue = ((TextBox)e.EditingElement).Text; | ||
|
||
App.FastFlags.SetValue(entry.Name, newValue); | ||
|
||
break; | ||
} | ||
} | ||
|
||
private void AddButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
var dialog = new AddFastFlagDialog(); | ||
dialog.ShowDialog(); | ||
|
||
if (dialog.Result != MessageBoxResult.OK) | ||
return; | ||
|
||
var entry = new FastFlag | ||
{ | ||
Enabled = true, | ||
Name = dialog.FlagNameTextBox.Text, | ||
Value = dialog.FlagValueTextBox.Text | ||
}; | ||
|
||
_fastFlagList.Add(entry); | ||
|
||
App.FastFlags.SetValue(entry.Name, entry.Value); | ||
} | ||
|
||
private void DeleteButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
var tempList = new List<FastFlag>(); | ||
|
||
foreach (FastFlag entry in DataGrid.SelectedItems) | ||
tempList.Add(entry); | ||
|
||
foreach (FastFlag entry in tempList) | ||
{ | ||
_fastFlagList.Remove(entry); | ||
App.FastFlags.SetValue(entry.Name, null); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters