Re: Add duplicate menu items
Re: Add duplicate menu items
- Subject: Re: Add duplicate menu items
- From: Harilaos Skiadas <email@hidden>
- Date: Thu, 23 Sep 2004 20:58:37 -0700 (PDT)
>On 23 Sep 2004, at 22:48, John Mistler wrote:
>
>> I would like to populate a popup button with a list
such as:
>>
>> {"thisItem", "thisItem", "thatItem", "thatItem",
"thatItem"}
>
>I'm sure you have a good reason for doing this but
I'm also sure it
>will be confusing to your users.
>
I had a similar situation recently, where the menu was
to contain the history list of all the commands that
the user had previously typed in (the app was a GUI
for a terminal based interactive application, and a
user might type the same command more than once, with
lots of other commands inbetween possibly. I wanted
the popup menu to show him everything that he had
typed in so far, in the order in which he typed them.)
>> I am looking for a method that does not remove
duplicate items. >For
>> instance, "addItemsWithTitles" only adds "thisItem"
and "thatItem" >to
>> the
>> menu, leaving only two menu items. I want five.
>>
>> Does anyone know how to accomplish this?
>
>How about calling -menu on the NSPopUpButton and then
adding >items
>directly to the underlying NSMenu using either
-addItem: or
>-addItemWithTitle:action:keyEquivalent:
>
This is exactly what I ended up doing. I set myself as
the delegate of the menu in IB, and then listened for
the menuNeedsUpdate. This is the method that I have in
my program (It probably could use some improving):
- (void)menuNeedsUpdate:(NSMenu *)menu
{
if (menu == [historyPopUp menu])
{
[historyPopUp removeAllItems];
[historyPopUp addItemWithTitle:@"History"];
NSEnumerator *en = [[myHistoryList arrayFromHistory]
reverseObjectEnumerator];
NSString *historyItem;
while ( historyItem = [en nextObject] ) {
[menu addItemWithTitle:historyItem
action:@selector(useHistoryItem:) keyEquivalent:@""];
}
}
}
I asked the question in the thread titled "Creating
popup button's menu at the last moment" on Sep 16th,
you can find the discussion there.
> Nicko
Haris
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.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