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

Render the current playing track in bold

This commit is contained in:
Daniel Barber 2019-02-05 19:29:46 -05:00
parent dc86de752d
commit 24cc5181b8
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
3 changed files with 59 additions and 9 deletions

View File

@ -778,7 +778,7 @@
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="songTitleColumn" width="222" minWidth="128" maxWidth="1000" id="0Co-uF-CCB">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Title">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
@ -841,7 +841,7 @@
</prototypeCellViews>
</tableColumn>
<tableColumn identifier="songArtistColumn" width="222" minWidth="128" maxWidth="1000" id="SPM-QP-DX8">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Artist">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>

View File

@ -73,6 +73,7 @@ class MPDClient {
self.delegate?.didUpdateState(mpdClient: self, state: self.status!.state())
self.delegate?.didUpdateQueue(mpdClient: self, queue: self.queue)
self.delegate?.didUpdateQueuePos(mpdClient: self, song: self.status!.song())
idle()
}
@ -190,6 +191,7 @@ class MPDClient {
if mpdIdle.contains(.player) {
self.fetchStatus()
self.delegate?.didUpdateState(mpdClient: self, state: self.status!.state())
self.delegate?.didUpdateQueuePos(mpdClient: self, song: self.status!.song())
}
if !mpdIdle.isEmpty {
self.idle()

View File

@ -11,6 +11,15 @@ import mpdclient
class QueueController: NSViewController, NSOutlineViewDataSource, NSOutlineViewDelegate {
var queue: [MPDClient.Song] = []
var queuePos: Int32 = -1
let songTitleColumn = NSUserInterfaceItemIdentifier("songTitleColumm")
let songArtistColumn = NSUserInterfaceItemIdentifier("songArtistColumm")
struct SongItem {
var song: MPDClient.Song
var queuePos: Int
}
override func viewDidLoad() {
super.viewDidLoad()
@ -23,6 +32,13 @@ class QueueController: NSViewController, NSOutlineViewDataSource, NSOutlineViewD
name: MPDClient.queueChanged,
object: AppDelegate.mpdClient
)
NotificationCenter.default.addObserver(
self,
selector: #selector(queuePosChanged(_:)),
name: MPDClient.queuePosChanged,
object: AppDelegate.mpdClient
)
}
@objc func queueChanged(_ notification: Notification) {
@ -34,6 +50,38 @@ class QueueController: NSViewController, NSOutlineViewDataSource, NSOutlineViewD
queueView.reloadData()
}
@objc func queuePosChanged(_ notification: Notification) {
guard let queuePos = notification.userInfo?[MPDClient.queuePosKey] as? Int32
else { return }
if self.queuePos > -1 {
let oldSongRow = queueView.rowView(atRow: Int(self.queuePos + 1), makeIfNecessary: true)
let oldSongTitleCell = oldSongRow?.view(atColumn: 0) as! NSTableCellView
let oldSongArtistCell = oldSongRow?.view(atColumn: 1) as! NSTableCellView
oldSongTitleCell.textField?.font = NSFont.systemFont(ofSize: 13, weight: .regular)
oldSongArtistCell.textField?.font = NSFont.systemFont(ofSize: 13, weight: .regular)
//oldSongTitleCell.needsDisplay = true
//oldSongArtistCell.needsDisplay = true
}
let oldQueuePos = self.queuePos
self.queuePos = queuePos
let songRow = queueView.rowView(atRow: Int(self.queuePos + 1), makeIfNecessary: true)
let songTitleCell = songRow?.view(atColumn: 0) as! NSTableCellView
let songArtistCell = songRow?.view(atColumn: 1) as! NSTableCellView
songTitleCell.textField?.font = NSFont.systemFont(ofSize: 13, weight: .bold)
songArtistCell.textField?.font = NSFont.systemFont(ofSize: 13, weight: .bold)
//songTitleCell.needsDisplay = true
//songArtistCell.needsDisplay = true
queueView.reloadData(
forRowIndexes: [Int(oldQueuePos + 1), Int(queuePos + 1)],
columnIndexes: [0, 1]
)
}
func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
return queue.count + 1
}
@ -44,31 +92,31 @@ class QueueController: NSViewController, NSOutlineViewDataSource, NSOutlineViewD
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
if index > 0 {
return queue[index - 1]
return SongItem(song: queue[index - 1], queuePos: index - 1)
} else {
return ""
}
}
func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
if let song = item as? MPDClient.Song {
if let songItem = item as? SongItem {
switch tableColumn?.identifier.rawValue {
case "songTitleColumn":
let cellView = outlineView.makeView(
withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "songTitleCell"),
withIdentifier: NSUserInterfaceItemIdentifier("songTitleCell"),
owner: self
) as! NSTableCellView
cellView.textField?.stringValue = song.getTag(MPD_TAG_TITLE)
cellView.textField?.stringValue = songItem.song.getTag(MPD_TAG_TITLE)
return cellView
case "songArtistColumn":
let cellView = outlineView.makeView(
withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "songArtistCell"),
withIdentifier: NSUserInterfaceItemIdentifier("songArtistCell"),
owner: self
) as! NSTableCellView
cellView.textField?.stringValue = song.getTag(MPD_TAG_ARTIST)
cellView.textField?.stringValue = songItem.song.getTag(MPD_TAG_ARTIST)
return cellView
default:
@ -77,7 +125,7 @@ class QueueController: NSViewController, NSOutlineViewDataSource, NSOutlineViewD
} else {
if tableColumn?.identifier.rawValue == "songTitleColumn" {
let cellView = outlineView.makeView(
withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "queueHeadingCell"),
withIdentifier: NSUserInterfaceItemIdentifier("queueHeadingCell"),
owner: self
) as! NSTableCellView