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

Drag and drop works properly now

This commit is contained in:
Daniel Barber 2019-06-15 17:43:00 -04:00
parent aef5b8534b
commit 95323e8a6f
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
5 changed files with 38 additions and 13 deletions

View File

@ -22,7 +22,6 @@ class QueueViewController: NSViewController {
$0.select { $0.queueState } $0.select { $0.queueState }
} }
// queueView.dataSource = dataSource
queueView.columnAutoresizingStyle = .sequentialColumnAutoresizingStyle queueView.columnAutoresizingStyle = .sequentialColumnAutoresizingStyle
queueView.registerForDraggedTypes([REORDER_PASTEBOARD_TYPE]) queueView.registerForDraggedTypes([REORDER_PASTEBOARD_TYPE])
queueView.draggingDestinationFeedbackStyle = .regular queueView.draggingDestinationFeedbackStyle = .regular

View File

@ -45,17 +45,26 @@ class QueueDataSource: NSObject, NSOutlineViewDataSource {
guard let queueItem = item as? QueueItem guard let queueItem = item as? QueueItem
else { return nil } else { return nil }
let pbItem = NSPasteboardItem() let pasteboardItem = NSPasteboardItem()
pbItem.setPropertyList(["queuePos": queueItem.queuePos], forType: REORDER_PASTEBOARD_TYPE) pasteboardItem.setPropertyList(["queuePos": queueItem.queuePos], forType: REORDER_PASTEBOARD_TYPE)
return pbItem return pasteboardItem
} }
func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation { func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation {
var newQueuePos = index - 1
guard let draggingTypes = info.draggingPasteboard.types, guard let draggingTypes = info.draggingPasteboard.types,
draggingTypes.contains(REORDER_PASTEBOARD_TYPE), draggingTypes.contains(REORDER_PASTEBOARD_TYPE),
index >= 0 let payload = info.draggingPasteboard.propertyList(forType: REORDER_PASTEBOARD_TYPE) as? [String: Int],
let queuePos = payload["queuePos"],
newQueuePos >= 0
else { return [] }
if newQueuePos > queuePos { newQueuePos -= 1 }
guard queuePos != newQueuePos
else { return [] } else { return [] }
return .move return .move
@ -70,7 +79,8 @@ class QueueDataSource: NSObject, NSOutlineViewDataSource {
if newQueuePos > queuePos { newQueuePos -= 1 } if newQueuePos > queuePos { newQueuePos -= 1 }
guard queuePos != newQueuePos else { return false } guard queuePos != newQueuePos
else { return false }
App.store.dispatch(MPDMoveSongInQueue(oldQueuePos: queuePos, newQueuePos: newQueuePos)) App.store.dispatch(MPDMoveSongInQueue(oldQueuePos: queuePos, newQueuePos: newQueuePos))

View File

@ -8,8 +8,14 @@
import AppKit import AppKit
struct QueueItem: Equatable { struct QueueItem: Hashable {
var song: Song var song: Song
var queuePos: Int var queuePos: Int
var isPlaying: Bool var isPlaying: Bool
func hash(into hasher: inout Hasher) {
hasher.combine(song)
hasher.combine(queuePos)
hasher.combine(isPlaying)
}
} }

View File

@ -43,3 +43,13 @@ extension Song: Equatable {
(lhs.album == rhs.album) (lhs.album == rhs.album)
} }
} }
extension Song: Hashable {
func hash(into hasher: inout Hasher) {
hasher.combine(mpdSong.uriString)
hasher.combine(trackNumber)
hasher.combine(title)
hasher.combine(artist)
hasher.combine(album.title)
}
}

View File

@ -578,17 +578,17 @@
<rect key="frame" x="0.0" y="0.0" width="328" height="548"/> <rect key="frame" x="0.0" y="0.0" width="328" height="548"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews> <subviews>
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="S3o-nF-NN7"> <scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="22" horizontalPageScroll="10" verticalLineScroll="22" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="S3o-nF-NN7">
<rect key="frame" x="0.0" y="0.0" width="328" height="219"/> <rect key="frame" x="0.0" y="0.0" width="328" height="219"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<clipView key="contentView" drawsBackground="NO" id="WI8-Pw-03L"> <clipView key="contentView" drawsBackground="NO" id="WI8-Pw-03L">
<rect key="frame" x="0.0" y="0.0" width="328" height="219"/> <rect key="frame" x="0.0" y="0.0" width="328" height="219"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="sourceList" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" indentationPerLevel="16" outlineTableColumn="0Co-uF-CCB" id="jEJ-jg-fll" customClass="QueueView" customModule="Persephone" customModuleProvider="target"> <outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="sourceList" multipleSelection="NO" autosaveColumns="NO" rowHeight="22" rowSizeStyle="automatic" viewBased="YES" indentationPerLevel="14" outlineTableColumn="0Co-uF-CCB" id="jEJ-jg-fll" customClass="QueueView" customModule="Persephone" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="328" height="219"/> <rect key="frame" x="0.0" y="0.0" width="328" height="219"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/> <size key="intercellSpacing" width="3" height="0.0"/>
<color key="backgroundColor" name="_sourceListBackgroundColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="_sourceListBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/> <color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns> <tableColumns>
@ -606,7 +606,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES"/> <tableColumnResizingMask key="resizingMask" resizeWithTable="YES"/>
<prototypeCellViews> <prototypeCellViews>
<tableCellView identifier="queueHeadingCell" id="GOd-cg-juD"> <tableCellView identifier="queueHeadingCell" id="GOd-cg-juD">
<rect key="frame" x="1" y="1" width="200" height="17"/> <rect key="frame" x="1" y="0.0" width="200" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<textField verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xgd-Cz-np3"> <textField verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xgd-Cz-np3">
@ -627,7 +627,7 @@
</constraints> </constraints>
</tableCellView> </tableCellView>
<tableCellView identifier="songTitleCell" id="5rR-Gz-AcP" customClass="QueueSongTitleView" customModule="Persephone" customModuleProvider="target"> <tableCellView identifier="songTitleCell" id="5rR-Gz-AcP" customClass="QueueSongTitleView" customModule="Persephone" customModuleProvider="target">
<rect key="frame" x="1" y="20" width="200" height="17"/> <rect key="frame" x="1" y="17" width="200" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<imageView identifier="queuePlayerState" translatesAutoresizingMaskIntoConstraints="NO" id="o8i-cz-hIP" userLabel="Player State View"> <imageView identifier="queuePlayerState" translatesAutoresizingMaskIntoConstraints="NO" id="o8i-cz-hIP" userLabel="Player State View">
@ -687,7 +687,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES"/> <tableColumnResizingMask key="resizingMask" resizeWithTable="YES"/>
<prototypeCellViews> <prototypeCellViews>
<tableCellView identifier="songArtistCell" id="JSk-Vc-Y7e"> <tableCellView identifier="songArtistCell" id="JSk-Vc-Y7e">
<rect key="frame" x="204" y="1" width="122" height="17"/> <rect key="frame" x="204" y="0.0" width="122" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="tBe-Q9-3Rw"> <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="tBe-Q9-3Rw">