Monday, October 22, 2018

#1 2018-05-17 03:52:27 pm

jcwelch
Member
Registered: 2009-09-11
Posts: 50

Records and popupbuttons

Okay, so I have a popup button populated from a list of records. Say, {{name:bill,eyes:green,feet:two},{name:john,eyes:blue,feet:yes}}

I've set up my array controller and popup bindings correctly so the popup list shows the correct values, (in this example, name).

What I'd like to get returned when the user makes a selection though, is the entire record, so if they pick "john", I get the entire thing.

Offline

 

#2 2018-05-17 05:34:56 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Records and popupbuttons

Try binding to the Selected Object.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2018-05-17 06:46:01 pm

jcwelch
Member
Registered: 2009-09-11
Posts: 50

Re: Records and popupbuttons

so I created a test variable:

property popupTest:""

I bind popupTest to selected object, binding it to delegate and popupTest in the model key path, changing nothing else. All I get is the value I see in the popup.

Offline

 

#4 2018-05-17 07:49:41 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Records and popupbuttons

You're not saying where you want to "get" the value. If you have an action handler connected to the popup, you can get it like this:

Applescript:

   on chooseItem:sender
       set x to arrayController's selectedObjects()'s firstObject()
       current application's NSLog("selected: %@", x)
   end chooseItem:

where arrayController is an outlet to your array controller.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2018-05-17 10:49:10 pm

jcwelch
Member
Registered: 2009-09-11
Posts: 50

Re: Records and popupbuttons

I'm trying to get the values when they make a selection in the popup.

I have the ArrayController's content array bound to the list of records.
The popup's content values are connected to the name value in the record, and selected object is bound to the variable that i'm trying to inject the record values into.

so, because I want to get the concepts correctly, I should be binding that variable I want the record to be injected into to the array controller?

Offline

 

#6 2018-05-18 03:57:35 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Records and popupbuttons

Don't try to do everything with bindings. For the selection, IMO you're better of using an action handler. That way you get the value plus an indication that the selection has changed.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#7 2018-05-18 12:59:08 pm

jcwelch
Member
Registered: 2009-09-11
Posts: 50

Re: Records and popupbuttons

that did it (once I used selectedObjects()'s instead of selectedObject()'s)!

Thanks man!

Offline

 

#8 2018-05-29 10:59:13 am

jcwelch
Member
Registered: 2009-09-11
Posts: 50

Re: Records and popupbuttons

okay, so hitting a related thing: how do I get the object corresponding to the actual selection. Right now, it's only returning the first object. Which makes sense, but even if I set it to last object, I get the first one.

The array controller for this has its content array bound to a list of records, theNagiosServerRecords, and its referencing outlet is popupSelection which is set up as an IBOutlet

the popup has its content values bound to the above array controller, controller key arrangedObjects, model key path serverName

the sent actions for the popup is attached to selectedServerName:sender

I did go looking through the dev docs for selectedObjects in NSArrayController, but didn't find anything that pointed me in the right direction, or if it did, I have the dumb.

Offline

 

#9 2018-05-29 02:26:32 pm

jcwelch
Member
Registered: 2009-09-11
Posts: 50

Re: Records and popupbuttons

Never mind, doped it out. I had to use NSpopupButton's indexOfSelectedItem to get the numerical index, then use arrayController's setSelectionIndex.

Now on to figuring out why userSelection's removeObjects:(userSelection's arrangedObjects()) isn't doing what it's supposed to do

Offline

 

#10 2018-05-29 02:35:31 pm

jcwelch
Member
Registered: 2009-09-11
Posts: 50

Re: Records and popupbuttons

Derp. Helps if you clear out the list of records variable you're using before putting more data into it

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)