1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

WIP: Dragging works

We need to let drags through the button.
This commit is contained in:
Daniel Barber 2019-06-28 22:34:17 -04:00
parent 95319d9359
commit 52718cfcd6
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
11 changed files with 131 additions and 56 deletions

View File

@ -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 = "<group>"; };
E439109722640213002982E9 /* SongNotifierService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SongNotifierService.swift; sourceTree = "<group>"; };
E43AC1F022C68E6A001E483C /* NSPasteboardItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSPasteboardItem.swift; sourceTree = "<group>"; };
E43AC1F222C6A439001E483C /* AlbumViewController+NSCollectionViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AlbumViewController+NSCollectionViewDelegate.swift"; sourceTree = "<group>"; };
E43AC1F422C6A4F4001E483C /* DraggedAlbum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraggedAlbum.swift; sourceTree = "<group>"; };
E43B67A822909793007DCF55 /* AlbumDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlbumDetailView.swift; sourceTree = "<group>"; };
E43B67A922909793007DCF55 /* AlbumDetailView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AlbumDetailView.xib; sourceTree = "<group>"; };
E43B67AC229194CD007DCF55 /* AlbumTracksDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlbumTracksDataSource.swift; sourceTree = "<group>"; };
@ -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 = "<group>";
@ -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 */,

View File

@ -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
}
}

View File

@ -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 {

View File

@ -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!

View File

@ -125,5 +125,4 @@ class QueueDataSource: NSObject, NSOutlineViewDataSource {
}
}
}
}

View File

@ -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")
}

View File

@ -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 }

View File

@ -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
)
}

View File

@ -17,7 +17,7 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<customView wantsLayer="YES" id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="823" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
@ -47,6 +47,10 @@
<constraint firstAttribute="width" constant="300" id="8XY-bQ-C7X"/>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="300" id="cyo-wr-hV8"/>
</constraints>
<shadow key="shadow" blurRadius="4">
<size key="offset" width="0.0" height="-2"/>
<color key="color" white="0.0" alpha="0.34795884683098594" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</shadow>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="defaultCoverArt" id="scE-kj-gex"/>
</imageView>
<button verticalHuggingPriority="750" imageHugsTitle="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jMU-bv-TNF">

View File

