NSOutlineView validateDrop Flips Values
NSOutlineView validateDrop Flips Values
- Subject: NSOutlineView validateDrop Flips Values
- From: Seth Willits <email@hidden>
- Date: Mon, 31 Jan 2005 18:18:59 -0800
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:
This email sent to email@hidden