From 1e5de83f6247459abc702f62f6a8cfbac6bf4a40 Mon Sep 17 00:00:00 2001 From: Frank Becker Date: Thu, 17 Jun 2021 09:27:57 -0700 Subject: [PATCH] Simple RTF support via RichTextBox. (#933) * Simple RTF support via RichTextBox. * Minor tweaks to file extension checks. Co-authored-by: Frank Becker --- .../QuickLook.Plugin.TextViewer/Plugin.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs index 3ca0200..4cb3846 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs @@ -20,6 +20,7 @@ using System.IO; using System.Linq; using System.Reflection; using System.Windows; +using System.Windows.Controls; using System.Xml; using ICSharpCode.AvalonEdit; using ICSharpCode.AvalonEdit.Highlighting; @@ -66,7 +67,7 @@ namespace QuickLook.Plugin.TextViewer 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 @@ -93,9 +94,23 @@ namespace QuickLook.Plugin.TextViewer public void View(string path, ContextObject context) { - _tvp = new TextViewerPanel(path, context); + 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 = _tvp; + context.ViewerContent = rtfBox; + context.IsBusy = false; + } + else + { + _tvp = new TextViewerPanel(path, context); + context.ViewerContent = _tvp; + } context.Title = $"{Path.GetFileName(path)}"; }