Popup Cell inside table view

Hi

I’m just going thru Shane’s Excellent PDF and trying to create a small app which includes a table view.
So far so good but i’ll be honest i haven’t added much of my own code yet, most of it i could use from the PDF and the rest is within bindings.
What i would like to do now is add a Popup menu cell inside the table view,(similar to the checkbox cell in the pdf) unfortunately i’ve hit a brick wall
and its all starting to look double dutch at the moment.
I’ve added the popup and also added the menu items (which i’m not sure if adding here is correct or i populate it from the script)
Also there not working like a standard popup when i compile there just blank, when i click them i can see and select but they just go blank when i release it.

Any help or advice or tips would be grateful.

P.S. Your PDF is a great little resource to help us who have previously been scared off ASOC, thanks Shane

Cheers

I’m assuming you’re doing this in the sample doc. Have you removed the binding for enabled on that column?

Hi Shane

Yeah i’ve removed the Binding, the app compiles fine with the popupbuttoncell in the column.
I’ve added 3 items to it but there just not showing up.
If i create a popup button outside the table view its fine when compiled.

What am i missing?

Thanks in advance for your help.

Add a property containing your choices:

	property pValues : {"One", "Two", "Three", "Four", "Five"}

Click on the cell and bind its Content Values to the main script, with a Model Key Path of pValues. Make sure it has no other bindings. That should populate it (I’m assuming you’ve removed any existing menu items in IB).

Now bind the table column’s Selected Value to the array controller, with a Controller Key of arrangedObjects and a Model Key Path of isVisible. Again, make sure it has no other bindings.

Noe change this:

	set end of tempList to {theName:item i of theNames, theSize:item i of theSizes, isVisible:item i of isVisbles}

to this:

	set end of tempList to {theName:item i of theNames, theSize:item i of theSizes, isVisible:"One"}

for testing. Build and Run.

Thanks Shane

I’m away from my home machine were this app is living at the mo but
I’ll test and get back to you when i can.

Thanks i appreciate the help.

Hi Shane

I’ve tried allsorts of variations on what you’ve suggested with varying results.
Mainly bad if i’m honest, which is not your fault obviously its where i’ve been placing my code and adding the bindings etc.
I’ve had it so it populates the popup but with only one item on build and run, but my repeat loop is creating more blank menu items as i add them which i know is coming from repeat loop (least of my worries) and its great that the bindings you’ve suggested are working i feel like i’m making progress.
It just isn’t sinking in for me unfortunately.

i may have told you the wrong info regarding which bit of the pdf i was in, hence that hasn’t helped the confusion in my head :confused:

Heres my script (thank god for duplicates) cause i’m going thru these like wild fire.
Obviously like i said i’ve wrote no code only altered and added to yours and so far it works fine until i add the popupbutton cell in the trap column.

And i’m thinking of adding more stuff and growing this little app and also use it as a learning tool for myself an ASOC, i think i might inadvertently picked the worse think to start with.

anyhow once again i appreciate your help.

cheers

script ReproTimeXAppDelegate
	property parent : class "NSObject"
	
	property tableData : {}
	property theArrayController : missing value
	
	on saveData_(sender)
		tell theArrayController to set theList to arrangedObjects() as list
		log theList
		set theRows to {}
		repeat with i from 1 to count of theList
			set oneRow to item i of theList
			set oneRow to item i of theList & {isItAdded:false}
			try
				set end of theRows to jobnumber of oneRow & tab & TimeX of oneRow & tab & theProcess of oneRow & tab & theTrap of oneRow & tab & theDescription of oneRow & tab & ((isItAdded of oneRow) as integer) as text
			on error
				tell theArrayController to setSelectionIndex_(i - 1)
				display alert "Unable to save:" & return & "The selected row is incomplete." message "Please make sure all columns are filled in before saving."
				return
			end try
		end repeat
		set oldDelims to AppleScript's text item delimiters
		set AppleScript's text item delimiters to {return}
		set tabbedText to theRows as text
		set AppleScript's text item delimiters to oldDelims -- save to file
		set newFile to (choose file name with prompt "Save" default name "ReproTimeX.txt")
		tell current application -- required for read/write commands
			set fileRef to (open for access newFile with write permission)
			set eof fileRef to 0
			write tabbedText to fileRef as text
			close access fileRef
		end tell
	end saveData_
	
	on applicationWillFinishLaunching_(aNotification)
		-- Insert code here to initialize your application before any files are opened 
		set my tableData to {{jobnumber:"add Jn", TimeX:"add time", theProcess:"add Process", theTrap:"add trap", theDescription:"double click in each field to add", isItAdded:true}}
	end applicationWillFinishLaunching_
	
	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_
	
