If you've subclassed NSDocumentController, when the user opens multiple documents, the method
will be called once per each document.
If you need to figure out how many documents are being opened (you might to do something after the last document that is part of a batch has been opened), you need to do a couple of things.
For documents opened via the open panel, things are easy:
In your NSDocumentController subclass, override the implementation for URLsFromRunningOpenPanel:
For documents being opened through Applescript events (such as documents dropped over the application icon), this is my not very elegant but efficient solution:
- (id)openDocumentWithContentsOfURL:(NSURL *)absoluteURL display:(BOOL)displayDocument error:(NSError **)outError
will be called once per each document.
If you need to figure out how many documents are being opened (you might to do something after the last document that is part of a batch has been opened), you need to do a couple of things.
For documents opened via the open panel, things are easy:
In your NSDocumentController subclass, override the implementation for URLsFromRunningOpenPanel:
- (NSArray *)URLsFromRunningOpenPanel
{
NSArray * a = [super URLsFromRunningOpenPanel];
documentsPendingOpen = [a count];
return a;
}
For documents being opened through Applescript events (such as documents dropped over the application icon), this is my not very elegant but efficient solution:
- (id)openDocumentWithContentsOfURL:(NSURL *)absoluteURL display:(BOOL)displayDocument error:(NSError **)outError
{
NSAppleEventDescriptor * aed = [[[NSAppleEventManager sharedAppleEventManager]
currentAppleEvent]
paramDescriptorForKeyword:keyDirectObject];
if(aed != nil && cachedAppleEventDescriptor != nil && ![[aed data] isEqualToData:[cachedAppleEventDescriptor data]])
{
cachedAppleEventDescriptor = aed;
documentsPendingOpen = [aed numberOfItems];
}
[..]