문제

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!

도움이 되었습니까?

해결책

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).

다른 팁

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;
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top