0

I've scanned the documentation and googled fairly extensively and found nothing on this subject.

What I'm needing to do is interact with a specific instance of one of my NSWindows - that is, one created through the NSDocument system put in place by creating a document-based application in Xcode.

So is there a way to do this? Something like [[NSSharedDocumentController frontmostWindow] subView: doAction], perhaps?

John Wells
  • 1,139
  • 1
  • 10
  • 27
  • Could you elaborate on that? If your application has five documents opened, which one are you interested in? Does your application have windows other than the document windows? Do your `NSDocument` subclass manage its own window controllers? –  Feb 18 '11 at 00:11
  • It's nothing more than the default doc-based setup. All I'm interested in at this point is the frontmost window and/or the in the case of programmatcally creating a new document, the window I just created. – John Wells Feb 18 '11 at 06:17

1 Answers1

2

To obtain the frontmost window (aka the main window), use -[NSApplication mainWindow]:

NSWindow *mainWindow = [NSApp mainWindow];

To obtain the window corresponding to a given document:

NSDocument *someDocument; // reference to the document you’re interested in
NSWindow *window = [[[someDocument windowControllers] objectAtIndex:0] window];

NSDocument creates a single window controller to manage the corresponding document window, so -[NSDocument windowControllers] returns an array with a single element corresponding to the window controller. -[NSWindowController window] returns the window managed by that window controller.