forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextMateHelper.cs
More file actions
63 lines (54 loc) · 1.73 KB
/
Copy pathTextMateHelper.cs
File metadata and controls
63 lines (54 loc) · 1.73 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.IO;
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));
}
}
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 == ".plist")
{
ext = ".xml";
}
var reg = installation.RegistryOptions as RegistryOptions;
installation.SetGrammar(reg.GetScopeByExtension(ext));
GC.Collect();
}
}
}