ASOC NSOutlineView Example?

Hello,

OutlineViews are very common in Mac interface, the better example is Xcode itself. So they should be widely documented. But they are only a few examples (like the Apple’s “SourceView” downloadable project), and they are in Objective-C and some of them rely on subclassing/overriding.

They are a number of concepts to understand if you want to use this class:

M: Of what kind is the data source? it is possible to use an already defined structure like a .plist?
V: The setup and the bindings of the NSOutlineView are unclear: how many columns? data or cell based?
C: What kind of controller to use? a dictionary or a tree controller?

The problem is, NSOutlineView may certainly be replaced with some other objects, like NSTableViews, but:
a) I’m not sure that to make a table view “look like” an outline view would be more simple than to implement a real outline view;
b) users are so familiar with outline views that presenting another interface would certainly confuse them.

So my request is: could somebody, using pure ASOC (without subclassing) and IB bindings explain to us how the whole thing works and give some hints to implement one of these NSOutlineViews?

Note that I didn’t say “and make it simple”.:slight_smile:

Regards,

Ok, so far:

The app delegates must implement four methods. Could somebody translate this Obj-C for me, please?

For example, what could be this line

once translated into any comprehensive (say, high-level) language?

@implementation DataSource

// Data Source methods

  • (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
    return (item == nil) ? 1 : [item numberOfChildren];
    }

  • (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
    return (item == nil) ? YES : ([item numberOfChildren] != -1);
    }

  • (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
    return (item == nil) ? [FileSystemItem rootItem] : [(FileSystemItem *)item childAtIndex:index];
    }

  • (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
    return (item == nil) ? @“/” : (id)[item relativePath];
    }

// Delegate methods

  • (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item {
    return NO;
    }

@end

Thank you,

The one you asked about, I can’t quite figure out, but the one above is equivalent to this in applescript:

if item is missing value then
    return 1
else
    return item's numberOfChildren()
end if

It’s just a C shortcut for an if-then-else statement.
You don’t necessarily need to implement those data source methods, you can also do outline views with bindings. I have an example that I made a while ago, but I’m not at my home computer now. I’ll send you a copy when I get home on Thursday or Friday.

Ric