1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- //
- // DropImageView.m
- // DragNDrop
- //
- // Created by Dominik Hofacker on 26.11.11.
- // Copyright (c) 2011 CCoding. All rights reserved.
- //
- #import "DropImageView.h"
- #import "ZGFileUtils.h"
- @implementation DropImageView
- @synthesize delegate = _delegate;
- - (id)initWithCoder:(NSCoder *)aDecoder {
-
- self = [super initWithCoder:aDecoder];
- if (self) {
- [self registeredDraggedTypes];
- }
-
- return self;
- }
- - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
- highlight = YES;
- [self setNeedsDisplay: YES];
- return NSDragOperationCopy;
- }
- - (void)draggingExited:(id<NSDraggingInfo>)sender {
- highlight = NO;
- [self setNeedsDisplay:YES];
- }
- - (void)drawRect:(NSRect)dirtyRect {
- [super drawRect:dirtyRect];
- if (highlight) {
- [[NSColor grayColor]set];
- [NSBezierPath setDefaultLineWidth:5];
- [NSBezierPath strokeRect:dirtyRect];
- }
- }
- - (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender {
- highlight = NO;
- [self setNeedsDisplay:YES];
- return YES;
- }
- - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
-
- if ([sender draggingSource] != self) {
- NSURL *fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
- // NSString *filePath = [[fileURL path] stringByAppendingString:@"/"];
- NSString *filePath = [fileURL path];
- if ([ZGFileUtils pathIsDirectory:[fileURL path]]) {
- [_delegate dropImageView:self didSelectDirectory:filePath];
- } else {
- [_delegate dropImageView:self didSelectFile:filePath];
- }
- }
-
- return YES;
- }
- @end
|