Note that there are some explanatory texts on larger screens.

plurals
  1. POLimit allowed operations to only NSDragOperationCopy
    primarykey
    data
    text
    <p>I have a custom view that is a drag source. I want to limit the allowed drag operations to only a copy, and hence I return NSDragOperationCopy in my draggingSession:sourceOperationMaskForDraggingContext: method.</p> <p>For some reason this has no effect.</p> <p>There doesn't seem to be anything wrong with my code as returning NSDragOperationNone works as expected and blocks drags.</p> <p>Below is the code from my NSView that is the dragging source. Dragging from the view to the "Trash" you'll see a NSDragOperationMove or NSDragOperationDelete even though I only want to allow the NSDragOperationCopy operation.</p> <p>I've also uploaded a small demo project to demonstrate what I'm talking about: <a href="https://dl.dropbox.com/u/368222/test.zip" rel="nofollow">https://dl.dropbox.com/u/368222/test.zip</a>.</p> <pre><code>- (void)mouseDown:(NSEvent *)event { NSString *path = [[NSBundle mainBundle] resourcePath]; NSString *imagePath = [path stringByAppendingString:@"/image.png"]; NSImage *image = [[NSImage alloc] initWithContentsOfFile:imagePath]; NSArray *file = [NSArray arrayWithObject:imagePath]; NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; [pboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil]; [pboard setPropertyList:file forType:NSFilenamesPboardType]; [self dragImage:image at:NSZeroPoint offset:NSMakeSize(0, 0) event:event pasteboard:pboard source:self slideBack:NO]; } - (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context { return NSDragOperationCopy; } - (void)draggingSession:(NSDraggingSession *)session endedAtPoint:(NSPoint)screenPoint operation:(NSDragOperation)operation { NSLog(@"Dragging session ended with operation: %li", operation); } </code></pre> <p>Anyone?</p> <p>Thx!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload