Question

By default (it seems), IKImageBrowserView enables drag and drop to locations in the Finder. I would like to turn off this behavior but am unsure of how to do so. I was thinking that perhaps implementing the NSDraggingDestination protocol and overriding it could solve this, but so far it hasn't worked for me.

Thanks for any help!

Was it helpful?

Solution

If you want to customize IKImageBrowserView's drag and drop behavior, you can implement the - (NSUInteger) imageBrowser:(IKImageBrowserView *) aBrowser writeItemsAtIndexes:(NSIndexSet *) itemIndexes toPasteboard:(NSPasteboard *)pasteboard method in your browser's data source object. That will let you define what types and data you want to put on the pasteboard when doing a drag. If you want to disable dragging entirely, you should be able to just return 0 (the number of items you want to be dragged).

OTHER TIPS

If you're targeting Lion you can subclass IKImageBrowserView and override the draggingSession:sourceOperationMaskForDraggingContext: NSDraggingSource protocol method. To prevent drags outside of your application just return NSDragOperationNone if the context is NSDraggingContextOutsideApplication. Otherwise, return the dragging operations that you're interested in. This way you can disallow drags to the desktop, Finder, etc. but still permit drags within your application's image browser view.

- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
    [super draggingSession:session sourceOperationMaskForDraggingContext:context];

    switch (context) {
        case NSDraggingContextOutsideApplication:
            return NSDragOperationNone;
            break;

        case NSDraggingContextWithinApplication:
            return NSDragOperationAll;
            break;

        default:
            return NSDragOperationAll;
            break;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top