-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXmlViewerPanel.axaml.cs
More file actions
32 lines (26 loc) · 1007 Bytes
/
XmlViewerPanel.axaml.cs
File metadata and controls
32 lines (26 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.Diagnostics.CodeAnalysis;
using Avalonia.Controls;
using AvaloniaEdit;
using AvaloniaEdit.TextMate;
using TextMateSharp.Grammars;
namespace SharpFM.Plugin.XmlViewer;
[ExcludeFromCodeCoverage]
public partial class XmlViewerPanel : UserControl
{
private TextMate.Installation? _textMateInstallation;
public XmlViewerPanel()
{
InitializeComponent();
var editor = this.FindControl<TextEditor>("xmlEditor");
if (editor is null) return;
var registryOptions = new RegistryOptions((ThemeName)(int)ThemeName.DarkPlus);
_textMateInstallation = editor.InstallTextMate(registryOptions);
var xmlLang = registryOptions.GetLanguageByExtension(".xml");
_textMateInstallation.SetGrammar(registryOptions.GetScopeByLanguageId(xmlLang.Id));
}
protected override void OnDetachedFromVisualTree(Avalonia.VisualTreeAttachmentEventArgs e)
{
base.OnDetachedFromVisualTree(e);
_textMateInstallation?.Dispose();
}
}