readFromURL only called once on NSDocument-based app for each "Open Recent" menu item

I have a single-windowed app that loads textures. I want to be able to switch textures to anything in the Open Recent menu item list that I add URLs into.

When I launch the app, each recent menu item calls readFromURL once. But subsequent selection of the menu item does not. I can see the documents in the document controller increasing, so I know that is likely why this callback isn't called.

If I return NO from readFromURL then it is called every time, but posts a dialog about the file failing to load. I want that behavior, but not the dialog.

I'm not really using the NSDocuments created, but I needed this mechanism to get at the URL to load the data. I can't really remove documents from list, so I just let them accumulate but they basically just store the URL.

What am I supposed to hook as a callback? Is there a switchToDocument callback hook/delegate?








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:(NSArray<NSURL *> *)urls API_AVAILABLE(macos(10.13));


Code Block
- (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
}

readFromURL only called once on NSDocument-based app for each "Open Recent" menu item
 
 
Q