2024-03-20 04:49:01 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2024-03-20 03:27:48 -07:00
|
|
|
|
|
|
|
|
|
using Avalonia.Styling;
|
|
|
|
|
|
|
|
|
|
using AvaloniaEdit;
|
|
|
|
|
using AvaloniaEdit.TextMate;
|
|
|
|
|
|
|
|
|
|
using TextMateSharp.Grammars;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.Models
|
|
|
|
|
{
|
|
|
|
|
public static class TextMateHelper
|
|
|
|
|
{
|
|
|
|
|
public static TextMate.Installation CreateForEditor(TextEditor editor)
|
|
|
|
|
{
|
|
|
|
|
if (App.Current?.ActualThemeVariant == ThemeVariant.Dark)
|
|
|
|
|
{
|
|
|
|
|
return editor.InstallTextMate(new RegistryOptions(ThemeName.DarkPlus));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return editor.InstallTextMate(new RegistryOptions(ThemeName.LightPlus));
|
2024-03-21 06:08:30 -07:00
|
|
|
|
}
|
2024-03-20 03:27:48 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetThemeByApp(TextMate.Installation installation)
|
|
|
|
|
{
|
|
|
|
|
if (installation == null) return;
|
|
|
|
|
|
|
|
|
|
var reg = installation.RegistryOptions as RegistryOptions;
|
|
|
|
|
if (App.Current?.ActualThemeVariant == ThemeVariant.Dark)
|
|
|
|
|
{
|
|
|
|
|
installation.SetTheme(reg.LoadTheme(ThemeName.DarkPlus));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
installation.SetTheme(reg.LoadTheme(ThemeName.LightPlus));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetGrammarByFileName(TextMate.Installation installation, string filePath)
|
|
|
|
|
{
|
|
|
|
|
if (installation == null) return;
|
|
|
|
|
|
|
|
|
|
var ext = Path.GetExtension(filePath);
|
|
|
|
|
if (ext == ".h")
|
|
|
|
|
{
|
|
|
|
|
ext = ".cpp";
|
|
|
|
|
}
|
|
|
|
|
else if (ext == ".resx")
|
|
|
|
|
{
|
|
|
|
|
ext = ".xml";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var reg = installation.RegistryOptions as RegistryOptions;
|
|
|
|
|
installation.SetGrammar(reg.GetScopeByExtension(ext));
|
2024-03-20 04:49:01 -07:00
|
|
|
|
GC.Collect();
|
2024-03-20 03:27:48 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-21 06:08:30 -07:00
|
|
|
|
}
|