mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Add ability to import FastFlags from JSON
This commit is contained in:
parent
e0fcbaab2f
commit
b651be7024
@ -34,6 +34,7 @@
|
|||||||
</ui:Button.Style>
|
</ui:Button.Style>
|
||||||
</ui:Button>
|
</ui:Button>
|
||||||
<ToggleButton x:Name="TogglePresetsButton" Content="Show preset flags" Click="ToggleButton_Click" Margin="12,0,0,0" />
|
<ToggleButton x:Name="TogglePresetsButton" Content="Show preset flags" Click="ToggleButton_Click" Margin="12,0,0,0" />
|
||||||
|
<ui:Button Icon="ArrowImport24" Content="Import JSON" Margin="12,0,0,0" Click="ImportJSONButton_Click" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<ui:TextBox x:Name="SearchTextBox" Grid.Row="2" Margin="0,0,0,16" Icon="Search32" PlaceholderText="Search" TextChanged="SearchTextBox_TextChanged" />
|
<ui:TextBox x:Name="SearchTextBox" Grid.Row="2" Margin="0,0,0,16" Icon="Search32" PlaceholderText="Search" TextChanged="SearchTextBox_TextChanged" />
|
||||||
|
@ -3,6 +3,8 @@ using System.Windows;
|
|||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Controls.Primitives;
|
using System.Windows.Controls.Primitives;
|
||||||
|
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
using Wpf.Ui.Mvvm.Contracts;
|
using Wpf.Ui.Mvvm.Contracts;
|
||||||
|
|
||||||
using Bloxstrap.UI.Elements.Dialogs;
|
using Bloxstrap.UI.Elements.Dialogs;
|
||||||
@ -211,6 +213,63 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
|
|||||||
ReloadList();
|
ReloadList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ImportJSONButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var dialog = new OpenFileDialog
|
||||||
|
{
|
||||||
|
Filter = "JSON files|*.json|All files|*.*"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dialog.ShowDialog() != true)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = JsonSerializer.Deserialize<Dictionary<string, object>>(File.ReadAllText(dialog.FileName));
|
||||||
|
|
||||||
|
if (list is null)
|
||||||
|
throw new Exception("JSON deserialization returned null");
|
||||||
|
|
||||||
|
var conflictingFlags = App.FastFlags.Prop.Where(x => list.ContainsKey(x.Key)).Select(x => x.Key);
|
||||||
|
bool overwriteConflicting = false;
|
||||||
|
|
||||||
|
if (conflictingFlags.Any())
|
||||||
|
{
|
||||||
|
var result = Controls.ShowMessageBox(
|
||||||
|
"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" +
|
||||||
|
"Conflicting flags:\n" +
|
||||||
|
String.Join(", ", conflictingFlags),
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
_searchFilter = "";
|
||||||
|
ReloadList();
|
||||||
|
}
|
||||||
|
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)
|
private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is not TextBox textbox)
|
if (sender is not TextBox textbox)
|
||||||
|
Loading…
Reference in New Issue
Block a user