I’ve been following the following link as a guide to what I want to do:
http://macscripter.net/viewtopic.php?pid=171287#p171287
I am building a hierarchy of music tracks that will be displayed using the Outline View. I am starting from the basics (no children), and I would just like to display in the first column the track names of the query and in the second column the artist name.
This is what I have:
property theData : missing value --binded to Tree Controller
property NSTN : class "NSTreeNode"
on awakeFromNib()
set theData to current application's NSMutableArray's array()
tell application "iTunes"
set codingTracks to every file track of playlist "Coding"
end tell
repeat with aTrack in codingTracks
set tempNode to NSTN's treeNodeWithRepresentedObject:{name of aTrack, artist of aTrack}
theData's addObject_(tempNode)
end repeat
setTheData_(theData)
end awakeFromNib
Now…I have absolutely no idea how I would use a ‘Model Key Path’ to populate the column (binded to the Tree Controller) with the name property that is currently stored on each of the nodes of the Tree Controller.
Am I doing this completely wrong?
Your tree node needs to be a record, not a list.
Thanks for the reply.
Tried it this way:
on awakeFromNib()
set theData to current application's NSMutableArray's array()
tell application "iTunes"
set codingTracks to every file track of playlist "Coding"
repeat with aTrack in codingTracks
set tempTrackName to (name of aTrack as text)
set tempTrackArtist to (artist of aTrack as text)
set tempNode to my NSTN's treeNodeWithRepresentedObject: {theName: tempTrackName, ¬
theArtist: tempTrackArtist}
theData's addObject_(tempNode)
end repeat
end tell
setTheData_(theData)
end awakeFromNib
And I set the column to bind to Tree Controller with “Model Key Path” ‘theName’. When I run, nothing is displayed…
It’s hard to say with what you’ve supplied. But you don’t seem to have any hierarchical data, so I don’t see how you can get far.
I will have hierarchical data eventually, this is just for starters. If I can populate the name column in this way, then the next step would be include the children and so on.
Would this be the right procedure to go about doing this? When working with a table, the steps I followed were:
-Create an outlet to the ArrayController
-Create a list of records
-Add the list of records to the ArrayController
-Bind each column of the OutlineView to the Model Key Path of the name of a record of the ArrayController
I’m doing something similar for the Tree Controller:
-Create an outlet to the TreeController
-Create a node that contains a couple of records (theName, theArtist)
-Add the node of records to the TreeController
-Bind each column of the TreeController to the Model Key Path of the name of a record of the TreeController
I am not certain how the binding from the TreeView in the column will be able to obtain “theName” from the list of nodes. I’ve spent way too much time on this without any luck, if anyone wants to have a look, I have posted a small project here:
https://minbox.com/gi/PRzJPdeABA/original
You only need to change the playlist name property to a playlist in your itunes.
Cheers!
To be honest, in real projects I’ve found it easier to use a datasource rather than bindings for outline controllers. It might be just me, but I find it easier that way to follow what’s going on.
Thanks for the tip! Anything that makes things easier is good with me, I’ll start with that approach.