6
votes

I'm using an NSOutlineView object to represent a file structure and am finding that it will not correctly indent any children which are expandable, though it will indent children that aren't.

Here's a picture to show what I mean:

NSOutlineView example

In this example, "AnotherFolder" is a child of "Folder2" yet it does not indent in line with the other indented files. Curiously enough, the child "AnotherFile.java" of "AnotherFolder" does indent correctly (2 levels in).

I have tried setting properties such as "indentationFollowsCells" to no avail. This seems as though it should be very simple but I can't solve it.

Thanks!

Edit: Some extra information upon request:

I am using the NSOutlineViewDataSource protocol for the implementation, here is the code related to that:

- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
    return item;
}

- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
    NSMutableDictionary* dict;
    if(item == nil) {
        dict = fileTree;
    } else {
        dict = [((MyFile*) item) children];
    }

    NSArray* keys = [dict allKeys];
    NSArray* sorted = [keys sortedArrayUsingSelector:@selector(compare:)];
    NSString* key = [sorted objectAtIndex:index];
    return [dict objectForKey:key];
}

- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
    return [[item children] count] > 0;
}

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
    if(item == nil) {
        return [fileTree count];
    }
    return [[item children] count];
}
2
You haven't provided any technical detail. Are you using Bindings or NSOutlineViewDataSource protocol? If the former, post a complete description of your bindings; if the latter, post a complete code listing of your data source protocol implementation. - Joshua Nozzi
@Joshua sure thing, updated the original post - Gary
Are you sure it doesn't indent all expandable children, or just those at the 2nd level? What if you have deeply nested expandable items? - jtbandes
@jtbandes: Good point. upon checking again, it seems that expandable items are always 1 level lower than they should be for indentation. Upon examining another level, I noticed it was 1 level indented when it should have been 2. - Gary
Try changing your outline view from a Source outline view to a normal one. - spudwaffle

2 Answers

7
votes

Try changing your outline view from a Source outline view to a normal one.

0
votes

I ran into this right now, and found it a bit strange that nine years after this post, the problem still persists.

This behaviour is baked into the Source style: the first row of the standard content is aligned with the header cell rather than indented, so everything is shifted over by one level.

If you use header cells, you want this behaviour, and everything is fine. If you don't want to use header cells, not using a SourceList is your only option.

incorrect indentation without header correctly indented SourceView with header cell