Adding Sub-Items to an Outline Data Source?

Hey everyone, this is my first post & I’m still kinda new to AppleScript

OK I feel really dumb but I cant figure out how to add sub items to an NSOutline view. Or rather I can, but not dynamically… I started playing with one of Apples examples which taught me how to create the data source & populate the outline view. I then extended it by adding a button that takes text from a text field and adds it as a new item, but I can only figure out how to add it as a main item in the list, not as a sub item of whatever is selected. So far what I have is:


-- Create the data source
	set theDataSource to make new data source at end of data sources with properties {name:"fileDataSource"}
	
	-- Create Columns in Data Source
	tell theDataSource
		make new data column at end of data columns with properties {name:"entryTitle"}
		make new data column at end of data columns with properties {name:"entryPath"}
	end tell
	
	
	
	
	-- Create the parent item "masterLibrary"
	set masterLibrary1 to make new data item at end of data items of theDataSource
	set contents of data cell "entryTitle" of masterLibrary1 to "Test 1"
	set contents of data cell "entryPath" of masterLibrary1 to "..."
	
	
	-- Create the parent item "masterLibrary"
	set masterLibrary to make new data item at end of data items of theDataSource
	set contents of data cell "entryTitle" of masterLibrary to "File Library"
	set contents of data cell "entryPath" of masterLibrary to "..."
	
	
	
	
	
	-- Create a few CHILD items "Group_1"
	set Group_1 to make new data item at end of data items of masterLibrary
	set contents of data cell "entryTitle" of Group_1 to "Named Group"
	set contents of data cell "entryPath" of Group_1 to "..."
	
	set Group_1 to make new data item at end of data items of masterLibrary
	set contents of data cell "entryTitle" of Group_1 to "Named Group"
	set contents of data cell "entryPath" of Group_1 to "..."
	
	
	-- Assign the data source to the outline view
	set data source of outline view "libraryOutline" of scroll view "libraryScroll" of window "mainWindow" to theDataSource

And I have some other code that adds a new child item when a button is clicked, but heres what I dont get, in order to create a new sublevel I need to create a new variable to do that, for example:

set Group_1 to make new data item at end of data items of masterLibrary

In that, Group_1 is explicitly named as that group. How to I dynamically name that? If I dont know how many levels or items or anything I’m going to have, how do I say, “OK figure out which item is hilighted & create a new child item for it.” if I cant create a name for the group like group_(n) in advance?

Thanks for any help anyone might be able to offer.

[/b]

/Developer/Examples/AppleScript Studio/Outline

this shows an ouline view sample it should have everything you need