Skip to content

Instantly share code, notes, and snippets.

@ThatsJustCheesy
Forked from vigorouscoding/KSImageView.h
Last active August 18, 2018 23:40
Show Gist options
  • Save ThatsJustCheesy/5ec55b40d6319c303f84159ba1ec6620 to your computer and use it in GitHub Desktop.
Save ThatsJustCheesy/5ec55b40d6319c303f84159ba1ec6620 to your computer and use it in GitHub Desktop.
Forked from @vigorouscoding 's original and modernized. NSImageView subclass to get the filename of the dropped image and to disable deleting and cutting the image. The class sends a "KSImageDroppedNotification" with the image filename in the userinfo dictionary. vigorouscoding got the idea from: http://www.cocoabuilder.com/archive/cocoa/121824-…
#import <Cocoa/Cocoa.h>
@interface KSImageView : NSImageView
@end
#import "KSImageView.h"
@implementation KSImageView
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender {
NSPasteboard *pboard = sender.draggingPasteboard;
NSString *plist = [pboard stringForType:NSFilenamesPboardType];
if (!plist) return;
NSArray<NSString*> *files =
[NSPropertyListSerialization propertyListWithData:[plist dataUsingEncoding:NSUTF8StringEncoding]
options:NSPropertyListImmutable
format:NULL
error:NULL];
if (files.count == 0) return;
NSDictionary *userInfo = @{@"imagePath": files[0]};
[[NSNotificationCenter defaultCenter] postNotificationName:@"KSImageDroppedNotification"
object:self
userInfo:userInfo];
}
- (void)delete:(id)sender {
}
- (void)cut:(id)sender {
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment