| 9 |
|
|
| 10 |
#import "CRDropView.h" |
#import "CRDropView.h" |
| 11 |
#import <Foundation/Foundation.h> |
#import <Foundation/Foundation.h> |
| 12 |
|
#import "NSImage+data.h" |
| 13 |
|
|
| 14 |
@implementation CRDropView |
@implementation CRDropView |
| 15 |
|
|
| 38 |
// Drawing code here. |
// Drawing code here. |
| 39 |
} |
} |
| 40 |
|
|
|
//画像ファイルのチェック |
|
|
- (BOOL)isImageFile:(NSString*)filePath |
|
|
{ |
|
|
BOOL isImageFile = NO; |
|
|
LSItemInfoRecord info; |
|
|
CFStringRef uti = NULL; |
|
|
@try { |
|
|
|
|
|
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, |
|
|
(CFStringRef)filePath, kCFURLPOSIXPathStyle, FALSE); |
|
|
|
|
|
if (LSCopyItemInfoForURL(url, kLSRequestExtension | |
|
|
kLSRequestTypeCreator, &info) == noErr) |
|
|
{ |
|
|
if (info.extension != NULL) |
|
|
{ |
|
|
uti = |
|
|
UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, |
|
|
info.extension, kUTTypeData); |
|
|
CFRelease(info.extension); |
|
|
} |
|
|
|
|
|
if (uti == NULL) |
|
|
{ |
|
|
CFStringRef typeString = |
|
|
UTCreateStringForOSType(info.filetype); |
|
|
if ( typeString != NULL) |
|
|
{ |
|
|
uti = |
|
|
UTTypeCreatePreferredIdentifierForTag(kUTTagClassOSType, |
|
|
typeString, kUTTypeData); |
|
|
CFRelease(typeString); |
|
|
} |
|
|
} |
|
|
|
|
|
if (uti != NULL) |
|
|
{ |
|
|
CFArrayRef supportedTypes = |
|
|
CGImageSourceCopyTypeIdentifiers(); |
|
|
CFIndex i, typeCount = CFArrayGetCount(supportedTypes); |
|
|
|
|
|
for (i = 0; i < typeCount; i++) |
|
|
{ |
|
|
if (UTTypeConformsTo(uti, |
|
|
(CFStringRef)CFArrayGetValueAtIndex(supportedTypes, i))) |
|
|
{ |
|
|
isImageFile = YES; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
@catch (NSException *exception) { |
|
|
|
|
|
} |
|
|
@finally { |
|
|
} |
|
|
|
|
|
return isImageFile; |
|
|
} |
|
| 41 |
|
|
| 42 |
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender |
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender |
| 43 |
{ |
{ |
| 115 |
|
|
| 116 |
for (NSString *filename in array) { |
for (NSString *filename in array) { |
| 117 |
filename = [path stringByAppendingPathComponent:filename]; |
filename = [path stringByAppendingPathComponent:filename]; |
| 118 |
if ([self isImageFile:filename]) { |
if ([NSImage isImageFile:filename]) { |
| 119 |
NSLog(@"%@", filename); |
NSLog(@"%@", filename); |
| 120 |
[self._files addObject:filename]; |
[self._files addObject:filename]; |
| 121 |
} |
} |
| 122 |
} |
} |
| 123 |
} else { |
} else { |
| 124 |
if ([self isImageFile:path]) { |
if ([NSImage isImageFile:path]) { |
| 125 |
[self._files addObject:path]; |
[self._files addObject:path]; |
| 126 |
} |
} |
| 127 |
} |
} |
| 128 |
|
|
| 129 |
} |
} |
|
|
|
| 130 |
} |
} |
| 131 |
|
|
| 132 |
//ファイルがドロップされた事への通知、これでTableViewが更新される |
//ファイルがドロップされた事への通知、これでTableViewが更新される |
| 147 |
return YES; |
return YES; |
| 148 |
} |
} |
| 149 |
|
|
| 150 |
|
|
| 151 |
@end |
@end |