hi to all,
is it possible to append a data source that is connected to an outline view with a list like this:
{"Group 1", "Group 2"}
to display this:
Group 1
Group 2
and how can i add child items in the list
thx,
gecko
hi to all,
is it possible to append a data source that is connected to an outline view with a list like this:
{"Group 1", "Group 2"}
to display this:
Group 1
Group 2
and how can i add child items in the list
thx,
gecko
Working with outline views by supplying a dynamic source list as a data source is REALLY ugly. For simple tasks, it’s fairly straightforward, but if you’ve got a deep, complicated tree of items it can be a serious challenge. This is primarily because applescript studio doesn’t support dictionaries (record lists) very well. In obj-c, we can use a bunch of methods to dynamically access subitems and make references to objects by their location in a dictionary. In ASS we can’t do that as easily, so we’re forced to use ugly lists of lists that must be contructed by hand. The best way around this is to put the effort into learning how to use the outlineview datasource model that is covered in the doc and in apple’s outlineview and tableview examples. When you’re done managing the data source, you can use built-in methods to extract the list of lists and get around creating it yourself. If you must do it manually, here’s some simple code that shows how to structure the list and then send it to the outline view. As I said, it’s very complicated to manage an outlineview data source this way, because you can’t simply add items to sublists without writing some pretty hefty code to break down and reconstruct the nested lists every time you make a change.
property OutlineView : null
property dataList : {}
on will finish launching theObject
set dataList to {{"parent1", {"child1a"}, {"child1b", {"subchild1b.1"}}}, {"parent2", {"child2a"}}}
end will finish launching
on awake from nib theObject
if name of theObject is "OutlineView" then
set OutlineView to theObject
end if
end awake from nib
on launched theObject
set content of OutlineView to dataList
show window "Window"
end launched
Hope this helps,
j
thx,
that helped. i was just trying to figure out how the data source was storing the values for use with a table view.
thx anyway
gecko
also,
What is the easiest way to create an outline view that displays the hierarchy of all the folders of a folder and their children and their childrens children for an unlimited number of levels?
thanks for all your help
gecko
There are four required handlers that you must use, and you of course must provide the path to the directory. I find that it’s best to make sure that the window is NOT set to open on launch, and open it myself programmatically. Also, don’t forget to tell the outlineview to update, so it knows that it’s supposed to reload the data using the handlers outlined below. Note that the code below only updates the root list on launch. In practice, you’de want to create a handler that updated the path to the directory and then updated the outlineview, so you could programmatically force the outlineview to reflect changes when you know they’ve been made.
property rootDirectory : "/Developer/"
property rootDirectoryItems : {}
---> The following three handlers are called in the order in which they're listed in the code
---> If you initialize data or reference objects out of order you'll run into problems
on will finish launching theObject
(* Create a list that contains all of the items for the root level *)
tell application "Finder" to set rootDirectoryItems to (items of ((POSIX file rootDirectory) as alias))
end will finish launching
on awake from nib theObject
if name of theObject is "OutlineView" then
tell theObject to update
end if
end awake from nib
on launched theObject
show window "Window"
end launched
(* 4 required handlers for managing the outline view datasource *)
on child of item theObject child theChild outline item outlineItem
set childItem to ""
try
tell application "Finder"
if outlineItem is 0 then
set childItem to (get item theChild of rootDirectoryItems as string) as string
else
set childItem to item theChild of (get item outlineItem) as string
end if
end tell
end try
return childItem
end child of item
on item value theObject table column tableColumn outline item outlineItem
set itemValue to ""
try
tell application "Finder"
set itemValue to displayed name of (get item outlineItem) as string
end tell
end try
return itemValue
end item value
on number of items theObject outline item outlineItem
set itemCount to 0
try
tell application "Finder"
if (count of rootDirectoryItems) > 0 then
if outlineItem is 0 then
set itemCount to count of rootDirectoryItems
else
set itemCount to count of items of (get item ((outlineItem as string) as alias))
end if
end if
end tell
end try
return itemCount
end number of items
on item expandable theObject outline item outlineItem
set isExpandable to false
try
if outlineItem is 0 then
if (count of rootDirectoryItems) is greater than 1 then
set isExpandable to true
end if
else
tell application "Finder"
if (count of items of (get item outlineItem)) is greater than 0 then
set isExpandable to true
else if kind of (get item outlineItem) is "folder" then
set isExpandable to true
end if
end tell
end if
end try
return isExpandable
end item expandable
Working with outline views in ASStudio sucks. It’s slow, and unless you want to learn some cocoa methods to replace all of the finder calls you’re stuck with it being that way. I’ve turned to obj-c to do all of my outlineviews, and I’m much happier now. Everything runs lots faster, and I’m able to provide custom cells that also display the icon of each item. The above code will get you started in ASS, but if that’s not enough for you, you may want to expand your horizons and look at obj-c for your OV data sources instead.
j