Can't force no untitled documents

redbird

Registered
Hopefully someone will be able to help me with this.

I am creating a document based Cocoa application. I have things set up pretty much as Apple gives them to you. I've filled in some document types that my program is supposed to take, etc.. The problem is, though, that my program is not supposed to create new documents, only read in existing ones. Alas, I can't seem to stop my program from creating a new one when I run it.

I tried making my application a viewer of all the types I read (which is fine, because I don't write output via the default methods in my NSDocument subclass), but it still opens a new document on start up. :-/

Any ideas?
 

ksuther

Registered
Try this:
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
return NO;
}

That should work.
 

redbird

Registered
Originally posted by ksuther
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
return NO;
}

Thanks, that did it. Guess I should have snooped around NSApplication more (I figured it was somewhere in there, but couldn't find it).
 

whitesaint

cocoa love
- (id)makeUntitledDocumentOfType:(NSString *)type

This method is found in the NSDocumentController class. Had the same problem before, this actually works.
 

redbird

Registered
On this topic, there's another thing I can't get working. I want my application to show the open file panel once it has finished loading. Since the open menu talks to the FirstResponder to do its openDocument, I thought I'd connect to the FirstResponder and run openDocument. Alas, IB wouldn't let me connect an outlet to the FirstResponder. Aside from doing the ugly thing is creating an outlet for the open menu and then calling it's target selector, how can I have my application run the open panel on startup?

I looked around NSApplication and didn't find anything. Where is this openDocument method being implemented, anyway?

BTW, thanks everyone here for being so helpful. I'm always happy at how this site can provide me with answers to questions like these so quickly, even when they aren't in the archives.
 

serving2masters

Registered
My memory is pretty hazy on this, but if I remember right, there's some kind of conspiracy between NSApplication, the application-wide NSOpenPanel, and your document class that does the openDocument: thing.

The way I would do this, which is admittedly sloppy, ugly, and likely immoral (but which saves programming time, and won't slow execution) is to actually connect to the "open" menu item and send it a "performClick:" message.
 
Top