Here's my hack for now. This deletes any existing documents that aren't the current document, but this seems pretty ugly. The docs state the following, but not how to handle once a document URL already has an associated NSDocument. Hence the hack. If you can following any of the flow of commentary in NSDocumentController, then you are wiser than I.
/* This will be called for any URLs your application is asked to open. This includes URL types (CFBundleURLTypes) defined in your Info.plist, and Document types (CFBundleDocumentTypes) that have no associated NSDocument class. Document URLs that have an associated NSDocument class will be opened through NSDocumentController. If this is implemented, application:openFiles: and application:openFile: will not be called.
*/ (void)application:(NSApplication *)application openURLs:(NSArrayNSURL * *)urls API_AVAILABLE(macos(10.13));
(BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
...
BOOL isLoaded = [self loadFromURL: url];
if (isLoaded) {
NSDocumentController* dc = [NSDocumentController sharedDocumentController];
NSDocument* currentDoc = dc.currentDocument;
NSMutableArray* docsToRemove = [[NSMutableArray alloc] init];
for (NSDocument* doc in dc.documents) {
if (doc != currentDoc)
[docsToRemove addObject: doc];
}
for (NSDocument* doc in docsToRemove) {
[dc removeDocument: doc];
}
}
return isLoaded
}
Topic:
UI Frameworks
SubTopic:
AppKit
Tags: