Re: Subclassing NSWindowController for multi-window NSDocument?
Re: Subclassing NSWindowController for multi-window NSDocument?
- Subject: Re: Subclassing NSWindowController for multi-window NSDocument?
- From: Harilaos Skiadas <email@hidden>
- Date: Tue, 28 Dec 2004 03:40:24 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Keith,
>Hello,
>
>I know the question I am asking is on the trivial
>side, but even after reading the docs on
>NSWindowController, NSDocument and the document
>architecture, I am still nonplussed. The question:
>
>I have a document-based app that contains an outline
>view and a text view, a bit like Xcode. Clicking an
>item in the outline view opens it in the text view.
>And like in Xcode, I want it so that if you
>double-click on the item, it opens in a new window,
>and the title of this new window will appear in the
>app's 'Window' menu as a sub-item of the main window
>title.
>
>Do I need to subclass NSWindowController to achieve
>this? Basically, if the user double-clicks on an
item,
>it should open in the new window, but if the user
then
>flicks back to the main window and double-clicks on
>another item, that should open in the already-open
>extra window (ie. exactly like in Xcode). Do I need
to
Unless I misunderstand you, this is not how Xcode
works in my computer at least. Each time I
double-click in a file, a new window is created
containing that file.
>have an NSWindowController subclass as the file's
>owner instead of my NSDocument subclass for this? If
No, probably not. But what you need is a completely
different NSWindowController to deal with these new
windows (maybe, depending on how much functionality
you want from them.)
>so, do I need to move all of my outlets and actions
>from MyDocument into an NSWindowController subclass?
>And how do I make sure my main document window still
>loads as normal, but my other window loads when I
>want? I am totally baffled by the whole process of
>achieving this, even though it seems as though it
>should be really simple. All the books I have cover
What I would do in your case would be the following: I
would create a new nib file that contains the new
window you are trying to construct and its window
controller, which you might or might not want to
subclass. I would add a new variable (say
myExtraWindowController) owned by your NSDocument
subclass, of type NSWindowController, or an array of
them if you want different new windows to open each
time. Then, in the code in your NSDocument class
dealing with the double-click, I would do something
like:
myExtraWindowController = [[NSWindowController alloc]
initWithWindowNibName:@"myExtraNib"];
(You might need to change the NSWindowController with
your subclass.)
Now this new controller can be accessed from your
NSDocument class, and you can do anything you want
with it and its window from your document class. Just
remember that you also want to release it in your
dealloc method. You would probably need to work a bit
to be able to exchange information between the two
windows, depending on your application.
Now, to make this appear as a sub-menu of the menu
corresponding to the main window, you would probably
need to work harder. My guess, though I might be way
off, would be that you would need to subclass
NSDocumentController, set it up as the menu's
delegate, and in the delegate implementation have it
query all the document class instances for how many
extra windows each of the have, then construct the
menu from that. I would think twice before getting
into this.
HTH, good luck!
Haris
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden