20
20
using System . Linq ;
21
21
using System . Reflection ;
22
22
using System . Windows ;
23
+ using System . Windows . Controls ;
23
24
using System . Xml ;
24
25
using ICSharpCode . AvalonEdit ;
25
26
using ICSharpCode . AvalonEdit . Highlighting ;
@@ -66,7 +67,7 @@ public bool CanHandle(string path)
66
67
if ( Directory . Exists ( path ) )
67
68
return false ;
68
69
69
- if ( path . ToLower ( ) . EndsWith ( ".txt" ) )
70
+ if ( new [ ] { ".txt" , ".rtf" } . Any ( path . ToLower ( ) . EndsWith ) )
70
71
return true ;
71
72
72
73
// 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)
93
94
94
95
public void View ( string path , ContextObject context )
95
96
{
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
+ }
99
114
context . Title = $ "{ Path . GetFileName ( path ) } ";
100
115
}
101
116
0 commit comments