views:

35

answers:

1

Hey experts,

When I drag rows from an NSTableView to another NSOutlineView, the NSOutlineView gets a yellow highlighting border. How do I avoid that?

To be precise, this happens only if I drag the rows from the table into the free space (i.e. not on any items) of the NSTableView. However, when I drag the rows directly on items in the NSOutlineView, the yellow border does not show up, but (of course) the items get selected themselves.

The important part of outlineView:validateDrop:proposedItem:proposedChildIndex: in NSOutlineViews' data source looks like this:

- (NSDragOperation)outlineView:(NSOutlineView *)outlineView 
                  validateDrop:(id <NSDraggingInfo>)info 
                  proposedItem:(id)item 
            proposedChildIndex:(NSInteger)index
{
    if ([info draggingSource] == myOtherTableView) {
        [outlineView setDropItem:item 
                  dropChildIndex:NSOutlineViewDropOnItemIndex];
        return NSDragOperationMove;
    }

    return NSDragOperationNone;
}

Thanks for any help!

A: 

When NSOutlineView proposes a drop not on any particular item (resulting in the whole-border highlighting you're seeing), it will pass in an item of nil and a proposedChildIndex of NSOutlineViewDropOnItemIndex. You can test for this to tell when NSOutlineView is proposing this drop and return NSDragOperationNone to not allow a drop at all on that region.

- (NSDragOperation)outlineView:(NSOutlineView *)outlineView 
                  validateDrop:(id <NSDraggingInfo>)info 
                  proposedItem:(id)item 
            proposedChildIndex:(NSInteger)index
{
    if ([info draggingSource] == myOtherTableView) {
        if (item == nil)
            return NSDragOperationNone;
        else
        {
            [outlineView setDropItem:item 
                  dropChildIndex:NSOutlineViewDropOnItemIndex];
            return NSDragOperationMove;
        }
    }
    return NSDragOperationNone;
}
Brian Webster