Re: NSMenu not displaying items added programmatically
Re: NSMenu not displaying items added programmatically
- Subject: Re: NSMenu not displaying items added programmatically
- From: Patrick Hartling <email@hidden>
- Date: Thu, 10 May 2007 14:16:13 -0500
- Openpgp: id=C874F217; url=http://keyserver.veridis.com:11371/export?id=-4495319854773636585&created=1069733607000
I. Savant wrote:
> 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. :-)
What I have read suggests that there is a coupling between
NSDocumentController, NSDocument, and NSWindowController. I have not read
everything about document-based applications, but based on what you point
out below, I think I have a solution.
> 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.
I think it's probably too much to explain given that you zeroed in on what
is causing my problems.
>> 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?
I was not aware that this was an automatically maintained menu. That
explains a lot.
> 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.
I'm sure that you're right.
> 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.
OK, that's definitely easier than I was expecting. The documentation I was
reading led me to believe that I was going to have to work harder than that,
and that is why I was trying to skip the use of NSDocumentController. Thanks
for the insight. It is a huge help.
-Patrick
--
Patrick L. Hartling
VP Engineering, Infiscape Corp.
http://www.infiscape.com/
Attachment:
signature.asc
Description: OpenPGP digital signature
_______________________________________________
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