readFromURL:url options: not working for me
readFromURL:url options: not working for me
- Subject: readFromURL:url options: not working for me
- From: David Rice <email@hidden>
- Date: Mon, 12 Jul 2004 12:24:45 -0400
I am trying to open an RTFD file in such a way as to display the
document's bg color.
Files that I save cannot be opened but the code works with Revert.
i.e. When I create a file, save it , change the open file and choose
Revert, the following code executes and the document reverts to the
saved version.
However, when this code is run upon Opening a file, the
"readFromURL:url" does not work.
Can someone shed some light on this. I just don't know what I'm doing
wrong.
- (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)docType
{
NSMutableDictionary *options = [NSMutableDictionary dictionary];
NSDictionary *docAttrs;
text = [textView textStorage];
NSLayoutManager *layoutManager = [textView layoutManager];
NSURL *url = [NSURL fileURLWithPath:fileName];
id val;
BOOL success = NO;
[options setObject:NSRTFDTextDocumentType forKey:@"DocumentType"];
[[text mutableString] setString:@""]; // Empty the document
[layoutManager retain]; // Temporarily remove layout mgr so it doesn't
work while loading
[text removeLayoutManager:layoutManager];
[text beginEditing]; // Bracket with begin/end editing for efficiency
success = [text readFromURL:url options:options
documentAttributes:&docAttrs]; // Read!
[text endEditing];
[text addLayoutManager:layoutManager]; // Hook layout manager back up
[layoutManager release];
if (!success) return NO;
if ((val = [docAttrs objectForKey:@"BackgroundColor"])) [textView
setBackgroundColor:val];
return YES;
}
Thanks,
David
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.