Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSOutlineView validateDrop Flips Values



I'm attempting to add drag and drop support to an outline view in my app (proving to be more difficult than I thought it would be) and I came across a weird behavior. If I drag an item and hold it on top of an item in the list, the proposedItem parameter to validateDrop:proposedItem:proposedChildIndex: flips between an appropriate value and nil every other time the message is sent. This is without moving the mouse or anything. It simply changes on it's own and I'm not sure why.


Hopefully this is easy enough to understand:

- (NSDragOperation)outlineView:(NSOutlineView*)olv validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)childIndex
{
// This method validates whether or not the proposal is a valid one. Returns NO if the drop should not be allowed.
id <FileSystemItem> targetNode = item;
BOOL targetNodeIsValid = YES;
BOOL isOnDropTypeProposal = (childIndex == NSOutlineViewDropOnItemIndex);

if (item == nil)
NSLog(@"Item is nil");
else
NSLog(@"Item is not nil");


// Refuse if: dropping "on" the view itself unless we have no data in the view.
if (targetNode == nil && childIndex == NSOutlineViewDropOnItemIndex && [[self currentDirectory] numberOfChildren] != 0)
targetNodeIsValid = NO;

if (targetNode == nil && childIndex == NSOutlineViewDropOnItemIndex && NO == NO) // first no is: [self allowOnDropOnLeaf]
targetNodeIsValid = NO;

// Refuse if: we are trying to do something which is not allowed as specified by the UI check boxes.
if ((targetNodeIsValid && isOnDropTypeProposal==NO && YES == NO) || // Drop Between
([targetNode isDirectory] && isOnDropTypeProposal == YES && YES == NO) || // Drop On Group
([targetNode isDirectory] == NO && isOnDropTypeProposal == YES && NO == NO)) // Drop on Item
targetNodeIsValid = NO;

// Set the item and child index in case we computed a retargeted one.
[olv setDropItem:targetNode dropChildIndex:childIndex];

return targetNodeIsValid ? NSDragOperationMove : NSDragOperationNone;
}




Thanks,


-- Seth

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.