end script

The best thing at this stage is to open a copy of the File Table sample, make the changes I suggested above, and get that working. Then make your new project match. Sometimes that sort of approach can be easier.

Hi

Its a shame that the NSPopupButton Cell is not as straight forward as a standard popupbutton but i think i’m making headway, I’ve actually managed to populate it and get it to work 2 different ways (the first by populating it manually in IB the second bring the items in from a list in xcode) using your binding method Shane so thanks for that, Albeit i must of gone thru a 1000 combinations of bindings and confusing myself no end.

An issue i’m finding now though is that i have my PopUp filled with items but i always have 2 blank items in there as well, if i remove the property thats in my model key path then when i build and run i don’t have the blanks but it doesn’t stay selected in the interface, as soon as i add the model key path back the blanks appear and the item i’ve selected stays viewable.

Any suggestions on what i’m doing wrong here would be appreciated?

Its been a long weekend of trying many many options (simply down to my lack of experience with ASOC) but i’ve enjoyed it, and think i may have the bug.

“Applescript Explored” as been a huge help.

Cheers

That sounds a bit like the enabled binding is still in place.

Hi

I’ve checked and checked again and there isn’t an enabled binding set, although if i change the binding to select index or tag in the table column then it works how it should its a nice clean popup populated with my items no blank menu items, however it doesn’t save anymore so maybe i can get it to work this way and change the save code.

Cheers

Hi

A Quick Update,

I decided to start from scratch and base my app around the table you create in Chapter 8 in the PDF.
I needed to save info out and then import it back in.
Once again i’ve added very little if any code of my own, just changed variables and added extra columns etc.

But once again i’ve gone down the NSPopupButton Cell route in 2 of the columns and have got it working, which i’m very pleased with, and for whatever reason the 2 blank menu items i was getting in the previous incarnation aren’t there so happy with that.

I gotta admit it still hasn’t sunk in but i’m trying to force it into my head.

The next thing is to add the numbers in a single column together, which i’m gonna start looking into as soon as i’ve finished this email, but if you’ve any advice on how to go with this it would be appreciated.

Once again a big thanks for writing the PDF and your help in general.

Cheers

Whee, a happy ending! I thought you’d walked out on us :wink:

Could you elaborate?

one of the columns is for the time its taken to do a job in minutes, so say i have 3 rows the time column could have 60,60,30. i just want to add them together, at the minute i’m picking them values out of the
on specFromTabbedText_ handler.

its item 2 from my snippet:

on specFromTabbedText_(tabbedText)
		set theValues to (tabbedText's componentsSeparatedByString_(tab)) as list
		if length of theValues = 7 then
			set my adJobNumber to item 1 of theValues
			set my adTime to item 2 of theValues
			set my adColour to item 3 of theValues
			set my adPlates to item 4 of theValues
			set my popupProcessStore to item 5 of theValues
			set my popupStore to item 6 of theValues
			set my adDescription to item 7 of theValues
		else
			set my adJobNumber to "Invalid entry"
		end if
	end specFromTabbedText_

I hope i’m picking them up from the right place i think so cause i’ve managed to isolate them but struggling to get them into a list that i can then add them together.
its just logging:

so i can single them out but not able to add them together yet.

You’d use pretty standard AS, making sure you coerced to text first:

set theTotal to (item 2 of theValues as text) as real + (item 3 of theValues as text) as real…

Hi

I can’t understand it, i’m really struggling to add these rows together, it must be the way the table
is getting repopulated when i import. i can isolate the numbers in the column, i’m not sure if i’ve managed to get them into a list so i can then start adding them together.

This is confusing stuff:/

Try just treating the contents as a normal AS string, and use normal AS techniques.

Hi

Hooray! I’ve finally done it, wasn’t that straight forward in the end (for me anyhow) i had to go around the houses to strip the info out of the particular rows i wanted, but its done now and i do think i’ve learned a little so need to crack on.
Bring on the next project.

Thanks for your help.

Cheers