diff --git a/Language/zh_CN.xaml b/Language/zh_CN.xaml
index c41e720..4702bef 100644
--- a/Language/zh_CN.xaml
+++ b/Language/zh_CN.xaml
@@ -23,6 +23,8 @@
删除配置
导入配置
+ 美化Json
+ 压缩Json
是否退出程序?
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 7835d91..dc02990 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -100,12 +100,12 @@
diff --git a/Resource/Other/Json-Mode-Default.xshd b/Resource/Other/Json-Mode-Default.xshd
new file mode 100644
index 0000000..3f3837a
--- /dev/null
+++ b/Resource/Other/Json-Mode-Default.xshd
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "
+ "
+
+
+ '
+ '
+
+
+ :
+
+
+ ,
+
+
+
+
+
+
+ ,
+
+
+
+
+
+ true
+ false
+
+
+ null
+
+
+ "
+ "
+
+
+ '
+ '
+
+
+ \{
+ \}
+
+
+ \[
+ \]
+
+
+ \b0[xX][0-9a-fA-F]+|(\b\d+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SparkClient.csproj b/SparkClient.csproj
index 8b02262..be710d8 100644
--- a/SparkClient.csproj
+++ b/SparkClient.csproj
@@ -9,6 +9,7 @@
+
@@ -54,6 +55,8 @@
Always
+
+
diff --git a/ViewModel/Configuration/AlgorithmConfigVM.cs b/ViewModel/Configuration/AlgorithmConfigVM.cs
index badb4ec..92d1837 100644
--- a/ViewModel/Configuration/AlgorithmConfigVM.cs
+++ b/ViewModel/Configuration/AlgorithmConfigVM.cs
@@ -1,13 +1,25 @@
-namespace SparkClient.ViewModel.Configuration;
+using System.Windows.Input;
+using HandyControl.Controls;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace SparkClient.ViewModel.Configuration;
public class AlgorithmConfigVM : BaseViewModel
{
-
+ public ICommand SaveAlgorithmDataCommand { get; }
+ public ICommand BeautifyJsonCommand { get; }
+ public ICommand UglifyJsonCommand { get; }
+
+
+ private string _AlgorithmConfigJson;
+ public string AlgorithmConfigJson { get { return _AlgorithmConfigJson; } set { _AlgorithmConfigJson = value; OnPropertyChanged("AlgorithmConfigJson"); } }
public AlgorithmConfigVM()
{
- // 初始化VIEW层参数
- // 初始化VIEW层Command
- this.InitAlgorithmData(null);
+ SaveAlgorithmDataCommand = new RelayCommand(SaveAlgorithmData);
+ BeautifyJsonCommand = new RelayCommand(BeautifyJson);
+ UglifyJsonCommand = new RelayCommand(UglifyJson);
+ InitAlgorithmData(null);
}
///
@@ -16,33 +28,45 @@ public class AlgorithmConfigVM : BaseViewModel
///
public void InitAlgorithmData(object param)
{
+ AlgorithmConfigJson = "{}";
}
+
///
- /// 添加行
+ /// 保存数据
///
- /// 行数
- public void AddRows(object row)
+ ///
+ public void SaveAlgorithmData(object param)
{
-
+ Growl.Info("Saving Algorithm Data");
}
///
- /// 保存数据
+ /// 梅花JSON
///
///
- public void SaveAlgorithmData(object param)
+ public void BeautifyJson(object param)
{
-
+ try
+ {
+ AlgorithmConfigJson = JToken.Parse(AlgorithmConfigJson).ToString();
+ }
+ catch (Exception ex)
+ {
+ Growl.Error(ex.Message);
+ }
+
+
}
///
- /// 删除一行数据
+ /// 压缩JSON
///
- /// 行
- public void DelAlgorRow(object row)
+ ///
+ public void UglifyJson(object param)
{
-
+ AlgorithmConfigJson = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(AlgorithmConfigJson));
}
+
}
\ No newline at end of file
diff --git a/Views/Configuration/AlgorithmConfigPage.xaml b/Views/Configuration/AlgorithmConfigPage.xaml
index dc78983..7832b60 100644
--- a/Views/Configuration/AlgorithmConfigPage.xaml
+++ b/Views/Configuration/AlgorithmConfigPage.xaml
@@ -3,10 +3,45 @@
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:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:SparkClient.Views"
+ xmlns:configuration="clr-namespace:SparkClient.Views.Configuration"
mc:Ignorable="d"
>
-
- 算法配置
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Views/Configuration/AlgorithmConfigPage.xaml.cs b/Views/Configuration/AlgorithmConfigPage.xaml.cs
index 06bd872..543731b 100644
--- a/Views/Configuration/AlgorithmConfigPage.xaml.cs
+++ b/Views/Configuration/AlgorithmConfigPage.xaml.cs
@@ -1,11 +1,51 @@
-using System.Windows.Controls;
+using System.IO;
+using System.Reflection;
+using System.Windows;
+using System.Windows.Controls;
+using System.Xml;
+using ICSharpCode.AvalonEdit;
+using ICSharpCode.AvalonEdit.Highlighting;
+using ICSharpCode.AvalonEdit.Highlighting.Xshd;
+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;
+
}
-}
\ No newline at end of file
+}
diff --git a/Views/Configuration/ConfigMenuPage.xaml.cs b/Views/Configuration/ConfigMenuPage.xaml.cs
index 61df299..9f9f9ab 100644
--- a/Views/Configuration/ConfigMenuPage.xaml.cs
+++ b/Views/Configuration/ConfigMenuPage.xaml.cs
@@ -1,4 +1,4 @@
-using System.Drawing;
+
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;