mirror of
https://github.com/2dust/v2rayN.git
synced 2026-04-16 12:35:46 +00:00
Remove TextMateSharp.Grammars
This commit is contained in:
parent
4f73f31d73
commit
868efa6574
3 changed files with 40 additions and 13 deletions
|
|
@ -9,7 +9,6 @@
|
|||
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.3.12" />
|
||||
<PackageVersion Include="Avalonia.Desktop" Version="11.3.12" />
|
||||
<PackageVersion Include="Avalonia.Diagnostics" Version="11.3.12" />
|
||||
<PackageVersion Include="AvaloniaEdit.TextMate" Version="11.4.1" />
|
||||
<PackageVersion Include="ReactiveUI.Avalonia" Version="11.4.12" />
|
||||
<PackageVersion Include="CliWrap" Version="3.10.0" />
|
||||
<PackageVersion Include="Downloader" Version="5.1.0" />
|
||||
|
|
@ -26,7 +25,6 @@
|
|||
<PackageVersion Include="NLog" Version="6.1.1" />
|
||||
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
<PackageVersion Include="TaskScheduler" Version="2.12.2" />
|
||||
<PackageVersion Include="TextMateSharp.Grammars" Version="2.0.3" />
|
||||
<PackageVersion Include="WebDav.Client" Version="2.9.0" />
|
||||
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
|
||||
<PackageVersion Include="ZXing.Net.Bindings.SkiaSharp" Version="0.16.14" />
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Text.Json;
|
||||
using AvaloniaEdit.TextMate;
|
||||
using TextMateSharp.Grammars;
|
||||
using System.Xml;
|
||||
using AvaloniaEdit.Highlighting;
|
||||
using AvaloniaEdit.Highlighting.Xshd;
|
||||
|
||||
namespace v2rayN.Desktop.Views;
|
||||
|
||||
|
|
@ -8,19 +9,49 @@ public partial class JsonEditor : UserControl
|
|||
{
|
||||
private static readonly JsonSerializerOptions SIndentedOptions = new() { WriteIndented = true };
|
||||
|
||||
private static readonly Lazy<IHighlightingDefinition> SHighlightingDark =
|
||||
new(() => BuildHighlighting(dark: true), isThreadSafe: true);
|
||||
|
||||
private static readonly Lazy<IHighlightingDefinition> SHighlightingLight =
|
||||
new(() => BuildHighlighting(dark: false), isThreadSafe: true);
|
||||
|
||||
public JsonEditor()
|
||||
{
|
||||
InitializeComponent();
|
||||
var currentTheme = Application.Current?.ActualThemeVariant;
|
||||
var themeName = currentTheme == ThemeVariant.Dark ? ThemeName.DarkPlus :
|
||||
currentTheme == ThemeVariant.Light ? ThemeName.LightPlus :
|
||||
ThemeName.DarkPlus;
|
||||
var jsonRegistryOptions = new RegistryOptions(themeName);
|
||||
var grammarScopeName = jsonRegistryOptions.GetScopeByLanguageId(jsonRegistryOptions.GetLanguageByExtension(".json").Id);
|
||||
Editor.InstallTextMate(jsonRegistryOptions).SetGrammar(grammarScopeName);
|
||||
var isDark = Application.Current?.ActualThemeVariant != ThemeVariant.Light;
|
||||
Editor.SyntaxHighlighting = isDark ? SHighlightingDark.Value : SHighlightingLight.Value;
|
||||
Editor.TextArea.TextView.Options.EnableHyperlinks = false;
|
||||
}
|
||||
|
||||
private static IHighlightingDefinition BuildHighlighting(bool dark)
|
||||
{
|
||||
var keyColor = dark ? "#9CDCFE" : "#0451A5";
|
||||
var strColor = dark ? "#CE9178" : "#A31515";
|
||||
var numColor = dark ? "#B5CEA8" : "#098658";
|
||||
var kwColor = dark ? "#569CD6" : "#0000FF";
|
||||
var xshd = $"""
|
||||
<?xml version="1.0"?>
|
||||
<SyntaxDefinition name="JSON" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
|
||||
<Color name="Key" foreground="{keyColor}" />
|
||||
<Color name="String" foreground="{strColor}" />
|
||||
<Color name="Number" foreground="{numColor}" />
|
||||
<Color name="Keyword" foreground="{kwColor}" fontWeight="bold" />
|
||||
<RuleSet>
|
||||
<Rule color="Key">"([^"\\]|\\.)*"(?=\s*:)</Rule>
|
||||
<Rule color="String">"([^"\\]|\\.)*"</Rule>
|
||||
<Rule color="Number">-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?</Rule>
|
||||
<Keywords color="Keyword">
|
||||
<Word>true</Word>
|
||||
<Word>false</Word>
|
||||
<Word>null</Word>
|
||||
</Keywords>
|
||||
</RuleSet>
|
||||
</SyntaxDefinition>
|
||||
""";
|
||||
using var reader = XmlReader.Create(new StringReader(xshd));
|
||||
return HighlightingLoader.Load(reader, HighlightingManager.Instance);
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get => Editor.Text;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
</PackageReference>
|
||||
<PackageReference Include="Avalonia.Desktop" />
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" />
|
||||
<PackageReference Include="AvaloniaEdit.TextMate" />
|
||||
<PackageReference Include="ReactiveUI.Avalonia" />
|
||||
<PackageReference Include="MessageBox.Avalonia" />
|
||||
<PackageReference Include="Semi.Avalonia" />
|
||||
|
|
@ -29,7 +28,6 @@
|
|||
<PackageReference Include="ReactiveUI.Fody">
|
||||
<TreatAsUsed>true</TreatAsUsed>
|
||||
</PackageReference>
|
||||
<PackageReference Include="TextMateSharp.Grammars" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in a new issue