On Apr 30, 2010, at 08:56, Brad Stone wrote:
> I want to open NSPersistentDocuments and load them into the same window one
> at a time.
Excuse the soapbox, but you do realize that from the outside looking in, this
*seems* like a terrible idea? If your documents really are documents in the
user interface sense, then what's the reason for inventing a new
document-handling metaphor for users? If they're not really documents, then why
try to shoehorn them into the NSDocument metaphor?
Keep in mind that Core Data persistent stores don't really fit the standard
document metaphor very well, so that NSPersistentDocument is already a little
bit broken. (Ask the people who've had trouble with Save As, for example.)
Piling on another layer of metaphorical abuse seems like a prescription for
great pain. But anyway ...
> - (IBAction)newBookTwo:(id)sender {
> NSDocumentController *dc = [NSDocumentController
> sharedDocumentController];
> NSURL *url = [NSURL fileURLWithPath:[@"~/Desktop/File 2.binary"
> stringByExpandingTildeInPath]];
>
> NSError *error;
> MainWindowDocument *thisDoc = [dc openDocumentWithContentsOfURL:url
> display:NO error:&error];
>
> [self setDocument:thisDoc];
> [self setManagedObjectContext:[thisDoc managedObjectContext]];
> }
Here's what I'd try (apologies if you've tried this already; all typed in mail):
1. Create a global variable:
MyWindowController* recycledWindowController = nil;
2. In the window controller:
- (IBAction)newBookTwo:(id)sender {
NSDocumentController *dc = [NSDocumentController
sharedDocumentController];
NSURL *url = [NSURL fileURLWithPath:[@"~/Desktop/File 2.binary"
stringByExpandingTildeInPath]];
recycledWindowController = self;
[self.document removeWindowController: self];
NSError *error;
MainWindowDocument *thisDoc = [dc openDocumentWithContentsOfURL:url
display:NO error:&error];
}
3. In the document:
- (void) makeWindowControllers {
if (! recycledWindowController) {
recycledWindowController = ... // create a new window controller
recycledWindowController.shouldCloseDocument = YES;
}
[self addWindowController: recycledWindowController];
[recycledWindowController noteChangedDocument]; // or send a
notification, or have the window controller KVO-observe its own 'document'
property
recycledWindowController = nil;
}
Something like that.
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]