Skip to content

Commit 7a13991

Browse files
mooflufb-te
authored andcommitted
Simple RTF support via RichTextBox. (QL-Win#933)
* Simple RTF support via RichTextBox. * Minor tweaks to file extension checks. Co-authored-by: Frank Becker <frank.becker@thoughtexchange.com>
1 parent c685de0 commit 7a13991

File tree

1 file changed

+19
-4
lines changed
  • QuickLook.Plugin/QuickLook.Plugin.TextViewer

1 file changed

+19
-4
lines changed

QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs

+19-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Linq;
2121
using System.Reflection;
2222
using System.Windows;
23+
using System.Windows.Controls;
2324
using System.Xml;
2425
using ICSharpCode.AvalonEdit;
2526
using ICSharpCode.AvalonEdit.Highlighting;
@@ -66,7 +67,7 @@ public bool CanHandle(string path)
6667
if (Directory.Exists(path))
6768
return false;
6869

69-
if (path.ToLower().EndsWith(".txt"))
70+
if (new[] { ".txt", ".rtf" }.Any(path.ToLower().EndsWith))
7071
return true;
7172

7273
// if there is a matched highlighting scheme (by file extension), treat it as a plain text file
@@ -93,9 +94,23 @@ public void Prepare(string path, ContextObject context)
9394

9495
public void View(string path, ContextObject context)
9596
{
96-
_tvp = new TextViewerPanel(path, context);
97-
98-
context.ViewerContent = _tvp;
97+
if (path.ToLower().EndsWith(".rtf"))
98+
{
99+
var rtfBox = new RichTextBox();
100+
FileStream fs = File.OpenRead(path);
101+
rtfBox.Selection.Load(fs, DataFormats.Rtf);
102+
rtfBox.IsReadOnly = true;
103+
rtfBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
104+
rtfBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
105+
106+
context.ViewerContent = rtfBox;
107+
context.IsBusy = false;
108+
}
109+
else
110+
{
111+
_tvp = new TextViewerPanel(path, context);
112+
context.ViewerContent = _tvp;
113+
}
99114
context.Title = $"{Path.GetFileName(path)}";
100115
}
101116

0 commit comments

Comments
 (0)