Re: NSWrapper Plus Plain text files
Re: NSWrapper Plus Plain text files
- Subject: Re: NSWrapper Plus Plain text files
- From: Bill Garrison <email@hidden>
- Date: Sat, 15 Mar 2008 09:47:25 -0400
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?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden