Multiple Selection Popup button

How do I enable Multiple Selection in a Popup button ? I looked at the attributes and didn’t find anything that turns on multiple selection in a popup. I’m using Xcode 4.

I don’t think you can do that. PopUpButtons display menu items, and as far as I know, you can only choose one menu item at a time.

Ric

Is there a way to achieve this ? I guess I will have to display the options using a table view and enable Multiple selection.

There is a way to achieve it inside a popUpButton by using a view as a menu item. I don’t know if this has any advantage over just popping up a window from a regular button other than it looks like a popUpButton.

I added a popup button to a window and an NSBox. In the box, I put a matrix of 5 NSLabels with different titles for each (five fruits) and a button below the matrix (labeled “close”). The matrix was set to List Mode to allow for drag selection. I made the script the delegate of the popUp’s menu. The following code allowed me to change the title of the popUp to the selected item – or the last item selected if making multiple selections. You can select by dragging or the usual shift-click or command-click methods for continuous or discontinuous selection. It doesn’t matter where you put the box and its contents in the window, because when that view is added to the menu of the popUp, it doesn’t appear in the window where you put it in IB. You can close the menu by clicking the close button in the popUp menu or by clicking anywhere outside the popUp.

script ViewInMenuAppDelegate
	property parent : class "NSObject"
	property pu : missing value -- IBOutlet for the popUpButton
	property theBox : missing value -- IBOutlet for the NSBox enclosing the matrix and buuton
	property item1 : missing value
	property mat : missing value -- IBOutlet for the matrix of NSLabels
	
	on applicationWillFinishLaunching_(aNotification)
		set item1 to current application's NSMenuItem's alloc()'s initWithTitle_action_keyEquivalent_("Apple", missing value, "")
		item1's setView_(theBox)
		item1's setTarget_(me)
		pu's removeAllItems()
		pu's |menu|()'s addItem_(item1)
	end applicationWillFinishLaunching_
	
	on matrixClick_(sender) -- IBAction for the matrix
		item1's setTitle_(sender's selectedCell()'s stringValue())
		
	end matrixClick_
	
	on menuDidClose_(sender) -- A delegate method of the popUp's menu (set the script to be the delegate in IB)
		repeat with aCell in mat's selectedCells()
			log aCell's stringValue
		end repeat
	end menuDidClose_
	
	on buttonClick_(sender) -- IBAction for the button
		pu's |menu|()'s cancelTracking()
	end buttonClick_
	
end script

Ric