diff --git a/Persephone.xcodeproj/project.pbxproj b/Persephone.xcodeproj/project.pbxproj index 9d394ac..1fe455b 100644 --- a/Persephone.xcodeproj/project.pbxproj +++ b/Persephone.xcodeproj/project.pbxproj @@ -41,6 +41,8 @@ E435E3E4221CD75D00184CFC /* NSImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = E435E3E3221CD75D00184CFC /* NSImage.swift */; }; E439109822640213002982E9 /* SongNotifierService.swift in Sources */ = {isa = PBXBuildFile; fileRef = E439109722640213002982E9 /* SongNotifierService.swift */; }; E43AC1F122C68E6A001E483C /* NSPasteboardItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = E43AC1F022C68E6A001E483C /* NSPasteboardItem.swift */; }; + E43AC1F522C6A4F4001E483C /* DraggedAlbum.swift in Sources */ = {isa = PBXBuildFile; fileRef = E43AC1F422C6A4F4001E483C /* DraggedAlbum.swift */; }; + E43AC1F622C6AD0B001E483C /* AlbumViewController+NSCollectionViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E43AC1F222C6A439001E483C /* AlbumViewController+NSCollectionViewDelegate.swift */; }; E43B67AA22909793007DCF55 /* AlbumDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E43B67A822909793007DCF55 /* AlbumDetailView.swift */; }; E43B67AB22909793007DCF55 /* AlbumDetailView.xib in Resources */ = {isa = PBXBuildFile; fileRef = E43B67A922909793007DCF55 /* AlbumDetailView.xib */; }; E43B67AD229194CD007DCF55 /* AlbumTracksDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = E43B67AC229194CD007DCF55 /* AlbumTracksDataSource.swift */; }; @@ -236,6 +238,8 @@ E435E3E3221CD75D00184CFC /* NSImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSImage.swift; sourceTree = ""; }; E439109722640213002982E9 /* SongNotifierService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SongNotifierService.swift; sourceTree = ""; }; E43AC1F022C68E6A001E483C /* NSPasteboardItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSPasteboardItem.swift; sourceTree = ""; }; + E43AC1F222C6A439001E483C /* AlbumViewController+NSCollectionViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AlbumViewController+NSCollectionViewDelegate.swift"; sourceTree = ""; }; + E43AC1F422C6A4F4001E483C /* DraggedAlbum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraggedAlbum.swift; sourceTree = ""; }; E43B67A822909793007DCF55 /* AlbumDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlbumDetailView.swift; sourceTree = ""; }; E43B67A922909793007DCF55 /* AlbumDetailView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AlbumDetailView.xib; sourceTree = ""; }; E43B67AC229194CD007DCF55 /* AlbumTracksDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlbumTracksDataSource.swift; sourceTree = ""; }; @@ -646,6 +650,7 @@ E43B67A822909793007DCF55 /* AlbumDetailView.swift */, E4E7A6AC22AAAF98006D566C /* AlbumDetailView+NSTableViewDelegate.swift */, E408D3C1220E134F0006D9BE /* AlbumViewController.swift */, + E43AC1F222C6A439001E483C /* AlbumViewController+NSCollectionViewDelegate.swift */, E47E2FD4222071FD00F747E6 /* AlbumViewItem.swift */, E47E2FD022205C4600F747E6 /* MainSplitViewController.swift */, E4405191227644340090CD6F /* MPDServerController.swift */, @@ -691,6 +696,7 @@ E4B11B72226A6C770075461B /* TrackTimer.swift */, E451E36A22BD214D008BE9B2 /* DraggedSongType.swift */, E451E36C22BD23DB008BE9B2 /* DraggedSong.swift */, + E43AC1F422C6A4F4001E483C /* DraggedAlbum.swift */, ); path = Models; sourceTree = ""; @@ -888,8 +894,10 @@ E4F6B467221E233200ACF42A /* AlbumDataSource.swift in Sources */, E4B11BA92274EDE30075461B /* Loading.swift in Sources */, E408D3C2220E134F0006D9BE /* AlbumViewController.swift in Sources */, + E43AC1F522C6A4F4001E483C /* DraggedAlbum.swift in Sources */, E40FE71B221B904300A4223F /* NSEvent.swift in Sources */, E4B11BB62275374B0075461B /* UserNotificationsController.swift in Sources */, + E43AC1F622C6AD0B001E483C /* AlbumViewController+NSCollectionViewDelegate.swift in Sources */, E4B11B68226A4FA00075461B /* QueueState.swift in Sources */, E4928E0B2218D62A001D4BEA /* CGColor.swift in Sources */, E4D3BFA622B419C000C56F48 /* QueueViewController+NSOutlineViewDelegate.swift in Sources */, diff --git a/Persephone/Controllers/AlbumViewController+NSCollectionViewDelegate.swift b/Persephone/Controllers/AlbumViewController+NSCollectionViewDelegate.swift new file mode 100644 index 0000000..e5e5eb2 --- /dev/null +++ b/Persephone/Controllers/AlbumViewController+NSCollectionViewDelegate.swift @@ -0,0 +1,32 @@ +// +// AlbumViewController+NSCollectionViewDelegate.swift +// Persephone +// +// Created by Daniel Barber on 2019/6/28. +// Copyright © 2019 Dan Barber. All rights reserved. +// + +import AppKit + +extension AlbumViewController: NSCollectionViewDelegate { + func registerForDragAndDrop(_ collectionView: NSCollectionView) { + collectionView.registerForDraggedTypes([.albumPasteboardType]) + collectionView.setDraggingSourceOperationMask(.every, forLocal: true) + } + + func collectionView(_ collectionView: NSCollectionView, pasteboardWriterForItemAt index: Int) -> NSPasteboardWriting? { + let album = dataSource.albums[index] + + return NSPasteboardItem( + draggedAlbum: DraggedAlbum( + title: album.title, + artist: album.artist + ), + ofType: .albumPasteboardType + ) + } + + func collectionView(_ collectionView: NSCollectionView, canDragItemsAt indexes: IndexSet, with event: NSEvent) -> Bool { + return true + } +} diff --git a/Persephone/Controllers/AlbumViewController.swift b/Persephone/Controllers/AlbumViewController.swift index 3758504..6dc83d8 100644 --- a/Persephone/Controllers/AlbumViewController.swift +++ b/Persephone/Controllers/AlbumViewController.swift @@ -11,11 +11,7 @@ import ReSwift import Differ class AlbumViewController: NSViewController, - NSCollectionViewDelegate, NSCollectionViewDelegateFlowLayout { - let paddingWidth: CGFloat = 40 - let gutterWidth: CGFloat = 20 - var dataSource = AlbumDataSource() override func viewDidLoad() { @@ -28,6 +24,8 @@ class AlbumViewController: NSViewController, albumScrollView.postsBoundsChangedNotifications = true albumCollectionView.dataSource = dataSource + + registerForDragAndDrop(albumCollectionView) } deinit { diff --git a/Persephone/Controllers/AlbumViewItem.swift b/Persephone/Controllers/AlbumViewItem.swift index 674515c..39c65b4 100644 --- a/Persephone/Controllers/AlbumViewItem.swift +++ b/Persephone/Controllers/AlbumViewItem.swift @@ -12,6 +12,12 @@ class AlbumViewItem: NSCollectionViewItem { var observer: NSKeyValueObservation? var album: Album? + override var isSelected: Bool { + didSet { + //albumCoverBox.isHidden = !isSelected + } + } + override func viewDidLoad() { super.viewDidLoad() @@ -20,6 +26,15 @@ class AlbumViewItem: NSCollectionViewItem { albumCoverView.layer?.borderWidth = 1 setAppearance() +// albumCoverBox.wantsLayer = true +// albumCoverBox.layer?.cornerRadius = 5 +// albumCoverBox.layer?.borderWidth = 8 +// if #available(OSX 10.14, *) { +// albumCoverBox.layer?.borderColor = NSColor.controlAccentColor.cgColor +// } else { +// albumCoverBox.layer?.borderColor = NSColor.selectedControlColor.cgColor +// } + if #available(OSX 10.14, *) { observer = NSApp.observe(\.effectiveAppearance) { (app, _) in self.setAppearance() @@ -65,12 +80,13 @@ class AlbumViewItem: NSCollectionViewItem { AlbumDetailView.popover.contentViewController = AlbumDetailView.shared AlbumDetailView.popover.behavior = .transient AlbumDetailView.popover.show( - relativeTo: sender.bounds, - of: sender, + relativeTo: albumCoverView.bounds, + of: albumCoverView, preferredEdge: .maxY ) } + @IBOutlet var albumCoverBox: NSBox! @IBOutlet var albumCoverView: NSButton! @IBOutlet var albumTitle: NSTextField! @IBOutlet var albumArtist: NSTextField! diff --git a/Persephone/DataSources/QueueDataSource.swift b/Persephone/DataSources/QueueDataSource.swift index 28a4adf..a2820b4 100644 --- a/Persephone/DataSources/QueueDataSource.swift +++ b/Persephone/DataSources/QueueDataSource.swift @@ -125,5 +125,4 @@ class QueueDataSource: NSObject, NSOutlineViewDataSource { } } } - } diff --git a/Persephone/Extensions/NSPasteboard.swift b/Persephone/Extensions/NSPasteboard.swift index 52e9401..7f5efa3 100644 --- a/Persephone/Extensions/NSPasteboard.swift +++ b/Persephone/Extensions/NSPasteboard.swift @@ -9,5 +9,6 @@ import AppKit extension NSPasteboard.PasteboardType { - static let songPasteboardType = NSPasteboard.PasteboardType("me.danbarber.persephone") + static let songPasteboardType = NSPasteboard.PasteboardType("me.danbarber.persephone.song") + static let albumPasteboardType = NSPasteboard.PasteboardType("me.danbarber.persephone.album") } diff --git a/Persephone/Extensions/NSPasteboardItem.swift b/Persephone/Extensions/NSPasteboardItem.swift index e28303d..b691f38 100644 --- a/Persephone/Extensions/NSPasteboardItem.swift +++ b/Persephone/Extensions/NSPasteboardItem.swift @@ -14,12 +14,23 @@ extension NSPasteboardItem { self.setDraggedSong(draggedSong, forType: type) } + convenience init(draggedAlbum: DraggedAlbum, ofType type: NSPasteboard.PasteboardType) { + self.init() + self.setDraggedAlbum(draggedAlbum, forType: type) + } + func setDraggedSong(_ draggedSong: DraggedSong, forType type: NSPasteboard.PasteboardType) { let data = try! PropertyListEncoder().encode(draggedSong) setData(data, forType: type) } + func setDraggedAlbum(_ draggedAlbum: DraggedAlbum, forType type: NSPasteboard.PasteboardType) { + let data = try! PropertyListEncoder().encode(draggedAlbum) + + setData(data, forType: type) + } + func draggedSong(forType type: NSPasteboard.PasteboardType) -> DraggedSong? { guard let itemData = data(forType: type) else { return nil } diff --git a/Persephone/Layouts/AlbumViewLayout.swift b/Persephone/Layouts/AlbumViewLayout.swift index 774bb19..2ea3bc0 100644 --- a/Persephone/Layouts/AlbumViewLayout.swift +++ b/Persephone/Layouts/AlbumViewLayout.swift @@ -9,20 +9,20 @@ import AppKit class AlbumViewLayout: NSCollectionViewFlowLayout { - let maxItemWidth: CGFloat = 180 - let albumInfoHeight: CGFloat = 39 + let maxItemWidth: CGFloat = 200 + let albumInfoHeight: CGFloat = 44 var scrollPosition: CGFloat = 0 required init?(coder aDecoder: NSCoder) { super.init() - minimumLineSpacing = 20 - minimumInteritemSpacing = 20 + minimumLineSpacing = 0 + minimumInteritemSpacing = 0 sectionInset = NSEdgeInsets( - top: 20, - left: 40, - bottom: 60, - right: 40 + top: 10, + left: 30, + bottom: 50, + right: 30 ) } diff --git a/Persephone/Resources/AlbumDetailView.xib b/Persephone/Resources/AlbumDetailView.xib index 9bbdc8b..8f736e3 100644 --- a/Persephone/Resources/AlbumDetailView.xib +++ b/Persephone/Resources/AlbumDetailView.xib @@ -17,7 +17,7 @@ - + @@ -47,6 +47,10 @@ + + + + + + + + + + + + + - + @@ -30,48 +59,28 @@ - + - - - - - - - - - - + + + - - - - - - - + + + + + + - - - - + diff --git a/Persephone/Resources/Base.lproj/Main.storyboard b/Persephone/Resources/Base.lproj/Main.storyboard index 3caba28..af4eb28 100644 --- a/Persephone/Resources/Base.lproj/Main.storyboard +++ b/Persephone/Resources/Base.lproj/Main.storyboard @@ -757,9 +757,6 @@ - - - @@ -806,7 +803,7 @@ - +