Skip to content

Commit fb54b8c

Browse files
authored
Add syntax highlight (#4)
* Add syntax highlight handler * Change to AvalonEdit * add nuget restore * fix solution path * skip build UWP package
1 parent 4b253e6 commit fb54b8c

5 files changed

+48
-1
lines changed

appveyor.yml

+4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ platform: Any CPU
2424

2525
configuration: Release
2626

27+
before_build:
28+
- nuget restore .\src\WinQuickLook.sln
29+
2730
build:
31+
project: .\src\WinQuickLook\WinQuickLook.csproj
2832
verbosity: minimal
2933

3034
artifacts:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.IO;
2+
using System.Windows;
3+
using System.Windows.Media;
4+
5+
using ICSharpCode.AvalonEdit.Highlighting;
6+
7+
namespace WinQuickLook.Handlers
8+
{
9+
public class SyntaxHighlightPreviewHandler : PreviewHandlerBase
10+
{
11+
public override bool CanOpen(string fileName)
12+
{
13+
return HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName)) != null;
14+
}
15+
16+
public override FrameworkElement GetElement(string fileName)
17+
{
18+
var avalonEdit = new ICSharpCode.AvalonEdit.TextEditor();
19+
20+
avalonEdit.BeginInit();
21+
22+
avalonEdit.FontFamily = new FontFamily("Consolas");
23+
avalonEdit.FontSize = 14;
24+
avalonEdit.IsReadOnly = true;
25+
avalonEdit.Load(fileName);
26+
avalonEdit.SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName));
27+
28+
avalonEdit.EndInit();
29+
30+
return avalonEdit;
31+
}
32+
}
33+
}

src/WinQuickLook/QuickLookWindow.xaml.cs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public QuickLookWindow()
3939
new VideoPreviewHandler(),
4040
new AudioPreviewHandler(),
4141
new HtmlPreviewHandler(),
42+
new SyntaxHighlightPreviewHandler(),
4243
new TextPreviewHandler(),
4344
new ComInteropPreviewHandler(),
4445
new GenericPreviewHandler()

src/WinQuickLook/WinQuickLook.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
<ApplicationManifest>app.manifest</ApplicationManifest>
4343
</PropertyGroup>
4444
<ItemGroup>
45+
<Reference Include="ICSharpCode.AvalonEdit, Version=5.0.3.0, Culture=neutral, PublicKeyToken=9cc39be672370310, processorArchitecture=MSIL">
46+
<HintPath>..\packages\AvalonEdit.5.0.3\lib\Net40\ICSharpCode.AvalonEdit.dll</HintPath>
47+
<Private>True</Private>
48+
</Reference>
4549
<Reference Include="System" />
4650
<Reference Include="System.Drawing" />
4751
<Reference Include="System.Windows.Forms" />
@@ -77,6 +81,7 @@
7781
<Compile Include="Converters\FileNameToTypeNameConverter.cs" />
7882
<Compile Include="Converters\FileInfoToFileSizeConverter.cs" />
7983
<Compile Include="Handlers\AudioPreviewHandler.cs" />
84+
<Compile Include="Handlers\SyntaxHighlightPreviewHandler.cs" />
8085
<Compile Include="Handlers\ComInteropPreviewHandler.cs" />
8186
<Compile Include="Handlers\HtmlPreviewHandler.cs" />
8287
<Compile Include="Handlers\ImagePreviewHandler.cs" />
@@ -129,6 +134,7 @@
129134
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
130135
</EmbeddedResource>
131136
<None Include="app.manifest" />
137+
<None Include="packages.config" />
132138
<None Include="Properties\Settings.settings">
133139
<Generator>SettingsSingleFileGenerator</Generator>
134140
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -159,7 +165,6 @@
159165
<ItemGroup>
160166
<Resource Include="Icon.ico" />
161167
</ItemGroup>
162-
<ItemGroup />
163168
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
164169
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
165170
Other similar extension points exist, see Microsoft.Common.targets.

src/WinQuickLook/packages.config

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="AvalonEdit" version="5.0.3" targetFramework="net461" />
4+
</packages>

0 commit comments

Comments
 (0)