On 07/03/2009, at 4:41 AM, Sean McBride wrote:

I actually used a DTS incident on this very issue.  As you say, it is
hard to get exactly right (if you want finesse).  In the end, I got
about 90% of the way to perfect.

I ended up doing the following:

- subclassing NSDocumentController
- giving it 2 modes: normal and queuing
- in normal mode it works like super
- in queuing mode, I queue any kAEPrintDocuments and kAEOpenDocuments
that I receive
- I set it to queue mode in applicationWillFinishLaunching (which is
before any kAEPrintDocuments/kAEOpenDocuments arrive)
- in applicationDidFinishLaunching I show my splash screen
- at this point the user may try to open or print documents, but I don't
want them to appear, but nor do I want them to be lost
- when OK is clicked in the splash screen, I end queuing mode and
process items in the queue
- if there are no items in the queue I call [self
openUntitledDocumentAndDisplay:error:]
- if there are items in the queue I call [super
openDocumentWithContentsOfURL:display:error:]
- also I implement applicationShouldOpenUntitledFile to return yes if
I'm in normal mode, and no if I'm in queuing mode.

This all works well for kAEOpenDocuments, but not so well for
kAEPrintDocuments.  The problem is that in
openDocumentWithContentsOfURL:display:error: (where I conditionally add
to the queue) I have no way to know if its an kAEPrintDocuments or a
kAEOpenDocuments. My app doesn't actually print, so I gave up at that point.

Would be nice if NSApplication had a delegate message like
applicationWillFinishLaunching that gives you a chance to show a modal
ok/cancel dialog at launch.  Please create a dupe. :)


Wow, that does seem involved... It was the seeds of a solution like this bubbling up in my head that had me in a bit of a panic, given my time constraints. I did file an enhancement request, #6653022

I tried Jeff Laing's suggestion of just handling the dialog in response to both -applicationShouldOpenUntitledFile and application:openFile: and as far as I can see that is sufficient - it defers the opening of both new and file documents until the dialog is dismissed. I haven't tried it for the print documents case - I will make sure I test that, as I do print.

Using -awakeFromNib also ought to work as Andy Lee suggested, though I haven't tried it since Jeff's is working so far.

Thanks to everyone for their help,

--Graham







_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to