macOS document based app - save all documents as one

25 views Asked by At

I have a document based app that manages some „configurations“ for different HIDDevices. Those configurations are subclasses of NSDocument, I can save and load them.

It is possible to have multiple documents open at the same time. I now want to implement a function that saves all currently open documents as a „performance setup“ in one file.

In pseudo code:

class PerformanceSetup() {
    var configurations: [Configuration]
}

var performanceSetup = PerformanceSetup()

for configuration in configurations {
    performanceSetup.configuration.append(configuration)
}

The PeformanceSetup class practically is not a document on its own, it is created on the fly to combine multiple configurations into one saveable data structure. When opening such a saved PerformanceSetup no document should be created upon the opening process itself, but the single Configurations should be decoded and then a Configuration object (aka NSDocument subclass) will be created for each configuration.

The saving of such a Setup should be user initiated via an additional menu entry „save as performance setup“. Any „open document“ panel should however let the user select single configurations as well as performance setups. The openDocument method of my custom NSDocumentController should then check the type of file and proceed accordingly.

I think, my main question is:

Do I still have to make the PerformanceSetup class a subclass of NSDocument? Do I have to register it as another document type with a different type identifier, file extension etc. to make it become selectable by the user in the open dialog?

0

There are 0 answers