@ -9,20 +9,49 @@
<customObject id="-2" userLabel="File's Owner" customClass="AlbumViewItem" customModule="Persephone" customModuleProvider="target">
<connections>
<outlet property="albumArtist" destination="5Uu-j1-qyT" id="2Et-tX-InT"/>
<outlet property="albumCoverView" destination="Kfb-8f-ean" id="CXx-gB-gz8"/>
<outlet property="albumCoverBox" destination="oat-Vd-t1v" id="aDy-tW-PFO"/>
<outlet property="albumCoverView" destination="juD-33-Glf" id="zPG-vz-USc"/>
<outlet property="albumTitle" destination="KEh-NL-c2W" id="SI3-hm-H2B"/>
<outlet property="imageView" destination="Kfb-8f-ean" id="Ur0-hX-wJm"/>
<outlet property="view" destination="Hz6-mo-xeY" id="v7W-XA-Emc"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY" customClass="AlbumItemView" customModule="Persephone" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="128" height="167"/>
<rect key="frame" x="0.0" y="0.0" width="158" height="192"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<box boxType="custom" borderType="none" cornerRadius="4" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="oat-Vd-t1v">
<rect key="frame" x="5" y="49" width="148" height="138"/>
<view key="contentView" wantsLayer="YES" id="h1X-3X-S5v">
<rect key="frame" x="0.0" y="0.0" width="148" height="138"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="juD-33-Glf">
<rect key="frame" x="5" y="5" width="138" height="128"/>
<shadow key="shadow" blurRadius="4">
<size key="offset" width="0.0" height="2"/>
<color key="color" white="0.0" alpha="0.34603323063380281" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</shadow>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="defaultCoverArt" imagePosition="only" alignment="center" lineBreakMode="truncatingTail" state="on" transparent="YES" imageScaling="proportionallyUpOrDown" inset="2" id="t8A-Hz-L38">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="showAlbumDetail:" target="-2" id="A4Q-gb-B45"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="juD-33-Glf" firstAttribute="top" secondItem="h1X-3X-S5v" secondAttribute="top" constant="5" id="aa9-xp-ssN"/>
<constraint firstAttribute="bottom" secondItem="juD-33-Glf" secondAttribute="bottom" constant="5" id="chP-h2-dVN"/>
<constraint firstItem="juD-33-Glf" firstAttribute="leading" secondItem="h1X-3X-S5v" secondAttribute="leading" constant="5" id="wpA-lb-lHS"/>
<constraint firstAttribute="trailing" secondItem="juD-33-Glf" secondAttribute="trailing" constant="5" id="z1e-o3-Xt0"/>
</constraints>
</view>
</box>
<textField identifier="albumTitle" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="KEh-NL-c2W">
<rect key="frame" x="-2" y="18" width="132" height="17"/>
<rect key="frame" x="8" y="28" width="142" height="17"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" title="Label" id="pDs-0t-e1j">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -30,48 +59,28 @@
</textFieldCell>
</textField>
<textField identifier="albumArtist" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5Uu-j1-qyT">
<rect key="frame" x="-2" y="0.0" width="132" height="17"/>
<rect key="frame" x="8" y="10" width="142" height="17"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" title="Label" id="yZn-e9-zyP">
<font key="font" metaFont="system"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<imageView identifier="albumArtwork" horizontalHuggingPriority="750" verticalHuggingPriority="750" placeholderIntrinsicWidth="128" placeholderIntrinsicHeight="128" translatesAutoresizingMaskIntoConstraints="NO" id="Kfb-8f-ean">
<rect key="frame" x="0.0" y="39" width="128" height="128"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="defaultCoverArt" id="FsA-JX-BFh"/>
</imageView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="x5e-56-uVO" userLabel="Album Detail Button">
<rect key="frame" x="0.0" y="39" width="128" height="128"/>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" alignment="center" lineBreakMode="truncatingTail" state="on" imageScaling="proportionallyDown" inset="2" id="MTh-fn-aCH">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="showAlbumDetail:" target="-2" id="nO1-4H-LHS"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="x5e-56-uVO" firstAttribute="leading" secondItem="Kfb-8f-ean" secondAttribute="leading" id="1Hi-Uk-rkL"/>
<constraint firstItem="5Uu-j1-qyT" firstAttribute="trailing" secondItem="KEh-NL-c2W" secondAttribute="trailing" id="64z-uz-4nY"/>
<constraint firstAttribute="bottom" secondItem="KEh-NL-c2W" secondAttribute="bottom" constant="18" id="8Kg-1r-wNp"/>
<constraint firstItem="x5e-56-uVO" firstAttribute="trailing" secondItem="Kfb-8f-ean" secondAttribute="trailing" id="BYd-Fg-DVb"/>
<constraint firstItem="Kfb-8f-ean" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="JMi-4i-dgs"/>
<constraint firstAttribute="trailing" secondItem="Kfb-8f-ean" secondAttribute="trailing" id="KQC-Wz-Bsg"/>
<constraint firstAttribute="bottom" secondItem="KEh-NL-c2W" secondAttribute="bottom" constant="28" id="8Kg-1r-wNp"/>
<constraint firstAttribute="bottom" secondItem="oat-Vd-t1v" secondAttribute="bottom" constant="49" id="9be-hX-hie"/>
<constraint firstItem="oat-Vd-t1v" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="5" id="HYh-A2-m7g"/>
<constraint firstItem="5Uu-j1-qyT" firstAttribute="leading" secondItem="KEh-NL-c2W" secondAttribute="leading" id="MUo-0i-fX9"/>
<constraint firstItem="Kfb-8f-ean" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="Qbk-jx-zAi"/>
<constraint firstItem="KEh-NL-c2W" firstAttribute="trailing" secondItem="Kfb-8f-ean" secondAttribute="trailing" id="U0w-G4-ggX"/>
<constraint firstItem="KEh-NL-c2W" firstAttribute="leading" secondItem="Kfb-8f-ean" secondAttribute="leading" id="V8r-Rc-Dx7"/>
<constraint firstAttribute="bottom" secondItem="5Uu-j1-qyT" secondAttribute="bottom" id="gci-4h-pDZ"/>
<constraint firstItem="x5e-56-uVO" firstAttribute="top" secondItem="Kfb-8f-ean" secondAttribute="top" id="hw2-ik-6VW"/>
<constraint firstItem="x5e-56-uVO" firstAttribute="bottom" secondItem="Kfb-8f-ean" secondAttribute="bottom" id="iVQ-Vn-dSV"/>
<constraint firstAttribute="bottom" secondItem="Kfb-8f-ean" secondAttribute="bottom" constant="39" id="sid-zJ-YMA"/>
<constraint firstItem="oat-Vd-t1v" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="5" id="PHC-uH-EH6"/>
<constraint firstAttribute="bottom" secondItem="5Uu-j1-qyT" secondAttribute="bottom" constant="10" id="gci-4h-pDZ"/>
<constraint firstItem="KEh-NL-c2W" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="10" id="hG2-cb-UqL"/>
<constraint firstAttribute="trailing" secondItem="oat-Vd-t1v" secondAttribute="trailing" constant="5" id="nD3-RG-rfr"/>
<constraint firstItem="KEh-NL-c2W" firstAttribute="top" secondItem="oat-Vd-t1v" secondAttribute="bottom" constant="4" id="rOI-E8-Odh"/>
<constraint firstItem="KEh-NL-c2W" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="ubc-MA-g7H"/>
</constraints>
<connections>
<outlet property="imageView" destination="Kfb-8f-ean" id="T7Z-En-dU3"/>
</connections>
<point key="canvasLocation" x="-22" y="125.5"/>
<point key="canvasLocation" x="-20" y="112"/>
</customView>
<collectionViewItem id="Qgu-aI-55A" customClass="AlbumViewItem" customModule="Persephone" customModuleProvider="target"/>
</objects>

View File

@ -757,9 +757,6 @@
<constraint firstAttribute="width" secondItem="iUb-eV-Qws" secondAttribute="height" multiplier="1:1" id="f4L-V4-5x2"/>
<constraint firstItem="Dw3-M5-tWY" firstAttribute="top" secondItem="iUb-eV-Qws" secondAttribute="top" id="ue4-Gb-CaX"/>
</constraints>
<shadow key="shadow">
<color key="color" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</shadow>
</customView>
</subviews>
<holdingPriorities>
@ -806,7 +803,7 @@
<rect key="frame" x="0.0" y="0.0" width="450" height="300"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<collectionView identifier="albumCollectionView" id="lfq-AB-epE">
<collectionView identifier="albumCollectionView" selectable="YES" id="lfq-AB-epE">
<rect key="frame" x="0.0" y="0.0" width="450" height="158"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<collectionViewLayout key="collectionViewLayout" id="YE8-sD-l5P" customClass="AlbumViewLayout" customModule="Persephone" customModuleProvider="target"/>