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

Update state of transport controls on state change

This commit is contained in:
Daniel Barber 2019-02-02 13:20:40 -05:00
parent 6bd29cdf00
commit 22926d343f
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
3 changed files with 20 additions and 1 deletions

View File

@ -18,5 +18,8 @@
"info" : { "info" : {
"version" : 1, "version" : 1,
"author" : "xcode" "author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
} }
} }

View File

@ -696,7 +696,7 @@
<toolbarItem implicitItemIdentifier="2D01DD0F-DDD1-411E-9270-20E2B5B07FC2" label="Controls" paletteLabel="Controls" sizingBehavior="auto" id="p3r-ty-Pxf"> <toolbarItem implicitItemIdentifier="2D01DD0F-DDD1-411E-9270-20E2B5B07FC2" label="Controls" paletteLabel="Controls" sizingBehavior="auto" id="p3r-ty-Pxf">
<nil key="toolTip"/> <nil key="toolTip"/>
<segmentedControl key="view" verticalHuggingPriority="750" id="Bbf-C6-1Gu"> <segmentedControl key="view" verticalHuggingPriority="750" id="Bbf-C6-1Gu">
<rect key="frame" x="0.0" y="14" width="153" height="23"/> <rect key="frame" x="0.0" y="14" width="153" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="texturedRounded" trackingMode="momentary" id="EBk-sD-nG7"> <segmentedCell key="cell" borderStyle="border" alignment="left" style="texturedRounded" trackingMode="momentary" id="EBk-sD-nG7">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@ -740,6 +740,7 @@
</window> </window>
<connections> <connections>
<outlet property="stateLabel" destination="KVt-e7-7I5" id="xMD-Iq-CSh"/> <outlet property="stateLabel" destination="KVt-e7-7I5" id="xMD-Iq-CSh"/>
<outlet property="transportControls" destination="EBk-sD-nG7" id="yOo-58-Fby"/>
<segue destination="fnD-7K-pHK" kind="relationship" relationship="window.shadowedContentViewController" id="fQQ-kB-KVc"/> <segue destination="fnD-7K-pHK" kind="relationship" relationship="window.shadowedContentViewController" id="fQQ-kB-KVc"/>
</connections> </connections>
</windowController> </windowController>

View File

@ -33,6 +33,20 @@ class WindowController: NSWindowController {
else { return } else { return }
stateLabel.stringValue = "\(state)".localizedCapitalized stateLabel.stringValue = "\(state)".localizedCapitalized
setTransportControlState(state)
}
func setTransportControlState(_ state: MPDClient.State) {
transportControls.setEnabled([.playing, .paused].contains(state), forSegment: 0)
transportControls.setEnabled([.playing, .paused, .stopped].contains(state), forSegment: 1)
transportControls.setEnabled([.playing, .paused].contains(state), forSegment: 2)
transportControls.setEnabled([.playing, .paused].contains(state), forSegment: 3)
if [.paused, .stopped, .unknown].contains(state) {
transportControls.setImage(NSImage(named: NSImage.Name(rawValue: "playButton")), forSegment: 1)
} else {
transportControls.setImage(NSImage(named: NSImage.Name(rawValue: "pauseButton")), forSegment: 1)
}
} }
@IBAction func handleTransportControl(_ sender: NSSegmentedControl) { @IBAction func handleTransportControl(_ sender: NSSegmentedControl) {
@ -52,4 +66,5 @@ class WindowController: NSWindowController {
} }
@IBOutlet var stateLabel: NSTextField! @IBOutlet var stateLabel: NSTextField!
@IBOutlet var transportControls: NSSegmentedCell!
} }