-
-
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-…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Cocoa/Cocoa.h> | |
@interface KSImageView : NSImageView | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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