Popup button disables after picking an item

Dear friends,

I have been banging my head with this for 3 hours…

It populates the popup button, and once I try to pick an item it simply greys out the entire list and selected item.

I push this code to a new project and it works…

Any clues?



        tell application "Mail"
            
            set allAccountAddresses to email addresses of accounts
            
        end tell
        
        set list_of_sender_addresses to {} -- start with an empty list
        
        repeat with i from 1 to count of allAccountAddresses
            set theAccount to item i of allAccountAddresses
            if (count of item in theAccount) = 1 then
                set end of list_of_sender_addresses to item 1 of theAccount
            else
                repeat with eachEmail from 1 to count of item in theAccount
                    set end of list_of_sender_addresses to item eachEmail of theAccount
                end repeat
            end if
        end repeat
        
        (**** somehow I need to reset the popup button, before running this: ****)

        tell theDropDown's |menu|() to removeAllItems()

        repeat with i from 1 to the count of items in list_of_sender_addresses
            
            
             tell theDropDown's |menu|() to addItemWithTitle_action_keyEquivalent_(item i of list_of_sender_addresses,"emailSelected:" , i as text)
         
        end repeat
        
   
    on emailSelected_(sender)
        log (theDropDown's title)
    end emailSelected_



Thanks!

What do you mean by this? It works if you put this code in a new project? I put it in a new project, and it worked fine, so what’s the problem? We can’t help find a problem if it’s not in the code you posted. You must have done something wrong originally that you fixed.

Ric

I delete the button and place it back, connect, and it doesn’t work.

I tried to duplicate that effect, but it still works for me. When you say it doesn’t work, do you mean it’s behaving like you said in the first post?

Ric

I have posted a screenshot here:

https://files.me.com/fundidor/sa3dp2

The project is 30Mb in size…

In the screen shot I tried creating a new window, place a new instance of a popup button and link it.

Still have the list greyed out.

I commented the line that deleted allItems before populating, so you will see the default 3 first items for a popup button…

Sorry, I don’t see anything wrong with the code you posted – I can’t see why your menu items are added but not enabled. I can’t recreate that problem here. Possibly, it has something to do with Xcode 4 – I’m still using 3.2.6, so I can’t help with that.

Ric

I am trying to use a different approach:

tell theDropDown’s |menu|() to insertItemWithTitle_atIndex_(“someString”, theIdNumber as text),

Bu I get:

-[NSMenu insertItemWithTitle:atIndex:]: unrecognized selector sent to instance 0x10303d930 (error -10000)

Any tips why this doesn’t work?

Thanks!

Because that’s a method of the popup itself, not of its menu. Should be:

tell theDropDown to insertItemWithTitle_atIndex_(“someString”, theIdNumber as text)

Ric

Thanks to all my friends.

Solved it.

Using insertItemWithTitle_atIndex_ solves it, although I still don’t understand why the previous code does not work.

Strangely insertItemWithTitle_atIndex_ ask me for ID as integer and starting with 0, not 1 as the previous did.

Thanks to all of you,

There is nothing strange about that – it’s not an ID, it’s an index, and indexes in cocoa are always 0 based (or at least mostly 0 based, I can’t think of any 1 based indexes at the moment).

The previous method that you were using, addItemWithTitle_action_keyEquivalent_, doesn’t have any index, so it wasn’t asking for you to start at 1 – you started at 1 in your repeat loop because you were using an applescript list which is 1 based, rather than a cocoa array which would be 0 based.

Ric