Re: Dynamic menu building
Re: Dynamic menu building
- Subject: Re: Dynamic menu building
- From: April Gendill <email@hidden>
- Date: Fri, 15 Aug 2003 09:16:11 -0700
Appearantly you did not understand what I was saying.
I CAN add single items to any menu, the dock menu, any of the main menu
bar items. I can add anything ITEM. addItem works fine even if I am
pulling data off of a file. HOWEVER to dynamically insert a whole
submenu, and to understand what I mean, open safari. In your bookmarks
do you have any groups set up? well i do, and with in those groups I
have subgroups, so i end up with menus like:
bookmarks
|
Some group -> A bookmark
Another Bookmark
A group -> Some bookmarks
More Bookmarks
If I know the name of the group, it is not a problem to ad all the
stuff to it I want, even other groups if I want other groups and
allocate them statically within the program.
However, like with the bookmarks menu in an browser, you cannot
possibly know what will be there from one run of the app to the next.
Thus I cannot simply allocate an NSMenu instance to treat as a submenu.
Understand, I am trying to add items to the dock menu. Some of these
items will be grouped items. those groups then become submenus. Or is
submenus the right word? You know the item is in the menu, there is a
triangle, when you select it, a new menu pops out to the side and there
is a list of things there.
From all I have seen when you allocate an NSMenu it is not possible to
do something similar to NSMenu *[anArray itemAtIndex:[varaible here to
pass an index]] =[[NSMenu alloc]initwithTitle:[some variable here to
pass a string]]; I mean I've never seen a language that can accept a
variable name from a variable. And unlike pascal you cant have things
like item[1],item[2] if I could this would be super easy it'd be NSMenu
*item[anIntToCountWith] =[[[NSMenu alloc]etc
unless there is a way to pass a variable that way, that I am not
aware of.
So my question is then more specifically:
If i have a while loop.
while (anInt < aCompatritor){
NSMenu aMenu=[[[NSMenu alloc]initWithTitle:[a variable call to pass a
string] autorelease];
<get info from a Dictionary or array built from a file or the
preferences>
[item setSubmenu:aMenu];
<here, should I iterate through all the items before adding the
submenu to the master menu?>
[masterMenu addItem:aMenu];
anInt++
}
(I am sure the above code is wrong somehow, but it's early for me, I
have not had coffee and I'm typing from memory here. )
this will iterate through the array or dictionary or what ever, it will
assign the items to the submenu aMenu, but if I nest that loop in a
loop that moves through an array of arrays or dictionaries won't all of
the items added to aMenu be wiped on the next dictionary that gets
stepped through on that while loop OR, will it be ok because the aMenu
is re initialized each time it steps a new dictionary, and it's re
initialized with a new name?
I am really trying to understand if cocoa is going to get confused if I
pass the same variable name for the menu a hundred times with different
initWithTitle: information?
On Friday, August 15, 2003, at 01:19 AM, j o a r wrote:
On den 15 augusti 2003, at 09:42:26AM, April Gendill wrote:
Dynamic menu building is as far as I can tell very complex.
No, it's very simple... ;)
Just find the menu (if it is the application menu you can get it from
the shared NSApplication instance) and then add / remove items from it
using the "addItem:" / "removeItem:" methods. Nothing complex there.
The name of the menu is most often not interesting / used - set it to
@"". You can change it's "name" using the "title" attribute of the
menu item instance holding the menu - this can be set and re-set as
many times as you want.
j o a r
_______________________________________________
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.