Re: How to get an NSWindow from an NSDocument?
Re: How to get an NSWindow from an NSDocument?
- Subject: Re: How to get an NSWindow from an NSDocument?
- From: Scott Ellsworth <email@hidden>
- Date: Thu, 26 May 2005 15:02:30 -0700
On May 23, 2005, at 5:30 PM, mmalcolm crawford wrote:
On May 23, 2005, at 1:55 PM, Scott Ellsworth wrote:
The following code is part of a Core Data app that can also read
and write "Tab Delimited Sector" and "Sector" files, but since
those are lossy, I want an 'untitled' window to show up when you
open one.
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)
typeName error:(NSError **)outError{
Modulo my gaffe regarding file wrappers, this seems like an
"unusual" approach to take -- assuming you're subclassing
NSPersistentDocument?
I am.
You almost certainly should be overriding - (BOOL)
configurePersistentStoreCoordinatorForURL:(NSURL *)url ofType:
(NSString *)fileType error:(NSError **)error (and - (id)
initWithType:(NSString *)type error:(NSError **)error) and setting
up an in-memory store...
If my current implementation, stripped of error checking, looks like:
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName
error:(NSError **)outError{
if ([typeName isEqualToString:@"Tab Delimited Sector"]){
NSString * data = [NSString
stringWithContentsOfURL:absoluteURL
encoding:NSMacOSRomanStringEncoding error:outError];
[self setFromString:data];
} else {
[super readFromURL...]
}
}
Would I implement this new approach by:
NSString * readData
configurePersistent...{
if ([typeName isEqualToString:@"Tab Delimited Sector"]){
// create new persistent store as needed
readData = [NSString stringWithContentsOfURL:absoluteURL
encoding:NSMacOSRomanStringEncoding error:outError];
} else {
[super configurePersistent...];
}
}
And then init would look like:
initWithType...{
if ([typeName isEqualToString:@"Tab Delimited Sector"]){
[self setFromString:readData];
} else {
[super initWithType...
}
I note that my current implementation has an init method, but does
not override initWithType. I shall have to look into this to see why
I did it that way.
Would the new in-memory store show up as an untitled window, which
will cause Save to look up a file name, as it does for other untitled
windows?
Scott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden