• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSOutlineView drag and drop: how to prevent parent being dropped on one of its children
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOutlineView drag and drop: how to prevent parent being dropped on one of its children


  • Subject: Re: NSOutlineView drag and drop: how to prevent parent being dropped on one of its children
  • From: Koen van der Drift <email@hidden>
  • Date: Sat, 29 Oct 2011 18:37:02 -0400

Thanks Kyle, I'll try to apply that. In the meantime, I also found the AbstractView sample code which does something similar.  I'll see which one fits my code better.

- Koen.


On Oct 29, 2011, at 5:34 PM, Kyle Sluder wrote:

> On Sat, Oct 29, 2011 at 1:18 PM, Koen van der Drift
> <email@hidden> wrote:
>> I'm setting up drag and drop for my NSOutlineView and I want to prevent parents being dropped on one of their children. The parent and children are all of the Group entity. I understand I need to do this in the outlineView:validatedrop method. I think I need to create an NSFetchRequest with the NSPredictate to get all the children of the parent, but I don't know what the predicate should be.
>
> If your outline view is set up such that children are descendant items
> of their parents, you don't even need to round-trip to the model
> layer. You could implement something like the following:
>
> // Warning: typed in Mail, not guaranteed to work
>
> - (NSDragOperation)outlineView:(NSOutlineView *)outlineView
> validateDrop:(id < NSDraggingInfo >)info proposedItem:(id)item
> proposedChildIndex:(NSInteger)index
> {
>  NSArray *draggingItems = ItemsFromDragInfo(info);
>
>  NSMutableSet *parentTree = [[NSMutableSet alloc] init];
>  id parentItem = item;
>  while (parentItem) {
>    [parentTree addObject:item];
>    parentItem = [outlineView parentForItem:item];
>  }
>
>  NSDragOperation op = NSDragOperationMove;
>  for (id item in draggingItems) {
>    if ([parentTree containsobject:item]) {
>      op = NSDragOperationNone;
>      break;
>    }
>  }
>
>  [parentTree release];
>  return op;
> }
>
> --Kyle Sluder

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSOutlineView drag and drop: how to prevent parent being dropped on one of its children (From: Koen van der Drift <email@hidden>)
 >Re: NSOutlineView drag and drop: how to prevent parent being dropped on one of its children (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: NSOutlineView drag and drop: how to prevent parent being dropped on one of its children
  • Next by Date: Re: Future for Mac applications
  • Previous by thread: Re: NSOutlineView drag and drop: how to prevent parent being dropped on one of its children
  • Next by thread: NSMetadataQuery - Just a warning.
  • Index(es):
    • Date
    • Thread