Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Documents in a Single Window in Cocoa

I want to write an application which may have multiple documents in a single window via a tabbed interface. Should I avoid the NSDocument architecture (the Cocoa Document-based Application template)? As far as I can tell, it supports only one or more window per document but not vice versa.

I have been wrestling with this question for a while and have already built much of my application on the NSDocument architecture but I cannot figure out a good way to associate multiple documents with a single window.

EDIT: I want to have project document windows in addition to basic document windows. At this level of complexity, would it still be worth hacking the NSDocument architecture? Did Apple write Xcode (which works this way) using the NSDocument architecture?

like image 866
titaniumdecoy Avatar asked Jul 12 '09 20:07

titaniumdecoy


2 Answers

I have the same kind of project — different independent documents that I want to present in a single window, with a sidebar that allows switching between documents — so I have done a little bit of searching myself.

I just found an interesting lead by reading Cocoadev's Document Based App With One Window For All Documents reference. It appears, from MikeTrent's answer, that using NSDocument is a very viable way to go. You just need subclassing NSDocumentController.

I also like Abhi's idea to use a borderless child window.

like image 166
KPM Avatar answered Oct 07 '22 15:10

KPM


Using an NSDocument-based architecture isn't necessarily a bad idea in this case; but it might require quite a bit of haquery.

It is quite likely that you will have to not only subclass NSDocument, but also it's more rarely subclassed sibling NSDocumentController. Once this is done, it should be a simple matter to hijack and avoid calls to -makeWindowControllers and other window-related methods, allowing you to wrap the document "windows" in whatever fashion you please, but still retain the benefits of the document-based application.

like image 29
Williham Totland Avatar answered Oct 07 '22 16:10

Williham Totland