mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 18:11:27 -07:00
Flag editor: refactor flag adding and localize
This commit is contained in:
parent
ae695d5cb3
commit
db544697ad
@ -36,6 +36,7 @@
|
||||
|
||||
<converters:ResourceConverter x:Key="ResourceConverter" />
|
||||
<converters:StringFormatConverter x:Key="StringFormatConverter" />
|
||||
<converters:RangeConverter x:Key="RangeConverter" />
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
|
87
Bloxstrap/Resources/Strings.Designer.cs
generated
87
Bloxstrap/Resources/Strings.Designer.cs
generated
@ -613,7 +613,9 @@ namespace Bloxstrap.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Paste in your JSON here....
|
||||
/// Looks up a localized string similar to {
|
||||
/// "FFlagDebugDisplayFPS": "True"
|
||||
///}.
|
||||
/// </summary>
|
||||
public static string Dialog_BulkAddFastFlag_Paste {
|
||||
get {
|
||||
@ -1803,6 +1805,15 @@ namespace Bloxstrap.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to An entry for this flag name already exists..
|
||||
/// </summary>
|
||||
public static string Menu_FastFlagEditor_AlreadyExists {
|
||||
get {
|
||||
return ResourceManager.GetString("Menu.FastFlagEditor.AlreadyExists", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Back.
|
||||
/// </summary>
|
||||
@ -1812,6 +1823,35 @@ namespace Bloxstrap.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Misusing this can lead to instability or unexpected things happening..
|
||||
/// </summary>
|
||||
public static string Menu_FastFlagEditor_BannerText {
|
||||
get {
|
||||
return ResourceManager.GetString("Menu.FastFlagEditor.BannerText", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Use with caution..
|
||||
/// </summary>
|
||||
public static string Menu_FastFlagEditor_BannerTitle {
|
||||
get {
|
||||
return ResourceManager.GetString("Menu.FastFlagEditor.BannerTitle", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Some of the flags you are attempting to import already have set values. Would you like to overwrite their current values with the ones defined in the import?
|
||||
///
|
||||
///.
|
||||
/// </summary>
|
||||
public static string Menu_FastFlagEditor_ConflictingImport {
|
||||
get {
|
||||
return ResourceManager.GetString("Menu.FastFlagEditor.ConflictingImport", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Delete selected.
|
||||
/// </summary>
|
||||
@ -1822,7 +1862,7 @@ namespace Bloxstrap.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Manage your own FastFlags. Use with caution. Double click a column to edit..
|
||||
/// Looks up a localized string similar to Manage your own FastFlags. Double click a column to edit..
|
||||
/// </summary>
|
||||
public static string Menu_FastFlagEditor_Description {
|
||||
get {
|
||||
@ -1840,7 +1880,37 @@ namespace Bloxstrap.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Copied JSON to clipboard..
|
||||
/// Looks up a localized string similar to The name of this flag is not valid as names can only contain letters, numbers, and underscores.
|
||||
/// </summary>
|
||||
public static string Menu_FastFlagEditor_InvalidCharacter {
|
||||
get {
|
||||
return ResourceManager.GetString("Menu.FastFlagEditor.InvalidCharacter", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to The JSON you've entered does not appear to be valid. Please double check it and try again.
|
||||
///
|
||||
///More information:
|
||||
///{0}.
|
||||
/// </summary>
|
||||
public static string Menu_FastFlagEditor_InvalidJSON {
|
||||
get {
|
||||
return ResourceManager.GetString("Menu.FastFlagEditor.InvalidJSON", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to The name of this flag is not valid as names must start with FFlag, DFInt, etc.
|
||||
/// </summary>
|
||||
public static string Menu_FastFlagEditor_InvalidPrefix {
|
||||
get {
|
||||
return ResourceManager.GetString("Menu.FastFlagEditor.InvalidPrefix", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Copied to clipboard..
|
||||
/// </summary>
|
||||
public static string Menu_FastFlagEditor_JsonCopiedToClipboard {
|
||||
get {
|
||||
@ -1848,6 +1918,17 @@ namespace Bloxstrap.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You appear to be importing a very large configuration. You should only be importing configurations that you fully understand. Do NOT blindly paste in configurations made by other people. If you continue, you will very likely end up with stability issues and encounter unexpected changes.
|
||||
///
|
||||
///Are you sure you want to continue?.
|
||||
/// </summary>
|
||||
public static string Menu_FastFlagEditor_LargeConfig {
|
||||
get {
|
||||
return ResourceManager.GetString("Menu.FastFlagEditor.LargeConfig", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Search.
|
||||
/// </summary>
|
||||
|
@ -306,7 +306,9 @@ Your ReShade configuration files will still be saved, and you can locate them by
|
||||
<value>Add FastFlag</value>
|
||||
</data>
|
||||
<data name="Dialog.BulkAddFastFlag.Paste" xml:space="preserve">
|
||||
<value>Paste in your JSON here...</value>
|
||||
<value>{
|
||||
"FFlagDebugDisplayFPS": "True"
|
||||
}</value>
|
||||
</data>
|
||||
<data name="Dialog.Connectivity.MoreInfo" xml:space="preserve">
|
||||
<value>More information:</value>
|
||||
@ -704,20 +706,51 @@ Would you like to upgrade your currently installed version?</value>
|
||||
<data name="Menu.FastFlagEditor.AddNew" xml:space="preserve">
|
||||
<value>Add new</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.AlreadyExists" xml:space="preserve">
|
||||
<value>An entry for this flag name already exists.</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.Back" xml:space="preserve">
|
||||
<value>Back</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.BannerText" xml:space="preserve">
|
||||
<value>Misusing this can lead to instability or unexpected things happening.</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.BannerTitle" xml:space="preserve">
|
||||
<value>Use with caution.</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.ConflictingImport" xml:space="preserve">
|
||||
<value>Some of the flags you are attempting to import already have set values. Would you like to overwrite their current values with the ones defined in the import?
|
||||
|
||||
</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.DeleteSelected" xml:space="preserve">
|
||||
<value>Delete selected</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.Description" xml:space="preserve">
|
||||
<value>Manage your own FastFlags. Use with caution. Double click a column to edit.</value>
|
||||
<value>Manage your own FastFlags. Double click a column to edit.</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.ExportJson" xml:space="preserve">
|
||||
<value>Export JSON</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.InvalidCharacter" xml:space="preserve">
|
||||
<value>The name of this flag is not valid as names can only contain letters, numbers, and underscores</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.InvalidJSON" xml:space="preserve">
|
||||
<value>The JSON you've entered does not appear to be valid. Please double check it and try again.
|
||||
|
||||
More information:
|
||||
{0}</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.InvalidPrefix" xml:space="preserve">
|
||||
<value>The name of this flag is not valid as names must start with FFlag, DFInt, etc</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.JsonCopiedToClipboard" xml:space="preserve">
|
||||
<value>Copied JSON to clipboard.</value>
|
||||
<value>Copied to clipboard.</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.LargeConfig" xml:space="preserve">
|
||||
<value>You appear to be importing a very large configuration. You should only be importing configurations that you fully understand. Do NOT blindly paste in configurations made by other people. If you continue, you will very likely end up with stability issues and encounter unexpected changes.
|
||||
|
||||
Are you sure you want to continue?</value>
|
||||
</data>
|
||||
<data name="Menu.FastFlagEditor.Search" xml:space="preserve">
|
||||
<value>Search</value>
|
||||
|
29
Bloxstrap/UI/Converters/RangeConverter.cs
Normal file
29
Bloxstrap/UI/Converters/RangeConverter.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Bloxstrap.UI.Converters
|
||||
{
|
||||
internal class RangeConverter : IValueConverter
|
||||
{
|
||||
public int? From { get; set; }
|
||||
|
||||
public int? To { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
int numvalue = (int)value;
|
||||
|
||||
if (From is null)
|
||||
return numvalue < To;
|
||||
|
||||
if (To is null)
|
||||
return numvalue > From;
|
||||
|
||||
return numvalue > From && numvalue < To;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
xmlns:local="clr-namespace:Bloxstrap.UI.Elements.Dialogs"
|
||||
xmlns:resources="clr-namespace:Bloxstrap.Resources"
|
||||
xmlns:converters="clr-namespace:Bloxstrap.UI.Converters"
|
||||
mc:Ignorable="d"
|
||||
Title="{x:Static resources:Strings.Dialog_AddFastFlag_Title}"
|
||||
MinHeight="0"
|
||||
@ -15,6 +16,10 @@
|
||||
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
|
||||
ExtendsContentIntoTitleBar="True"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<ui:UiWindow.Resources>
|
||||
<converters:RangeConverter x:Key="ValidationConverter" From="0" />
|
||||
</ui:UiWindow.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
@ -24,7 +29,9 @@
|
||||
|
||||
<ui:TitleBar Grid.Row="0" Grid.ColumnSpan="2" Padding="8" Title="{x:Static resources:Strings.Dialog_AddFastFlag_Title}" ShowMinimize="False" ShowMaximize="False" CanMaximize="False" KeyboardNavigation.TabNavigation="None" />
|
||||
|
||||
<Grid Grid.Row="1" Margin="15">
|
||||
<TabControl x:Name="Tabs" Grid.Row="1" Margin="16">
|
||||
<TabItem Header="Add single">
|
||||
<Grid Grid.Row="1" Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
@ -40,6 +47,25 @@
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" MinWidth="100" Text="{x:Static resources:Strings.Common_Value}" />
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Name="FlagValueTextBox" />
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="{x:Static resources:Strings.Common_ImportJson}">
|
||||
<Grid Margin="11">
|
||||
<TextBox x:Name="JsonTextBox" Margin="5" AcceptsTab="True" AcceptsReturn="True" MinHeight="80" MaxHeight="480" />
|
||||
<TextBlock IsHitTestVisible="False" Margin="18,14,0,0" Foreground="DarkGray" Text="{x:Static resources:Strings.Dialog_BulkAddFastFlag_Paste}">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="{x:Type TextBlock}">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Text, ElementName=JsonTextBox}" Value="">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
<Border Grid.Row="2" Margin="0,10,0,0" Padding="15" Background="{ui:ThemeResource SolidBackgroundFillColorSecondaryBrush}">
|
||||
<StackPanel Orientation="Horizontal" FlowDirection="LeftToRight" HorizontalAlignment="Right">
|
||||
@ -47,10 +73,22 @@
|
||||
<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>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding ElementName=Tabs, Path=SelectedIndex}" Value="0" />
|
||||
<Condition Binding="{Binding ElementName=FlagNameTextBox, Path=Text.Length, Converter={StaticResource ValidationConverter}}" Value="True" />
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="IsEnabled" Value="True" />
|
||||
</MultiDataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding ElementName=Tabs, Path=SelectedIndex}" Value="1" />
|
||||
<Condition Binding="{Binding ElementName=JsonTextBox, Path=Text.Length, Converter={StaticResource ValidationConverter}}" Value="True" />
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="IsEnabled" Value="True" />
|
||||
</MultiDataTrigger>
|
||||
</Style.Triggers>
|
||||
<Setter Property="IsEnabled" Value="False" />
|
||||
</Style>
|
||||
</Button.Style>
|
||||
</Button>
|
||||
|
@ -15,7 +15,7 @@ using System.Windows.Shapes;
|
||||
namespace Bloxstrap.UI.Elements.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AddFlagDialog.xaml
|
||||
/// Interaction logic for AddFastFlagDialog.xaml
|
||||
/// </summary>
|
||||
public partial class AddFastFlagDialog
|
||||
{
|
||||
|
@ -1,60 +0,0 @@
|
||||
<ui:UiWindow x:Class="Bloxstrap.UI.Elements.Dialogs.BulkAddFastFlagDialog"
|
||||
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"
|
||||
xmlns:resources="clr-namespace:Bloxstrap.Resources"
|
||||
mc:Ignorable="d"
|
||||
Title="{x:Static resources:Strings.Common_ImportJson}"
|
||||
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="{x:Static resources:Strings.Common_ImportJson}" ShowMinimize="False" ShowMaximize="False" CanMaximize="False" KeyboardNavigation.TabNavigation="None" />
|
||||
|
||||
<Grid Grid.Row="1" Margin="8,4,8,4">
|
||||
<TextBox x:Name="JsonTextBox" Margin="5" AcceptsTab="True" AcceptsReturn="True" MinHeight="80" MaxHeight="480" />
|
||||
<TextBlock IsHitTestVisible="False" Margin="18,14,0,0" Foreground="DarkGray" Text="{x:Static resources:Strings.Dialog_BulkAddFastFlag_Paste}">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="{x:Type TextBlock}">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Text, ElementName=JsonTextBox}" Value="">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
|
||||
<Border Grid.Row="3" Margin="0,10,0,0" Padding="15" Background="{ui:ThemeResource SolidBackgroundFillColorSecondaryBrush}">
|
||||
<StackPanel Orientation="Horizontal" FlowDirection="LeftToRight" HorizontalAlignment="Right">
|
||||
<Button MinWidth="100" Content="{x:Static resources:Strings.Common_OK}" Click="OKButton_Click">
|
||||
<Button.Style>
|
||||
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ElementName=JsonTextBox, 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="{x:Static resources:Strings.Common_Cancel}" IsCancel="True" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ui:UiWindow>
|
@ -1,35 +0,0 @@
|
||||
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 BulkAddFastFlagDialog.xaml
|
||||
/// </summary>
|
||||
public partial class BulkAddFastFlagDialog
|
||||
{
|
||||
public MessageBoxResult Result = MessageBoxResult.Cancel;
|
||||
|
||||
public BulkAddFastFlagDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OKButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Result = MessageBoxResult.OK;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,9 @@
|
||||
|
||||
<TextBlock Grid.Row="0" Margin="0,0,0,16" Text="{x:Static resources:Strings.Menu_FastFlagEditor_Description}" FontSize="14" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
|
||||
|
||||
<StackPanel Grid.Row="1" Margin="0,0,0,8" Orientation="Horizontal">
|
||||
<ui:InfoBar Grid.Row="1" Margin="0,0,0,16" Padding="8" Title="{x:Static resources:Strings.Menu_FastFlagEditor_BannerTitle}" IsOpen="True" Message="{x:Static resources:Strings.Menu_FastFlagEditor_BannerText}" Severity="Warning" IsClosable="False" />
|
||||
|
||||
<StackPanel Grid.Row="2" Margin="0,0,0,16" Orientation="Horizontal">
|
||||
<ui:Button Icon="ArrowLeft48" Content="{x:Static resources:Strings.Menu_FastFlagEditor_Back}" Click="BackButton_Click" />
|
||||
<ui:Button Icon="Add28" Content="{x:Static resources:Strings.Menu_FastFlagEditor_AddNew}" Click="AddButton_Click" Margin="12,0,0,0" />
|
||||
<ui:Button Icon="Delete48" Content="{x:Static resources:Strings.Menu_FastFlagEditor_DeleteSelected}" Click="DeleteButton_Click" Appearance="Danger" Margin="12,0,0,0">
|
||||
@ -36,10 +38,6 @@
|
||||
</ui:Button.Style>
|
||||
</ui:Button>
|
||||
<ToggleButton x:Name="TogglePresetsButton" Content="{x:Static resources:Strings.Menu_FastFlagEditor_ShowPresetFlags}" Click="ToggleButton_Click" Margin="12,0,0,0" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="2" Margin="0,0,0,16" Orientation="Horizontal">
|
||||
<ui:Button Icon="ArrowImport24" Content="{x:Static resources:Strings.Common_ImportJson}" Click="ImportJSONButton_Click" />
|
||||
<ui:Button Icon="ArrowExportRtl24" Content="{x:Static resources:Strings.Menu_FastFlagEditor_ExportJson}" Margin="12,0,0,0" Click="ExportJSONButton_Click" />
|
||||
</StackPanel>
|
||||
|
||||
|
@ -1,14 +1,11 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
|
||||
using Microsoft.Win32;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using Wpf.Ui.Mvvm.Contracts;
|
||||
|
||||
using Bloxstrap.UI.Elements.Dialogs;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Bloxstrap.UI.Elements.Menu.Pages
|
||||
{
|
||||
@ -21,6 +18,11 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
|
||||
// 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 List<string> _validPrefixes = new()
|
||||
{
|
||||
"FFlag", "DFFlag", "SFFlag", "FInt", "DFInt", "FString", "DFString", "FLog", "DFlog"
|
||||
};
|
||||
|
||||
private bool _showPresets = false;
|
||||
private string _searchFilter = "";
|
||||
|
||||
@ -85,6 +87,165 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
|
||||
ReloadList();
|
||||
}
|
||||
|
||||
private void ShowAddDialog()
|
||||
{
|
||||
var dialog = new AddFastFlagDialog();
|
||||
dialog.ShowDialog();
|
||||
|
||||
if (dialog.Result != MessageBoxResult.OK)
|
||||
return;
|
||||
|
||||
if (dialog.Tabs.SelectedIndex == 0)
|
||||
AddEntry(dialog.FlagNameTextBox.Text, dialog.FlagValueTextBox.Text);
|
||||
else if (dialog.Tabs.SelectedIndex == 1)
|
||||
ImportJSON(dialog.JsonTextBox.Text);
|
||||
}
|
||||
|
||||
private void AddEntry(string name, string value)
|
||||
{
|
||||
FastFlag? entry;
|
||||
|
||||
if (App.FastFlags.GetValue(name) is null)
|
||||
{
|
||||
if (!_validPrefixes.Where(x => name.StartsWith(x)).Any())
|
||||
{
|
||||
Frontend.ShowMessageBox(Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidPrefix, MessageBoxImage.Error);
|
||||
ShowAddDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!name.All(x => char.IsLetterOrDigit(x) || x == '_'))
|
||||
{
|
||||
Frontend.ShowMessageBox(Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidCharacter, MessageBoxImage.Error);
|
||||
ShowAddDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
entry = new FastFlag
|
||||
{
|
||||
// Enabled = true,
|
||||
Name = name,
|
||||
Value = value
|
||||
};
|
||||
|
||||
if (!name.Contains(_searchFilter))
|
||||
ClearSearch();
|
||||
|
||||
_fastFlagList.Add(entry);
|
||||
|
||||
App.FastFlags.SetValue(entry.Name, entry.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Frontend.ShowMessageBox(Bloxstrap.Resources.Strings.Menu_FastFlagEditor_AlreadyExists, MessageBoxImage.Information);
|
||||
|
||||
bool refresh = false;
|
||||
|
||||
if (!_showPresets && FastFlagManager.PresetFlags.Values.Contains(name))
|
||||
{
|
||||
TogglePresetsButton.IsChecked = true;
|
||||
_showPresets = true;
|
||||
refresh = true;
|
||||
}
|
||||
|
||||
if (!name.Contains(_searchFilter))
|
||||
{
|
||||
ClearSearch(false);
|
||||
refresh = true;
|
||||
}
|
||||
|
||||
if (refresh)
|
||||
ReloadList();
|
||||
|
||||
entry = _fastFlagList.Where(x => x.Name == name).FirstOrDefault();
|
||||
}
|
||||
|
||||
DataGrid.SelectedItem = entry;
|
||||
DataGrid.ScrollIntoView(entry);
|
||||
}
|
||||
|
||||
private void ImportJSON(string json)
|
||||
{
|
||||
Dictionary<string, object>? list = null;
|
||||
|
||||
json = json.Trim();
|
||||
|
||||
// autocorrect where possible
|
||||
if (!json.StartsWith('{'))
|
||||
json = '{' + json;
|
||||
|
||||
if (!json.EndsWith('}'))
|
||||
json += '}';
|
||||
|
||||
try
|
||||
{
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
ReadCommentHandling = JsonCommentHandling.Skip,
|
||||
AllowTrailingCommas = true
|
||||
};
|
||||
|
||||
list = JsonSerializer.Deserialize<Dictionary<string, object>>(json, options);
|
||||
|
||||
if (list is null)
|
||||
throw new Exception("JSON deserialization returned null");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Frontend.ShowMessageBox(
|
||||
String.Format(Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidJSON, ex.Message),
|
||||
MessageBoxImage.Error
|
||||
);
|
||||
|
||||
ShowAddDialog();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (list.Count > 16)
|
||||
{
|
||||
var result = Frontend.ShowMessageBox(
|
||||
Bloxstrap.Resources.Strings.Menu_FastFlagEditor_LargeConfig,
|
||||
MessageBoxImage.Warning,
|
||||
MessageBoxButton.YesNo
|
||||
);
|
||||
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
}
|
||||
|
||||
var conflictingFlags = App.FastFlags.Prop.Where(x => list.ContainsKey(x.Key)).Select(x => x.Key);
|
||||
bool overwriteConflicting = false;
|
||||
|
||||
if (conflictingFlags.Any())
|
||||
{
|
||||
int count = conflictingFlags.Count();
|
||||
|
||||
string message = String.Format(
|
||||
Bloxstrap.Resources.Strings.Menu_FastFlagEditor_ConflictingImport,
|
||||
count,
|
||||
String.Join(", ", conflictingFlags.Take(25))
|
||||
);
|
||||
|
||||
if (count > 25)
|
||||
message += "...";
|
||||
|
||||
var result = Frontend.ShowMessageBox(message, MessageBoxImage.Question, MessageBoxButton.YesNo);
|
||||
|
||||
overwriteConflicting = result == MessageBoxResult.Yes;
|
||||
}
|
||||
|
||||
foreach (var pair in list)
|
||||
{
|
||||
if (App.FastFlags.Prop.ContainsKey(pair.Key) && !overwriteConflicting)
|
||||
continue;
|
||||
|
||||
App.FastFlags.SetValue(pair.Key, pair.Value);
|
||||
}
|
||||
|
||||
ClearSearch();
|
||||
}
|
||||
|
||||
// refresh list on page load to synchronize with preset page
|
||||
private void Page_Loaded(object sender, RoutedEventArgs e) => ReloadList();
|
||||
|
||||
@ -122,7 +283,7 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
|
||||
|
||||
if (App.FastFlags.GetValue(newName) is not null)
|
||||
{
|
||||
Frontend.ShowMessageBox("A FastFlag with this name already exists.", MessageBoxImage.Information);
|
||||
Frontend.ShowMessageBox(Bloxstrap.Resources.Strings.Menu_FastFlagEditor_AlreadyExists, MessageBoxImage.Information);
|
||||
e.Cancel = true;
|
||||
textbox.Text = oldName;
|
||||
return;
|
||||
@ -153,62 +314,7 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
|
||||
window.Navigate(typeof(FastFlagsPage));
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dialog = new AddFastFlagDialog();
|
||||
dialog.ShowDialog();
|
||||
|
||||
if (dialog.Result != MessageBoxResult.OK)
|
||||
return;
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
if (!name.Contains(_searchFilter))
|
||||
ClearSearch();
|
||||
|
||||
_fastFlagList.Add(entry);
|
||||
|
||||
App.FastFlags.SetValue(entry.Name, entry.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Frontend.ShowMessageBox("An entry for this FastFlag already exists.", MessageBoxImage.Information);
|
||||
|
||||
bool refresh = false;
|
||||
|
||||
if (!_showPresets && FastFlagManager.PresetFlags.Values.Contains(name))
|
||||
{
|
||||
TogglePresetsButton.IsChecked = true;
|
||||
_showPresets = true;
|
||||
refresh = true;
|
||||
}
|
||||
|
||||
if (!name.Contains(_searchFilter))
|
||||
{
|
||||
ClearSearch(false);
|
||||
refresh = true;
|
||||
}
|
||||
|
||||
if (refresh)
|
||||
ReloadList();
|
||||
|
||||
entry = _fastFlagList.Where(x => x.Name == name).FirstOrDefault();
|
||||
}
|
||||
|
||||
DataGrid.SelectedItem = entry;
|
||||
DataGrid.ScrollIntoView(entry);
|
||||
}
|
||||
private void AddButton_Click(object sender, RoutedEventArgs e) => ShowAddDialog();
|
||||
|
||||
private void DeleteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@ -233,79 +339,6 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
|
||||
ReloadList();
|
||||
}
|
||||
|
||||
private void ImportJSONButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string json = "";
|
||||
Dictionary<string, object>? list = null;
|
||||
|
||||
while (list is null)
|
||||
{
|
||||
var dialog = new BulkAddFastFlagDialog();
|
||||
dialog.JsonTextBox.Text = json;
|
||||
dialog.ShowDialog();
|
||||
|
||||
if (dialog.Result != MessageBoxResult.OK)
|
||||
return;
|
||||
|
||||
json = dialog.JsonTextBox.Text.Trim();
|
||||
|
||||
// autocorrect where possible
|
||||
if (!json.StartsWith('{'))
|
||||
json = '{' + json;
|
||||
|
||||
if (!json.EndsWith('}'))
|
||||
json += '}';
|
||||
|
||||
try
|
||||
{
|
||||
list = JsonSerializer.Deserialize<Dictionary<string, object>>(json);
|
||||
|
||||
if (list is null)
|
||||
throw new Exception("JSON deserialization returned null");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Frontend.ShowMessageBox(
|
||||
"The JSON you've entered does not appear to be valid. Please double check it and try again.\n" +
|
||||
"\n" +
|
||||
"More information:\n" +
|
||||
$"{ex.Message}",
|
||||
MessageBoxImage.Error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var conflictingFlags = App.FastFlags.Prop.Where(x => list.ContainsKey(x.Key)).Select(x => x.Key);
|
||||
bool overwriteConflicting = false;
|
||||
|
||||
if (conflictingFlags.Any())
|
||||
{
|
||||
int count = conflictingFlags.Count();
|
||||
|
||||
string message = "Some of the flags you are attempting to import already have set values. Would you like to overwrite their current values with the ones defined in the import?\n" +
|
||||
"\n" +
|
||||
$"There are {count} conflicting flag definitions:\n" +
|
||||
String.Join(", ", conflictingFlags.Take(25));
|
||||
|
||||
if (count > 25)
|
||||
message += "...";
|
||||
|
||||
var result = Frontend.ShowMessageBox(message, MessageBoxImage.Question, MessageBoxButton.YesNo);
|
||||
|
||||
overwriteConflicting = result == MessageBoxResult.Yes;
|
||||
}
|
||||
|
||||
foreach (var pair in list)
|
||||
{
|
||||
if (App.FastFlags.Prop.ContainsKey(pair.Key) && !overwriteConflicting)
|
||||
continue;
|
||||
|
||||
App.FastFlags.SetValue(pair.Key, pair.Value);
|
||||
}
|
||||
|
||||
ClearSearch();
|
||||
}
|
||||
|
||||
private void ExportJSONButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string json = JsonSerializer.Serialize(App.FastFlags.Prop, new JsonSerializerOptions { WriteIndented = true });
|
||||
|
Loading…
Reference in New Issue
Block a user