You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.6 KiB

using System.Collections.ObjectModel;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Xml;
using HandyControl.Controls;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using SparkClient.Model.Entity;
using SparkClient.ViewModel.Configuration;
namespace SparkClient.Views.Configuration;
public partial class AlgorithmConfigPage
{
public AlgorithmConfigPage()
{
InitializeComponent();
DataContext = new AlgorithmConfigVM();
using (Stream stream = typeof(MainWindow).Assembly.GetManifestResourceStream(@"SparkClient.Resource.Other.Json-Mode-Default.xshd"))
using (XmlReader reader = new XmlTextReader(stream))
{
IHighlightingDefinition highlightingDefinition = HighlightingLoader.Load(reader, HighlightingManager.Instance);
HighlightingManager.Instance.RegisterHighlighting("JSON Highlighting", new string[] { ".json" }, highlightingDefinition);
TextEditor.SyntaxHighlighting = highlightingDefinition;
}
if (DataContext is AlgorithmConfigVM vm)
{
TextEditor.Text = vm.AlgorithmConfigJson;
vm.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(vm.AlgorithmConfigJson))
{
if (TextEditor.Text != vm.AlgorithmConfigJson)
{
TextEditor.Text = vm.AlgorithmConfigJson;
}
}
};
}
}
private void TextEditor_OnTextChanged(object? sender, EventArgs e)
{
if(DataContext is AlgorithmConfigVM vm)
vm.AlgorithmConfigJson = TextEditor.Text;
}
private void ButtonAddRow_OnClick(object sender, RoutedEventArgs e)
{
// List<string> jKeys = new List<string>();
// if (AgileJsonDataGrid.ItemsSource is List<AgileJsonConfigEntity> entities)
// {
// jKeys = entities.FirstOrDefault().JsonKeys;
// entities.Add(new AgileJsonConfigEntity(jKeys));
// AgileJsonDataGrid.ItemsSource = entities;
// }
}
private void ButtonDelRow_OnClick(object sender, RoutedEventArgs e)
{
if (AgileJsonDataGrid.ItemsSource is ObservableCollection<AgileJsonConfigEntity> entities)
{
if (AgileJsonDataGrid.SelectedItem is AgileJsonConfigEntity entity)
{
entities.Remove(entity);
}
AgileJsonDataGrid.ItemsSource = entities;
}
}
}