I've got NSOutlineView that, at the moment, only lists children of the root item. Everything works except when I try to rearrange items using drag & drop. The line with the circle in front of it always stays above the top row and doesn't follow my items when they need to be dragged between other items. However, I still get the index positions properly so I can still rearrange them in the datasource properly. I don't want to rearrange items by dragging them onto each other, I only want to rearrange the items off the root level (like the VLC playlist on the Mac).
Here are my four required methods:
//queue is a C-based data structure
-(NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
if(item == nil){
return queue.count; //each list item
}else{
return 0; //no children of each list item allowed
}
}
-(id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
{
if(item != nil) return nil;
return [[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithLong:index],@"index",
[NSString stringWithFormat:@"%s",queue.item[index].filepath],@"filePath",
nil] copy];
}
-(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
if(item == nil){
return YES;
}else{
return NO;
}
}
-(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
if(item == nil) return nil;
return [item objectForKey:[tableColumn identifier]];
}
And my drag methods:
-(BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard
{
[pasteboard declareTypes:[NSArray arrayWithObject:LOCAL_REORDER_PASTEBOARD_TYPE] owner:self];
[pasteboard setData:[NSData data] forType:LOCAL_REORDER_PASTEBOARD_TYPE];
return YES;
}
-(NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
{
NSUInteger op = NSDragOperationNone;
if(index != NSOutlineViewDropOnItemIndex){
op = NSDragOperationMove;
}
return op;
}