From 51a99a8bd01f670bba0af0a591ebbfc79e4e8a4f Mon Sep 17 00:00:00 2001 From: michael starke Date: Thu, 14 Sep 2017 00:32:20 +0200 Subject: [PATCH] drag and drop for icon files is working --- MacPass/Base.lproj/IconSelection.xib | 2 +- MacPass/MPIconSelectViewController.m | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/MacPass/Base.lproj/IconSelection.xib b/MacPass/Base.lproj/IconSelection.xib index a05832dd..948bc0df 100644 --- a/MacPass/Base.lproj/IconSelection.xib +++ b/MacPass/Base.lproj/IconSelection.xib @@ -83,7 +83,7 @@ - + diff --git a/MacPass/MPIconSelectViewController.m b/MacPass/MPIconSelectViewController.m index 5d3313cd..15e8216c 100644 --- a/MacPass/MPIconSelectViewController.m +++ b/MacPass/MPIconSelectViewController.m @@ -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 )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