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])