Repository navigation
Expand file tree
/
Copy pathImleeDragAndDropView.m
More file actions
59 lines (49 loc) · 1.54 KB
/
Copy pathImleeDragAndDropView.m
File metadata and controls
59 lines (49 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// ImleeDragAndDropView.m
// Imlee
//
// Created by Devarshi Kulshreshtha on 6/22/12.
// Copyright 2012 DaemonConstruction. All rights reserved.
//
#import "ImleeDragAndDropView.h"
#import "ImleeModelDelegate.h"
@implementation ImleeDragAndDropView
@synthesize delegate = _delegate;
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
[self setAnimates:YES]; // to automatically play animated images
// register for all image types
[self registerForDraggedTypes:[NSImage imagePasteboardTypes]];
}
return self;
}
#pragma mark implementing drag and drop
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
if (![[[[self delegate] imageTypes] valueForKey:@"imageTypeName"] containsObject:[[[NSURL URLFromPasteboard:[sender draggingPasteboard]] path] pathExtension]]) {
return NSDragOperationNone;
}
return NSDragOperationCopy;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pasteboard = [sender draggingPasteboard];
//FIXME: remove setCurrentImage and use only setCurrentImagePath to show image
NSImage *anImage = [[NSImage alloc] initWithPasteboard:pasteboard];
[[self delegate] setCurrentImage:anImage];
[anImage release];
[[self delegate] setCurrentImagePath:[[NSURL URLFromPasteboard:pasteboard] path]];
return YES;
}
#pragma mark handing mouse down action
- (void)mouseDown:(NSEvent *)theEvent
{
[[self delegate] openImage];
}
@end