Playback Buttons: Made stop button optional, hidden by default

CQTexperiment
Christopher Snowhill 2022-01-24 22:05:00 -08:00
parent fa67b79b22
commit 4bc3a2a1f3
2 changed files with 45 additions and 12 deletions

View File

@ -467,11 +467,11 @@
<point key="canvasLocation" x="450" y="-52"/> <point key="canvasLocation" x="450" y="-52"/>
</customView> </customView>
<customView id="CgN-sy-RmM" userLabel="AppearanceView"> <customView id="CgN-sy-RmM" userLabel="AppearanceView">
<rect key="frame" x="0.0" y="0.0" width="530" height="46"/> <rect key="frame" x="0.0" y="0.0" width="530" height="74"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="haX-dq-OIe"> <button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="haX-dq-OIe">
<rect key="frame" x="18" y="15" width="329" height="18"/> <rect key="frame" x="18" y="43" width="329" height="18"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="check" title="Colorful dock icons" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="GdX-5e-NeU"> <buttonCell key="cell" type="check" title="Colorful dock icons" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="GdX-5e-NeU">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/> <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
@ -481,6 +481,17 @@
<binding destination="52" name="value" keyPath="values.colorfulDockIcons" id="NZt-v6-8iW"/> <binding destination="52" name="value" keyPath="values.colorfulDockIcons" id="NZt-v6-8iW"/>
</connections> </connections>
</button> </button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="AA7-fr-NOk">
<rect key="frame" x="18" y="15" width="329" height="18"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="check" title="Show stop button" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="vMI-lj-Lrz">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<binding destination="52" name="value" keyPath="values.enableStopButton" id="JH0-bm-IC4"/>
</connections>
</button>
</subviews> </subviews>
<point key="canvasLocation" x="450" y="139"/> <point key="canvasLocation" x="450" y="139"/>
</customView> </customView>

View File

@ -30,29 +30,47 @@ static NSString *PlaybackButtonsPlaybackStatusObservationContext = @"PlaybackBut
- (void)startObserving - (void)startObserving
{ {
[playbackController addObserver:self forKeyPath:@"playbackStatus" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:(__bridge void * _Nullable)(PlaybackButtonsPlaybackStatusObservationContext)]; [playbackController addObserver:self forKeyPath:@"playbackStatus" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:(__bridge void * _Nullable)(PlaybackButtonsPlaybackStatusObservationContext)];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.enableStopButton" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:(__bridge void * _Nullable)(PlaybackButtonsPlaybackStatusObservationContext)];
} }
- (void)stopObserving - (void)stopObserving
{ {
[playbackController removeObserver:self forKeyPath:@"playbackStatus"]; [playbackController removeObserver:self forKeyPath:@"playbackStatus"];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.enableStopButton"];
} }
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{ {
if ([PlaybackButtonsPlaybackStatusObservationContext isEqual:(__bridge id)(context)]) if ([PlaybackButtonsPlaybackStatusObservationContext isEqual:(__bridge id)(context)])
{ {
NSInteger playbackStatus = [[change objectForKey:NSKeyValueChangeNewKey] integerValue]; if ([keyPath isEqualToString:@"playbackStatus"])
{
NSInteger playbackStatus = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
NSImage *image = nil; NSImage *image = nil;
if (playbackStatus == CogStatusPlaying) { if (playbackStatus == CogStatusPlaying) {
image = [NSImage imageNamed:@"pauseTemplate"]; image = [NSImage imageNamed:@"pauseTemplate"];
} }
else { else {
image = [NSImage imageNamed:@"playTemplate"]; image = [NSImage imageNamed:@"playTemplate"];
} }
[self setImage:image forSegment:1]; [self setImage:image forSegment:1];
}
else if ([keyPath isEqualToString:@"values.enableStopButton"])
{
BOOL segmentEnabled = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"enableStopButton"];
if (segmentEnabled) {
[self setSegmentCount:4];
[self setImage:[NSImage imageNamed:@"stopTemplate"] forSegment:2];
[self setImage:[NSImage imageNamed:@"nextTemplate"] forSegment:3];
}
else {
[self setSegmentCount:3];
[self setImage:[NSImage imageNamed:@"nextTemplate"] forSegment:2];
}
}
} }
else else
{ {
@ -63,8 +81,12 @@ static NSString *PlaybackButtonsPlaybackStatusObservationContext = @"PlaybackBut
- (BOOL)sendAction:(SEL)theAction to:(id)theTarget - (BOOL)sendAction:(SEL)theAction to:(id)theTarget
{ {
DLog(@"Mouse down!"); DLog(@"Mouse down!");
int clickedSegment = (int) [self selectedSegment];
int segmentCount = (int) [self segmentCount];
if (segmentCount == 3 && clickedSegment == 2)
clickedSegment = 3;
int clickedSegment = (int) [self selectedSegment];
if (clickedSegment == 0) //Previous if (clickedSegment == 0) //Previous
{ {
[playbackController prev:self]; [playbackController prev:self];