How to populate an outline view

I’ve wasted a perfectly good Saturday on this. What is the recommended method of populating an outline view? Should a data source be used?

I plodded through the Mail Search example in the AS Studio Programming Guide and when it got to the point where it creates and connects a data source with the outline view, a note is inserted basically saying “ignore the following paragraphs; you are redirected to Xcode’s ‘Older Release Notes’”, but when I go there I find nothing applicable.

When I examine the Outline example under /Developer/Examples I see no reference to data sources and I don’t see an example of how an outline view can be dynamically populated.

I’m assuming it’s a matter of starting with nested lists {{“ABC”, {“DEF”, {“GHI”, “JKL”}}, “MNO”}, “PQR”} or some such thing, and assigning this as the contents of the outline view, or perhaps assigning these list elements individually into data cells if a data source is used, or ???

So…if, for example, I wanted to initialize an outline view to

AAA
BBB
CCC
DDD
EEE
FFF
GGG

could someone please supply a few sample lines of code or a brief description of how to approach this? Sorry for my obtuseness. Thanks very much…

Hi dant,

I modified the simple outline example from the old studioreference.pdf and got this:

–AAA
----BBB
------CCC
------DDD
–EEE
----FFF
–GGG

on awake from nib theObject
– create the data source
set dataSource to make new data source at end of data sources with properties {name:“Outline”}
– create the data columns
tell dataSource
make new data column at end of data columns with properties {name:“Item”}
make new data column at end of data columns with properties {name:“Identity”}
end tell
– create first parent
set parentItem to make new data item at end of data items of dataSource
set contents of data cell “Item” of parentItem to “AAA”
set contents of data cell “Identity” of parentItem to “Parent”
– create child
set childItem to make new data item at end of data items of parentItem
set contents of data cell “Item” of childItem to “BBB”
set contents of data cell “Identity” of childItem to “Child”
– create first child of child
set childChildItem to make new data item at end of data items of childItem
set contents of data cell “Item” of childChildItem to “CCC”
set contents of data cell “Identity” of childChildItem to “Child of Child”
– create second child of child
set childChildItem to make new data item at end of data items of childItem
set contents of data cell “Item” of childChildItem to “DDD”
set contents of data cell “Identity” of childChildItem to “Child of Child”
– create second parent
set parentItem to make new data item at end of data items of dataSource
set contents of data cell “Item” of parentItem to “EEE”
set contents of data cell “Identity” of parentItem to “Parent”
– create child of second parent
set childItem to make new data item at end of data items of parentItem
set contents of data cell “Item” of childItem to “FFF”
set contents of data cell “Identity” of childItem to “Child”
– create third parent
set parentItem to make new data item at end of data items of dataSource
set contents of data cell “Item” of parentItem to “GGG”
set contents of data cell “Identity” of parentItem to “Parent”
– attach the data source
set data source of theObject to dataSource
end awake from nib

TheObject here is the outline view. Instead of data rows for tables, you use data items. I switched from using a launched handler to awake from nib because I couldn’t name the views in my version of IB.

gl,

Excellent! Thanks Kel…one small thing, though. I know you’re code works because I’m getting the proper number and position of disclosure arrows (so already I’m hours ahead of where I got yesterday). But…no text appears(!), just the arrows. Any ideas (anyone?) what to look for in my IB setup? or AppleScript? Thanks for your trouble.

Awaiting an embarrassingly simple answer… :slight_smile:

Hi dant,

In IB, at the bottom of the info palette for each of the two columns, type in the Identifier (Item for column 1 and Identity for column 2).

gl,

Bingo! Thanks Kel, that works perfectly…much obliged! :cool:

Hi dant,

Glad it worked for you.

I finally, remembered how to name things in IB. You can also name things in the AppleScript pane of the Info palette. That doesn’t make sense to me because it seems like you’re giving the script an internal name even if you’re not attaching a script to an object. Anyway, instead of using the Identifier field of the Attributes pane, you could have named it in the AppleScript pane.

gl,

Yep, you’re right. I removed the names from the Attributes palette, typed them in the AppleScript palette, rebuilt, and it still worked. I’m of the throw-it-against-the-wall persuasion, though, so whatever works :confused: (Obviously I’m not a commercial, but an internal, developer.)

Hi dant,

The best scripters are hobbyists, 'cause their range is unlimitted.

Have a good day,