Re: NSMenu not displaying items added programmatically
Re: NSMenu not displaying items added programmatically
- Subject: Re: NSMenu not displaying items added programmatically
- From: "I. Savant" <email@hidden>
- Date: Thu, 10 May 2007 14:59:38 -0400
On 5/10/07, Patrick Hartling <email@hidden> wrote:
I will look at NSDocumentController again. I am not opposed to using it, but
it seemed as though I would be working against its expectations by not
actually having documents associated with windows.
I don't know what you mean by "associated with windows". The Open
Recent menu is only for displaying documents that were "opened" ...
recently. :-) It's just a list of URLs to any documents that were
opened. If you're trying to forcibly add something to that list, you
must have a reason. Perhaps we should back up and you should elaborate
on what you're trying to accomplish by doing this. The "big picture".
Without that, all anyone can do is focus on answering the how-to.
Nevertheless, there must be some reason that the menu changes that I am
making are not showing up. I have seen examples of constructing menus
programmatically, and since the API exists for doing it, it seems that
people should be able to use it. I can only conclude that I am missing
something simple, and it would be very educational to know what that it.
I may very well be missing something myself (since I thought I had
clearly answered your question), but you're trying to modify a menu
that is *automatically maintained* by the Cocoa document architecture.
Are you really that surprised that an automatically-generated menu
isn't respecting your changes?
That said, there's nothing wrong with your menu-building code per
se; it's just that the menu you happen to be modifying also happens to
be an automatically maintained one. I can't guarantee that's the
reason your changes aren't being reflected, but I'd bet money (or
beer) it is.
You need, I think, to tell your app's Document Controller to "note
new recent document url". It's not going to create or open the
document (or a window for it); it's just going to add another "recent
document" entry to your menu.
In fact, let's test it ...
<two minutes passed, wherein I created a quick doc-based project,
added "[[NSDocumentController sharedDocumentController]
noteNewRecentDocumentURL:[NSURL
fileURLWithPath:@"/path/to/test/file.txt"]];" to my doc's
-windowControllerDidLoadNib: method and ran it >
... yep, it works.
Realize, though, that if the file URL is invalid, it's automatically
removed from the list. Try it in any doc-based app ... create a file,
open it, verify it's in the recent menu. Close it, delete the file,
empty your trash, then look at the recent menu ... gone.
--
I.S.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden