Does anyone here have experience with document-based applications on macOS in which you can make a document file type that the user can't save via the app? Having the rename/move dropdown with disabled name and location fields?
Wanted to start with the question before going into the explanation of the scenario below.
I'm trying to implement an intermediate file type for my document-based application. Think of it like a intermediate project file of sorts that describes an edit/combination of media, but if the user tries to close the window, they will be prompted to export the media into a final format (not of the intermediate type).
I'm trying to base the experience off of how QuickTime Player does. In QuickTime Player, if you open up a video, it acts like a viewer and it lets you rename/move the file via the dropdown from clicking on the title:
https://i.stack.imgur.com/a5WGr.png [Screenshot showing rename/move dropdown from QuickTime Player]
Note: Found it interesting that for some reason the Locked option is disabled. Is not the case when I open a file in mine.
Now, when you drag another video onto that one in QuickTime, you create a composition of the two and the window changes to an Untitled document that is marked as edited. This appears to be done via a new document file type they made with the extension qtpxcomposition. Looking in the plist for the QuickTime Player App shows that they have two types of QuickTime Player Compositions under the identifiers com.apple.quicktimeplayerx-composition and com.apple.quicktimeplayerx-composition-bundle, sharing the same extension. It also shows that the QuickTime Player App is set as an editor of these types. This I understand and have implemented my own Exported UTI in the same way with a different extension. I even got the behavior working where I create a temp file of that type, open a document with it's contents, and have it replace the current window. However, the big difference I am finding, is that the rename/move dropdown is fully enabled on mine, which means the user can save my intermediate file. On QuickTime Player, you can see here that this is not the case:
https://i.stack.imgur.com/yrCab.png [Screenshot showing rename/move dropdown for qtpxcomposition file in QuickTime Player]
The name, where, and locked options are all disabled. The user can only add to the tags, and as a result the tag dropdown auto opens when this rename/move dropdown is opened. I have not been able to figure out how this is done. Since it's an untitled document loaded from the contents of a file, it doesn't have a path if you right-click the title (mine does the same), and you can't rename/move it since those options are disabled on theirs. You will find the "Save," "Rename," and "Move to" options all disabled under the file menu and if you close the window, a save dialog box comes up that will export the composition as a .mov file as show here: https://i.stack.imgur.com/bf5w9.png. This means the app has effectively hidden any real way for the user to save this intermediate file. Does anyone know how they did this?
From my testing, it seems like that dropdown is only present when you return YES for + (BOOL)autosavesInPlace
and this is what also causes the save prompt to be presented when you try and close the window of an untitled document. Though I do know that QuickTime Player is setting a specific location for autosaves to be saved to. Namely within /Users/.../Library/Containers/com.apple.QuickTimePlayerX/Data/Library/Autosave Information. I still need to figure out how to properly setup autosaves to a location like that (my guess is via NSURL * autosavedContentsFileURL
), but I don't suspect this has something to do with why the name and location fields are disabled.
Things I have tried include returning an error from checkAutosavingSafetyAndReturnError
, testing what returning YES or NO from preservesVersions
or autosavesDrafts
does, as well as testing the idea of locking the document. However, none of these worked. The most one of these did was have the file seem to be marked as "Locked," but the user could just open that rename/move dropdown and unlock it. Given the file isn't marked locked on QuickTime Player, I don't think locking it like that is a part of it either.
The other approach I could think of was that they are accessing the dropdown itself and disabling those text fields, but I haven't found any way to get access to that dropdown. Haven't found any delegate methods or overridable methods that would give me it. Closest thing I found was in NSWindow where you can override - (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu
but that one just refers to the path pop-up that comes up when you right-click the title. Which for an untitled document like this, already doesn't do anything.
I'm not sure what else I can try at this point and I haven't had any luck finding anyone else asking about this kind of thing online. Only answer I saw someone give to disabling that dropdown was returning nil when that button was being made, however that doesn't work. While the chevron to the right of the title is gone, it doesn't stop the functionality from still happening if you click on the title.
Does anyone have any idea how this is being done in QuickTime Player?