Delete IKImageBrowserView drag and drop behavior

By default (it seems) IKImageBrowserView allows you to drag and drop objects into the Finder. I would like to disable this behavior, but I donโ€™t know how to do it. I thought that maybe implementing the NSDraggingDestination protocol and overriding it could solve this, but so far this has not worked for me.

Thanks for any help!

+4
source share
2 answers

If you want to customize the drag behavior of IKImageBrowserView, you can implement the - (NSUInteger) imageBrowser:(IKImageBrowserView *) aBrowser writeItemsAtIndexes:(NSIndexSet *) itemIndexes toPasteboard:(NSPasteboard *)pasteboard in the browser data source object. This will allow you to determine what types and data you want to place on the cardboard when you drag and drop. If you want to completely disable drag and drop, you can simply return 0 (the number of items you want to drag).

+6
source

If you are targeting Lion, you can subclass IKImageBrowserView and override the draggingSession:sourceOperationMaskForDraggingContext: NSDraggingSource method . To prevent drag and drop outside your application, simply return NSDragOperationNone if the context is NSDraggingContextOutsideApplication . Otherwise, return the drag and drop operations that interest you. Thus, you can prevent drag and drop to the desktop, Finder, etc., but still allow drag and drop in the application image viewer.

 - (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; } } 
+1
source

Source: https://habr.com/ru/post/1312692/


All Articles