drag and drop for icon files is working

This commit is contained in:
michael starke
2017-09-14 00:32:20 +02:00
parent cc69db11d3
commit 51a99a8bd0
2 changed files with 22 additions and 4 deletions

View File

@@ -83,7 +83,7 @@
<constraint firstItem="57" firstAttribute="top" secondItem="1" secondAttribute="top" constant="20" symbolic="YES" id="iuz-pK-yXC"/>
<constraint firstItem="101" firstAttribute="leading" secondItem="8kv-BJ-IEk" secondAttribute="trailing" constant="8" symbolic="YES" id="nvi-CZ-a6L"/>
</constraints>
<point key="canvasLocation" x="-43" y="90"/>
<point key="canvasLocation" x="-143" y="15"/>
</customView>
<collectionViewItem id="61">
<connections>

View File

@@ -43,7 +43,7 @@
self.iconCollectionView.selectable = YES;
self.iconCollectionView.allowsMultipleSelection = NO;
self.iconCollectionView.delegate = self;
//[self.iconCollectionView registerForDraggedTypes:@[(NSString *)kUTTypeURL, (NSString *)kUTTypeFileURL]];
[self.iconCollectionView registerForDraggedTypes:@[(NSString *)kUTTypeURL, (NSString *)kUTTypeFileURL]];
MPDocument *document = [NSDocumentController sharedDocumentController].currentDocument;
self.iconCollectionView.content = document.tree.metaData.customIcons;
@@ -95,8 +95,26 @@
}
- (BOOL)collectionView:(NSCollectionView *)collectionView acceptDrop:(id <NSDraggingInfo>)draggingInfo index:(NSInteger)index dropOperation:(NSCollectionViewDropOperation)dropOperation {
NSLog(@"Index:%ld", index);
return YES;
NSPasteboard *pBoard = [draggingInfo draggingPasteboard];
NSArray *urls = [pBoard readObjectsForClasses:@[NSURL.class] options:@{ NSPasteboardURLReadingFileURLsOnlyKey : @YES }];
if(urls.count == 0) {
return NO;
}
BOOL success = NO;
MPDocument *document = [NSDocumentController sharedDocumentController].currentDocument;
for(NSURL *url in urls) {
KPKIcon *icon = [[KPKIcon alloc] initWithImageAtURL:url];
if(icon.image) {
NSLog(@"Added Icon at:%@", url);
[document.tree.metaData addCustomIcon:icon];
success = YES;
}
}
if(success) {
self.iconCollectionView.content = document.tree.metaData.customIcons;
self.iconCollectionView.content = [[MPIconHelper databaseIcons] arrayByAddingObjectsFromArray:document.tree.metaData.customIcons];
}
return success;
}
@end