-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCodeFilePreviewHandler.cs
More file actions
52 lines (38 loc) · 1.65 KB
/
CodeFilePreviewHandler.cs
File metadata and controls
52 lines (38 loc) · 1.65 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
using System.IO;
using System.Windows.Media;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Highlighting;
using WinQuickLook.Extensions;
namespace WinQuickLook.Handlers;
public class CodeFilePreviewHandler : FilePreviewHandler
{
static CodeFilePreviewHandler()
{
var highlightingManager = HighlightingManager.Instance;
highlightingManager.RegisterHighlighting("TypeScript", [".ts", ".tsx"], highlightingManager.GetDefinitionByExtension(".js"));
highlightingManager.RegisterHighlighting("Vue", [".vue"], highlightingManager.GetDefinitionByExtension(".html"));
highlightingManager.RegisterHighlighting("JavaScript Extended", [".cjs", ".mjs"], highlightingManager.GetDefinitionByExtension(".js"));
}
public override HandlerPriorityClass PriorityClass => HandlerPriorityClass.AboveNormal;
protected override bool TryCreateViewer(FileInfo fileInfo, out HandlerResult? handlerResult)
{
var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(fileInfo.Extension);
if (highlighting is null)
{
handlerResult = default;
return false;
}
var textEditor = new TextEditor();
using (textEditor.Initialize())
{
textEditor.FontFamily = new FontFamily("Consolas");
textEditor.FontSize = 14;
textEditor.IsReadOnly = true;
textEditor.ShowLineNumbers = true;
textEditor.SyntaxHighlighting = highlighting;
textEditor.Load(fileInfo.OpenReadNoLock());
}
handlerResult = new HandlerResult { Content = textEditor };
return true;
}
}