Skip to content

Instantly share code, notes, and snippets.

@pallavtrivedi03
Created March 12, 2018 20:26
Show Gist options
  • Save pallavtrivedi03/1d299fc5e1d6753e3d7bfc797c967fa9 to your computer and use it in GitHub Desktop.
Save pallavtrivedi03/1d299fc5e1d6753e3d7bfc797c967fa9 to your computer and use it in GitHub Desktop.
extension HomeViewController: DragDropViewDelegate
{
func draggedMediaType(type: MediaType, url: NSURL) {
switch type {
case .audio:
self.createDirectory(sourcePath: url.absoluteString!, type: .audio)
case .video:
self.createDirectory(sourcePath: url.absoluteString!, type: .video)
case .image:
self.createDirectory(sourcePath: url.absoluteString!, type: .image)
case .document:
self.createDirectory(sourcePath: url.absoluteString!, type: .document)
}
}
}
extension HomeViewController: NSCollectionViewDataSource, NSCollectionViewDelegate
{
func numberOfSections(in collectionView: NSCollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
return files.count
}
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
let item = collectionView.makeItem(withIdentifier: "CollectionViewItem", for: indexPath)
guard let collectionViewItem = item as? CollectionViewItem else {return item}
let mediaName = Array(files.keys)[indexPath.item]
collectionViewItem.imageView?.image = files[mediaName]?.image
collectionViewItem.textField?.stringValue = mediaName
return item
}
func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>)
{
guard let indexPath = indexPaths.first else {
return
}
let mediaName = Array(files.keys)[indexPath.item]
let url = files[mediaName]?.url
NSWorkspace.shared().open(url!)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment