6

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];
}
Gary
  • 926
  • 3
  • 12
  • 24
  • 1
    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 Aug 08 '11 at 14:15
  • @Joshua sure thing, updated the original post – Gary Aug 08 '11 at 23:28
  • 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 Aug 09 '11 at 05:28
  • @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 Aug 09 '11 at 06:04
  • In that case, this is the normal behavior, and I'm pretty sure there are other questions about the same thing. I'll try to find one. – jtbandes Aug 09 '11 at 06:07
  • @jtbandes I've looked but not found any similar questions with an answer yet. If you find one, please post it as an answer – Gary Aug 09 '11 at 06:51
  • 1
    Try changing your outline view from a **Source** outline view to a normal one. – spudwaffle Aug 09 '11 at 17:06
  • @spudwaffle you should have posted that as an answer, that was exactly what I was after. Thanks! Not sure how I missed that.. – Gary Aug 10 '11 at 00:02

2 Answers2

7

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

spudwaffle
  • 2,905
  • 1
  • 22
  • 29
  • 1
    +1 Wow, thank you for this. This problem was driving me crazy! It took me awhile to figure out you meant the highlight style in interface builder... but I found it so thanks. – regulus6633 Dec 11 '12 at 23:18
0

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

green_knight
  • 1,319
  • 14
  • 26