Skip navigation.
 
mlRe: NSWrapper Plus Plain text files
FROM : Bill Garrison
DATE : Sat Mar 15 14:47:25 2008

Lincoln,

I'd refactor this so that you can take advantage of NSTextView's -
readRTFDFromFile: method.  It appears that you just want to get the 
NSTextView populated with some text.  You don't seem to be saving the 
RTF data for any other purpose.

Compiled in Mail.app:

NSString *filePath = ...;

BOOL isRTF = [type isEqualToString:@"Rich-Text With Attachments"] || 
[type isEqualToString:@"Rich-Text"];

if ( isRTF ) {
   BOOL didRead = [textView readRTFDFromFile:filePath];
   NSLog(@"did read RTF?: %@", didRead ? @"YES" : @"NO");
} else {
   [textView setString: [NSString stringWithContentsOfFile:filePath]];
   NSLog(@"did read plain text?: %@", [textView string] != nil ? 
@"YES" : @"NO");
}

Bill

On Mar 14, 2008, at 7:43 PM, Lincoln Green wrote:

> Hi, I am using loadFileWrapperRepresentation to implement a RTF/RTFD 
> reader. My code for RTF and RTFD support works, but I can't figure 
> out how to load in .txt files. the basic flow of the reader is, 
> determine the file type, set a NSAttributedString to a certain value 
> depending on the file type, and then load it into a textView. see 
> the following code.(rtfData is an NSAttributedString; textView is my 
> TextView).
>
>     if ([type isEqualToString:@"Rich-Text With Attachments"]) {
>           rtfData = [[NSAttributedString 
> alloc]initWithRTFDFileWrapper:wrapper documentAttributes:nil];
>     }
>     else if ([type isEqualToString:@"Rich-Text"]) {
>           rtfData = [[NSAttributedString alloc]initWithRTF:[wrapper 
> regularFileContents] documentAttributes:nil];
>     }
>     else
>     {


>         //code for plain text    
>     }
>
>    if (textView) {
>        [[textView 
> textStorage]replaceCharactersInRange:NSMakeRange(0, [[textView 
> string] length])withAttributedString:rtfData];
>        [rtfData release];
>    return YES;
>      }
> Any suggestions?

Related mailsAuthorDate
mlNSWrapper Plus Plain text files Lincoln Green Mar 15, 00:43
mlRe: NSWrapper Plus Plain text files Bill Garrison Mar 15, 14:47