Using MonoMac, I have a NSDocument-based application, but I’m needing to create a new NSDocument object when a button is clicked.
For example. I have in another Window I have a NSWindowController and I can do
Controller c = new Controller ();
c.Window.MakeKeyAndOrderFront (this);
thus causing the Window to be loaded that is tied to the controller.
With the NSDocument I guess the controller is built in?
So I’m expecting something like
MyNSDocument doc = new MyNSDocument ("Some Value ");
doc.Window.MakeKeyAndOrderFront (this);
Of course this doesn’t work.
Additional info, for example when in the Application if you hit Command + N, then a new Document Window is loaded. This is cool and I basically need the same thing to happen, but when a button is clicked.
Using “File” / “New” or
Control + NinvokesnewDocument:on the application’s shared document controller, which is themenu.xib‘s First Responder.To do the same programmatically, use
NSDocumentController.SharedDocumentControllerto get the application’s shared document controller, then invokeNewDocument ()on it (you can passnullas sender):