Skip to content

Commit

Permalink
Simple RTF support via RichTextBox. (QL-Win#933)
Browse files Browse the repository at this point in the history
* Simple RTF support via RichTextBox.

* Minor tweaks to file extension checks.

Co-authored-by: Frank Becker <[email protected]>
  • Loading branch information
mooflu and fb-te authored Jun 17, 2021
1 parent df66c42 commit 1e5de83
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Xml;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Highlighting;
Expand Down Expand Up @@ -66,7 +67,7 @@ public bool CanHandle(string path)
if (Directory.Exists(path))
return false;

if (path.ToLower().EndsWith(".txt"))
if (new[] { ".txt", ".rtf" }.Any(path.ToLower().EndsWith))
return true;

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

public void View(string path, ContextObject context)
{
_tvp = new TextViewerPanel(path, context);

context.ViewerContent = _tvp;
if (path.ToLower().EndsWith(".rtf"))
{
var rtfBox = new RichTextBox();
FileStream fs = File.OpenRead(path);
rtfBox.Selection.Load(fs, DataFormats.Rtf);
rtfBox.IsReadOnly = true;
rtfBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
rtfBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;

context.ViewerContent = rtfBox;
context.IsBusy = false;
}
else
{
_tvp = new TextViewerPanel(path, context);
context.ViewerContent = _tvp;
}
context.Title = $"{Path.GetFileName(path)}";
}

Expand Down

0 comments on commit 1e5de83

Please sign in to comment.