Re: Subclassing NSWindowController for multi-window NSDocument?
Re: Subclassing NSWindowController for multi-window NSDocument?
- Subject: Re: Subclassing NSWindowController for multi-window NSDocument?
- From: Keith Blount <email@hidden>
- Date: Tue, 28 Dec 2004 11:02:04 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Many thanks for your reply - your suggestion worked
perfectly! It was all much simpler than I thought, as,
like you said, I didn't have to do much to the main
document other than add a pointer to the window
controller for the extra window.
Incidentally, I just realised that I have Xcode in
single-window editor mode which is why it works like
that for me but not you... I think it may make more
sense for my app to open as many extra windows as the
user wants, though as you say, this does make things
more complicated. I just have to sit down and work out
how to swap the text storages around sensibly etc now.
And having played around with the menus, indentation
levels and what-not, I have indeed thought twice and
decided not to spend any more time trying to implement
the sub-menu thing until after my program gets to at
least version 1.0...
Anyway, thanks again, that helped loads and saved me
from a lot of confusion, I really appreciate it.
All the best (and happy New Year),
Keith
--- Harilaos Skiadas <email@hidden> wrote:
> 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 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