Dynamic menu building
Dynamic menu building
- Subject: Dynamic menu building
- From: April Gendill <email@hidden>
- Date: Fri, 15 Aug 2003 00:42:26 -0700
Ok...
Dynamic menu building is as far as I can tell very complex.
1 you have to create some form of data structure
2 you have to build the menu on the fly based on said(ever changing)
data.
In applications that we all use every day we find menus which expand
submenu to submenu to submenu, such as a bookmarks menu in any web
browser.
Now, since I'm new to all of this, I'm just working on being able to
build a group of submenus and add items to them. So... I have a top
level menu.
But the way it is allocated is: NSMenu * currentMenu = [[[NSMenu
alloc] initWithTitle:@"CurrentMenu"] autorelease];
So in order to create a menu, I have to know it's name before hand and
the number that I can allocate is static. And since I can see that this
is in fact not at all true, simply by clicking safari and going to the
bookmarks and selecting a group i named "Development" I have to wonder
how the submenus are allocated. The only examples I've seen have to
allocate each submenu before hand, and some how I seriously doubt that
apple computer bothered to allocate a special development submenu in
the bookmarks just for me.
My understanding of menu building is therefore incomplete to say the
least.
What I would like to do is create a program that can gather data from
a file and create a menu, with submenus displaying items from a
dictionary. Each dictionary would be a submenu all it's own and since I
cannot know the names and number of submenus that might be added, how
do I allocate the submenu item so it can be added to the toplevel.
As it stands I can build the menu programatically right now, as long as
I do it statically. This is not a problem. I can get the items to pass
the correct index and even get my execute menu item method to nslog the
correct information based on keys in a dictionary. so the setSubmenu
and all that I have working... But in order to draw data from a file
and use a predetermined name variable i need to be able to allocate a
menu on the fly, with no idea what it's name will be and thus no way to
assign it a variable because I cannot even be sure it will exist from
one run of the app to the next.
Hmmm does this even make sense?
I hope I explained my intent. I simply want to be able to create a
menu, that has under it, groups and each group has items. It will be
limited to only those two tiers.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.