From 4bc3a2a1f328b999e0b2ee6a683dd217b6025b5a Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Mon, 24 Jan 2022 22:05:00 -0800 Subject: [PATCH] Playback Buttons: Made stop button optional, hidden by default --- .../Preferences/Base.lproj/Preferences.xib | 15 ++++++- Window/PlaybackButtons.m | 42 ++++++++++++++----- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/Preferences/Preferences/Base.lproj/Preferences.xib b/Preferences/Preferences/Base.lproj/Preferences.xib index 52566f149..7e7852c4b 100644 --- a/Preferences/Preferences/Base.lproj/Preferences.xib +++ b/Preferences/Preferences/Base.lproj/Preferences.xib @@ -467,11 +467,11 @@ - + + diff --git a/Window/PlaybackButtons.m b/Window/PlaybackButtons.m index c027d004f..559d61a52 100644 --- a/Window/PlaybackButtons.m +++ b/Window/PlaybackButtons.m @@ -30,29 +30,47 @@ static NSString *PlaybackButtonsPlaybackStatusObservationContext = @"PlaybackBut - (void)startObserving { [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 { [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 { 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) { - image = [NSImage imageNamed:@"pauseTemplate"]; - } - else { - image = [NSImage imageNamed:@"playTemplate"]; - } + if (playbackStatus == CogStatusPlaying) { + image = [NSImage imageNamed:@"pauseTemplate"]; + } + else { + 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 { @@ -63,8 +81,12 @@ static NSString *PlaybackButtonsPlaybackStatusObservationContext = @"PlaybackBut - (BOOL)sendAction:(SEL)theAction to:(id)theTarget { 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 { [playbackController prev:self];