mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Allow flag JSON importing to be done by copy-paste
This commit is contained in:
parent
517546087c
commit
5f8e1401c7
@ -33,10 +33,10 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" MinWidth="100" Text="Flag name" Margin="0,0,0,12" />
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" MinWidth="100" Text="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" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" MinWidth="100" Text="Value" />
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Name="FlagValueTextBox" />
|
||||
</Grid>
|
||||
|
||||
|
60
Bloxstrap/UI/Elements/Dialogs/BulkAddFastFlagDialog.xaml
Normal file
60
Bloxstrap/UI/Elements/Dialogs/BulkAddFastFlagDialog.xaml
Normal file
@ -0,0 +1,60 @@
|
||||
<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"
|
||||
mc:Ignorable="d"
|
||||
Title="Import JSON"
|
||||
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="Import JSON" 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">
|
||||
<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>
|
||||
Paste in your JSON here...
|
||||
</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="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="Cancel" IsCancel="True" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ui:UiWindow>
|
35
Bloxstrap/UI/Elements/Dialogs/BulkAddFastFlagDialog.xaml.cs
Normal file
35
Bloxstrap/UI/Elements/Dialogs/BulkAddFastFlagDialog.xaml.cs
Normal file
@ -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 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -215,20 +215,38 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
|
||||
|
||||
private void ImportJSONButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dialog = new OpenFileDialog
|
||||
{
|
||||
Filter = "JSON files|*.json|All files|*.*"
|
||||
};
|
||||
string json = "";
|
||||
Dictionary<string, object>? list = null;
|
||||
|
||||
if (dialog.ShowDialog() != true)
|
||||
while (list is null)
|
||||
{
|
||||
var dialog = new BulkAddFastFlagDialog();
|
||||
dialog.JsonTextBox.Text = json;
|
||||
dialog.ShowDialog();
|
||||
|
||||
if (dialog.Result != MessageBoxResult.OK)
|
||||
return;
|
||||
|
||||
json = dialog.JsonTextBox.Text;
|
||||
|
||||
try
|
||||
{
|
||||
var list = JsonSerializer.Deserialize<Dictionary<string, object>>(File.ReadAllText(dialog.FileName));
|
||||
list = JsonSerializer.Deserialize<Dictionary<string, object>>(json);
|
||||
|
||||
if (list is null)
|
||||
throw new Exception("JSON deserialization returned null");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Controls.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;
|
||||
@ -257,17 +275,6 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
|
||||
|
||||
ClearSearch();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Controls.ShowMessageBox(
|
||||
"The file you've selected does not appear to be valid JSON. Please double check the file contents and try again.\n" +
|
||||
"\n" +
|
||||
"More information:\n" +
|
||||
$"{ex.Message}",
|
||||
MessageBoxImage.Error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user