Re: Copy-dragging in an NSTableView
Re: Copy-dragging in an NSTableView
- Subject: Re: Copy-dragging in an NSTableView
- From: Sean Murphy <email@hidden>
- Date: Thu, 9 Aug 2007 15:19:36 -0400
On Aug 8, 2007, at 12:01 PM, Andrew Merenbach wrote:
I'm trying to implement copy-dragging in a table view--that is to
say, I want rows to move when no modifier keys are held down (which
I have working) and I would like rows to be copied when the option
key is held down (with which I am having trouble).
I have overridden the following method in my table view:
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)flag
{
return flag ? NSDragOperationMove : NSDragOperationCopy |
NSDragOperationCopy;
}
and I have tried to test for the dragging operation in the
tableView:acceptDrop... method--but it always comes out to
NSDragOperationCopy. I found two references in the archives to
this, but no one actually mentions their solution.
The "flag" argument to the above draggingSourceOperationMaskForLocal:
is often alternatively named "isLocal," and the description of this
parameter from the ADC is:
isLocal
YES indicates that the candidate destination object (the window or
view over which the dragged image is currently poised) is in the same
application as the source, while a NO value indicates that the
destination object is in a different application.
In the code you listed, drags beginning and ending within your own
application will always take the first path and return
NSDragOperationMove (so I'm confused as to why NSDragOperationCopy
was always occurring for you - probably an issue with that syntax).
Since you're going after drag and drop reordering in the same
NSTableView, you should allow your desired behavior (move and copy)
when isLocal (flag) is true:
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)isLocal
{
if (isLocal)
return (NSDragOperationCopy | NSDragOperationMove);
return (NSDragOperationNone);
}
I'm not sure about which operations NSTableView's default
implementation of draggingSourceOperationMaskForLocal: will return if
the drag is local, but you might want to make sure that you actually
need to subclass it. If the drag is not local, the default
implementation returns NSDragOperationNone.
If the above does not help, maybe posing your code from
tableView:acceptDrop:row:dropOperation: would allow further
troubleshooting here.
For more information about the method in question:
<http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/Protocols/NSDraggingSource_Protocol/Reference/
Reference.html#//apple_ref/occ/instm/NSObject/
draggingSourceOperationMaskForLocal:>
- Sean
_______________________________________________
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