From 7b416e58773fea2f8ef27629c8e067817beeb9cd Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Fri, 11 Oct 2013 12:10:30 -0700 Subject: [PATCH] mamburu: Info window now shows info for currently playing track in mini mode --- InfoInspector/InfoWindowController.h | 10 ++++++++-- InfoInspector/InfoWindowController.m | 28 +++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/InfoInspector/InfoWindowController.h b/InfoInspector/InfoWindowController.h index a9feab1da..07f05a840 100644 --- a/InfoInspector/InfoWindowController.h +++ b/InfoInspector/InfoWindowController.h @@ -7,13 +7,19 @@ // #import +#import "AppController.h" -@interface InfoWindowController : NSWindowController { +@interface InfoWindowController : NSWindowController +{ IBOutlet id playlistSelectionController; + IBOutlet id currentEntryController; + IBOutlet AppController *appController; + + id valueToDisplay; } -@property(readonly) id playlistSelectionController; +@property(assign) id valueToDisplay; - (IBAction)toggleWindow:(id)sender; diff --git a/InfoInspector/InfoWindowController.m b/InfoInspector/InfoWindowController.m index f5a815510..923a54bc0 100644 --- a/InfoInspector/InfoWindowController.m +++ b/InfoInspector/InfoWindowController.m @@ -8,10 +8,12 @@ #import "InfoWindowController.h" #import "MissingAlbumArtTransformer.h" +#import "Logging.h" +#import "AppController.h" @implementation InfoWindowController -@synthesize playlistSelectionController; +@synthesize valueToDisplay; + (void)initialize { @@ -25,6 +27,30 @@ return [super initWithWindowNibName:@"InfoInspector"]; } +- (void)awakeFromNib +{ + [playlistSelectionController addObserver:self forKeyPath:@"selection" options:NSKeyValueObservingOptionNew context:nil]; + [currentEntryController addObserver:self forKeyPath:@"content" options:NSKeyValueObservingOptionNew context:nil]; + [appController addObserver:self forKeyPath:@"miniMode" options:NSKeyValueObservingOptionNew context:nil]; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + BOOL miniMode = [appController miniMode]; + BOOL currentEntryChanged = (object == currentEntryController && [keyPath isEqualTo:@"content"]); + BOOL selectionChanged = (object == playlistSelectionController && [keyPath isEqualTo:@"selection"]); + BOOL miniModeSwitched = (object == appController && [keyPath isEqual:@"miniMode"]); + + if (miniMode && (currentEntryChanged || miniModeSwitched)) + { + [self setValueToDisplay:[currentEntryController content]]; + } + else if (!miniMode && (selectionChanged || miniModeSwitched)) + { + [self setValueToDisplay:[playlistSelectionController selection]]; + } +} + - (IBAction)toggleWindow:(id)sender { if ([[self window] isVisible])