2009-03-07 22:31:57 +00:00
|
|
|
//
|
|
|
|
// InfoWindowController.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 3/7/09.
|
|
|
|
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "InfoWindowController.h"
|
2022-02-07 05:49:27 +00:00
|
|
|
#import "AppController.h"
|
|
|
|
#import "Logging.h"
|
2009-03-08 20:04:09 +00:00
|
|
|
#import "MissingAlbumArtTransformer.h"
|
2021-04-25 02:25:29 +00:00
|
|
|
#import "PlaylistEntry.h"
|
2009-03-07 22:31:57 +00:00
|
|
|
|
|
|
|
@implementation InfoWindowController
|
|
|
|
|
2022-06-15 23:47:43 +00:00
|
|
|
static void *kInfoWindowControllerContext = &kInfoWindowControllerContext;
|
|
|
|
|
2013-10-11 19:10:30 +00:00
|
|
|
@synthesize valueToDisplay;
|
2009-03-07 22:31:57 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (void)initialize {
|
2016-05-05 20:05:39 +00:00
|
|
|
NSValueTransformer *missingAlbumArtTransformer = [[MissingAlbumArtTransformer alloc] init];
|
2022-02-07 05:49:27 +00:00
|
|
|
[NSValueTransformer setValueTransformer:missingAlbumArtTransformer
|
|
|
|
forName:@"MissingAlbumArtTransformer"];
|
2009-03-08 20:04:09 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (id)init {
|
2009-03-07 22:31:57 +00:00
|
|
|
return [super initWithWindowNibName:@"InfoInspector"];
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
- (void)awakeFromNib {
|
2022-06-15 23:47:43 +00:00
|
|
|
[playlistSelectionController addObserver:self forKeyPath:@"selection" options:NSKeyValueObservingOptionNew context:kInfoWindowControllerContext];
|
|
|
|
[currentEntryController addObserver:self forKeyPath:@"content" options:NSKeyValueObservingOptionNew context:kInfoWindowControllerContext];
|
|
|
|
[appController addObserver:self forKeyPath:@"miniMode" options:NSKeyValueObservingOptionNew context:kInfoWindowControllerContext];
|
2013-10-11 19:10:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
2022-06-15 23:47:43 +00:00
|
|
|
if(context == kInfoWindowControllerContext) {
|
|
|
|
// Avoid "selection" because it creates a proxy that's hard to reason with when we don't need to write.
|
|
|
|
PlaylistEntry *currentSelection = [[playlistSelectionController selectedObjects] firstObject];
|
|
|
|
if(currentSelection != NULL) {
|
|
|
|
[self setValueToDisplay:currentSelection];
|
|
|
|
} else {
|
|
|
|
[self setValueToDisplay:[currentEntryController content]];
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
2022-06-15 23:47:43 +00:00
|
|
|
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
2013-10-11 19:10:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (IBAction)toggleWindow:(id)sender {
|
|
|
|
if([[self window] isVisible])
|
2009-03-07 22:31:57 +00:00
|
|
|
[[self window] orderOut:self];
|
2022-02-07 05:49:27 +00:00
|
|
|
else {
|
|
|
|
if([NSApp mainWindow]) {
|
|
|
|
NSRect rect = [[NSApp mainWindow] frame];
|
|
|
|
// Align Info Inspector HUD Panel to the right of Main Window.
|
|
|
|
NSPoint point = NSMakePoint(NSMaxX(rect), NSMaxY(rect));
|
|
|
|
[[self window] setFrameTopLeftPoint:point];
|
|
|
|
}
|
|
|
|
[self showWindow:self];
|
|
|
|
}
|
2009-03-07 22:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|