Skip to content

Commit

Permalink
Add exception handlers to TextMate loading
Browse files Browse the repository at this point in the history
  • Loading branch information
SKProCH committed Mar 28, 2024
1 parent c707246 commit d3d5d61
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Avalonia;
using Avalonia.Logging;
using Avalonia.LogicalTree;
using Avalonia.VisualTree;
using Avalonia.Xaml.Interactivity;
Expand All @@ -21,14 +22,24 @@ protected override void OnAttachedToVisualTree() {
var xamlDisplay = AssociatedObject.FindLogicalAncestorOfType<XamlDisplay>()!;
var themeName = xamlDisplay.GetValue(XamlDisplayAvaloniaEdit.CodeHighlightThemeNameProperty);

_registryOptions = new RegistryOptions(themeName);
_textMateInstallation = AssociatedObject!.InstallTextMate(_registryOptions);
_textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId("xml"));
try
{
_registryOptions = new RegistryOptions(themeName);
_textMateInstallation = AssociatedObject!.InstallTextMate(_registryOptions);
_textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId("xml"));

_disposable = xamlDisplay.GetObservable(XamlDisplayAvaloniaEdit.CodeHighlightThemeNameProperty)
.Subscribe(name => {
_textMateInstallation.SetTheme(_registryOptions.LoadTheme(name));
});
_disposable = xamlDisplay.GetObservable(XamlDisplayAvaloniaEdit.CodeHighlightThemeNameProperty)
.Subscribe(name => {
_textMateInstallation.SetTheme(_registryOptions.LoadTheme(name));
});
}
catch (Exception e)
{
if (Logger.TryGet(LogEventLevel.Warning, "ShowMeTheXaml.AvaloniaEdit", out var logger))
{
logger.Log(this, "TextMate highlighting can't be loaded. {Exception}", e);
}
}
}

/// <inheritdoc />
Expand Down

0 comments on commit d3d5d61

Please sign in to comment.