4

The OS X document versions browser (get to it from File > Revert to > Browse All Versions) shows the current version on the left side and and stack of older versions on the right side.

The window controller on the left side gets notifications letting you know that it's entering/exiting version browsing mode. Also the document for the left hand side returns true. in response to isBrowsingVersions.

But I don't know how to tell when my window is being used to display one of the actual version (the stack on the left side). Those windows don't get the entering/exiting notifications and their document's respond false toisBrowsingVersions`. What's the recommended way to determine if a window is being used to show and old version of a document in the version browser UI?

The two methods that I've found so far are:

  1. NSDocumentController.documents doesn't seem to contain those browed version documents.

  2. The browsed versions documents fileURLs start with file:///.DocumentRevisions.

Is there a better more supported/direct method to determine if my window is browsing an old document version? I need to change some UI behavior in that case.

Jesse Grosjean
  • 607
  • 4
  • 10

2 Answers2

6

Few minutes after posting, just figured this out. The answer is that documents on the right side will return true when asked isInViewingMode.

Jesse Grosjean
  • 607
  • 4
  • 10
  • Reading the documentation at https://developer.apple.com/documentation/appkit/nsdocument/1515086-isinviewingmode, this does not look reliable. Versions browser is only one of the specific case where your document would return true for isInViewingMode. I guess this would be true also for document types where you app does not have Editor role. And as the documentation says, for locked documents. – Ceylo May 16 '20 at 10:12
  • This is still interesting in some cases though. In my case I want to know when I'm in Versions Browser because each document can use >1GB RAM, so version browser blows up RAM. So instead I want to just load and display a lighter preview of my document. However thinking of isInViewingMode actually makes sense. Because my lighter previews would also be relevant for read-only or locked documents. So basically the lack of information is probably going to make my efforts useful in more cases. – Ceylo May 16 '20 at 10:51
  • 1
    So actually I experimented a bit and isInViewingMode remained false in these cases: file without write permissions, locked file, file type for which your app is viewer only. And the only case I found where it was true was indeed in versions browser. So although the documentation is not clear, it looks like the good way to determine that you're in version browser. – Ceylo May 19 '20 at 20:37
1

As the date of 2018-07-04

- (void)windowWillEnterVersionBrowser:(NSNotification *)notification NS_AVAILABLE_MAC(10_7);
Simon
  • 705
  • 1
  • 5
  • 11