Re: Dynamic menu for document-based app?
Re: Dynamic menu for document-based app?
- Subject: Re: Dynamic menu for document-based app?
- From: Keith Blount <email@hidden>
- Date: Wed, 19 Jan 2005 12:30:02 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Hello and many thanks for all your replies, much
appreciated - they have all helped a lot.
As suggested, I am only going to populate the menu
when needed, using a change count and the NSMenu
delegate methods.
One thing I am still a little puzzled about, though,
is the best way to access the current document from my
menu delegate - sorry if this is a really dumb
question.
I have an AppController as my application delegate,
and I have also made my AppController the delegate of
the menu that I need to create dynamically. So now, I
need to access the current document (still named
MyDocument, not good practice I know...), so that I
can ask it for the contents of the menu. One way might
be:
[[[NSApp mainWindow] windowController] document];
but I would have thought there would be an easier way
to get to the document than this. (NSMenu doesn't have
a target, only NSMenuItem, so I can't set it to nil
and ask it to look down the responder chain.) I guess
what I am really looking for is something like a
[NSApp currentDocument] method...
Many thanks for all the help,
Keith
TeachText wrote:
> At 14:39 Uhr -0800 18.01.2005, Keith Blount wrote:
> >For 1), I guess I could use add notifications to
> every
> >data source method that changes data, but this
> seems
> >somewhat clunky. Or I could go through my code and
> >make sure the menu gets updated every time I call
> >reloadData on the outline view - again, a little
> >clunky, maybe.
>
> Or, if your menu doesn't have keyboard shortcuts,
> you could
> dynamically populate the menu whenever the user
> opens it. You'd still
> need to keep around a change count so you know when
> the menu is
> current and when you need to reload it from the data
> source, but if
> your users never use the menu, they won't incur the
> overhead.
>
> >For 2), the only thing that looked helpful in
> >NSApplication's documentation was maybe using
> [[NSApp
> >orderedDocuments] objectAtIndex:0] to work out
> which
> >data source to show in the menu, though I would
> have
> >thought there would be a better way... Also, I
> would
> >need to know whenever the active document changes.
>
> Have a look at the First Responder. Just implement
> a
> getFirstDocumentsOutlineList: method and send that
> to the first
> responder. disable your menu when there is no first
> responder that
> accepts the message, populate it with the list's
> contents otherwise.
> --
> Cheers,
> M. Uli Kusterer
>
------------------------------------------------------------
> "The Witnesses of TeachText are
> everywhere..."
> http://www.zathras.de
>
__________________________________
Do you Yahoo!?
All your favorites on one personal page Try My Yahoo!
http://my.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