cog/Playlist/PlaylistView.m

243 lines
5.4 KiB
Matlab
Raw Normal View History

2005-06-02 18:16:43 +00:00
//
// PlaylistView.m
// Cog
//
// Created by Vincent Spader on 3/20/05.
2005-07-02 21:02:06 +00:00
// Copyright 2005 Vincent Spader All rights reserved.
2005-06-02 18:16:43 +00:00
//
#import "PlaylistView.h"
2006-01-20 15:22:03 +00:00
#import "PlaybackController.h"
2005-06-02 18:16:43 +00:00
#import "PlaylistController.h"
2006-05-29 22:23:56 +00:00
#import "PlaylistHeaderView.h"
2005-06-02 18:16:43 +00:00
@implementation PlaylistView
2006-04-28 23:19:14 +00:00
- (void)awakeFromNib
{
id c;
NSControlSize s = NSSmallControlSize;
NSEnumerator *oe = [[self tableColumns] objectEnumerator];
NSFont *f = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:s]];
[self setRowHeight:[f defaultLineHeightForFont]];
//Resize the fonts
while (c = [oe nextObject])
{
[[c dataCell] setControlSize:s];
[[c dataCell] setFont:f];
}
2006-04-29 00:03:28 +00:00
2006-05-29 22:23:56 +00:00
NSTableHeaderView *currentTableHeaderView = [self headerView];
PlaylistHeaderView *customTableHeaderView = [[PlaylistHeaderView alloc] init];
[customTableHeaderView setFrame:[currentTableHeaderView frame]];
[customTableHeaderView setBounds:[currentTableHeaderView bounds]];
2006-06-19 00:39:41 +00:00
// [self setColumnAutoresizingStyle:NSTableViewNoColumnAutoresizing];
2006-05-29 22:23:56 +00:00
[self setHeaderView:customTableHeaderView];
2006-04-29 00:03:28 +00:00
[self setVerticalMotionCanBeginDrag:YES];
2006-06-04 19:44:06 +00:00
2006-06-19 00:39:41 +00:00
//Hack for bindings and columns
_tableColumnsCache = [[NSArray alloc] initWithArray:[self tableColumns] copyItems:NO];
}
- (IBAction)takeBoolForTitle:(id)sender
{
[self showColumn:sender withIdentifier:@"title"];
}
- (IBAction)takeBoolForArtist:(id)sender
{
[self showColumn:sender withIdentifier:@"artist"];
}
- (IBAction)takeBoolForAlbum:(id)sender
{
[self showColumn:sender withIdentifier:@"album"];
}
- (IBAction)takeBoolForLength:(id)sender
{
[self showColumn:sender withIdentifier:@"length"];
}
- (IBAction)takeBoolForYear:(id)sender
{
[self showColumn:sender withIdentifier:@"year"];
}
- (IBAction)takeBoolForGenre:(id)sender
{
[self showColumn:sender withIdentifier:@"genre"];
}
- (IBAction)takeBoolForTrack:(id)sender
{
[self showColumn:sender withIdentifier:@"track"];
2006-06-04 19:44:06 +00:00
}
2006-06-19 00:39:41 +00:00
- (void)showColumn:(id)sender withIdentifier:(NSString *)identifier
2006-06-04 19:44:06 +00:00
{
2006-06-19 00:39:41 +00:00
if ([sender state] == NSOffState)
2006-06-04 19:44:06 +00:00
{
2006-06-19 00:39:41 +00:00
[sender setState:NSOnState];
[self showColumnWithIdentifier:identifier];
}
else
{
[sender setState:NSOffState];
[self hideColumnWithIdentifier:identifier];
2006-06-04 19:44:06 +00:00
}
}
2006-06-19 00:39:41 +00:00
- (void)hideColumnWithIdentifier:(NSString *)identifier
2006-06-04 19:44:06 +00:00
{
2006-06-19 00:39:41 +00:00
NSTableColumn *tc = [super tableColumnWithIdentifier:identifier];
if (!tc)
return;
2006-06-04 19:44:06 +00:00
2006-06-19 00:39:41 +00:00
[self removeTableColumn:tc];
2006-06-04 19:44:06 +00:00
}
2006-06-19 00:39:41 +00:00
- (void)showColumnWithIdentifier:(NSString *)identifier
2006-06-04 19:44:06 +00:00
{
2006-06-19 00:39:41 +00:00
if ([super tableColumnWithIdentifier:identifier])
return;
NSEnumerator *e = [_tableColumnsCache objectEnumerator];
NSTableColumn *t = nil;
while (t = [e nextObject])
{
// Locate cached version if there is one.
if ([[t identifier] isEqualToString:identifier])
// Remove it from the array and release the array if it isn't needed any more.
[self addTableColumn:t];
}
2006-06-04 19:44:06 +00:00
}
2006-06-19 00:39:41 +00:00
//FUN HACKS SO COLUMNS DONT DISAPPEAR WHEN THE TABLE IS AUTOSAVED
2006-06-04 19:44:06 +00:00
- (NSTableColumn *)tableColumnWithIdentifier:(id)anObject
{
NSTableColumn *tc = [super tableColumnWithIdentifier:anObject];
2006-06-19 00:39:41 +00:00
if (!tc)
2006-06-04 19:44:06 +00:00
{
2006-06-19 00:39:41 +00:00
NSEnumerator *e = [_tableColumnsCache objectEnumerator];
2006-06-04 19:44:06 +00:00
NSTableColumn *t = nil;
while (t = [e nextObject])
{
// Locate cached version if there is one.
if ([[t identifier] isEqual:anObject])
// Remove it from the array and release the array if it isn't needed any more.
return t;
}
}
return tc;
2006-04-28 23:19:14 +00:00
}
2005-06-02 18:16:43 +00:00
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (BOOL)resignFirstResponder
{
return YES;
}
2005-06-30 17:46:07 +00:00
- (BOOL)acceptsFirstMouse:(NSEvent *)mouseDownEvent
{
return NO;
}
2005-06-02 18:16:43 +00:00
- (void)mouseDown:(NSEvent *)e
{
2006-04-29 00:03:28 +00:00
NSLog(@"MOUSE DOWN");
2005-06-02 18:16:43 +00:00
if ([e type] == NSLeftMouseDown && [e clickCount] == 2)
{
2006-01-20 15:22:03 +00:00
[playbackController play:self];
2005-06-02 18:16:43 +00:00
}
else
{
2006-04-29 00:03:28 +00:00
NSLog(@"Super");
2005-06-02 18:16:43 +00:00
[super mouseDown:e];
}
}
// enables right-click selection for "Show in Finder" contextual menu
-(NSMenu*)menuForEvent:(NSEvent*)event
{
//Find which row is under the cursor
[[self window] makeFirstResponder:self];
NSPoint menuPoint = [self convertPoint:[event locationInWindow] fromView:nil];
int row = [self rowAtPoint:menuPoint];
/* Update the table selection before showing menu
Preserves the selection if the row under the mouse is selected (to allow for
multiple items to be selected), otherwise selects the row under the mouse */
BOOL currentRowIsSelected = [[self selectedRowIndexes] containsIndex:row];
if (!currentRowIsSelected)
[self selectRow:row byExtendingSelection:NO];
2006-05-29 22:23:56 +00:00
if ([self numberOfSelectedRows] <=0)
{
//No rows are selected, so the table should be displayed with all items disabled
NSMenu* tableViewMenu = [[self menu] copy];
int i;
for (i=0;i<[tableViewMenu numberOfItems];i++)
[[tableViewMenu itemAtIndex:i] setEnabled:NO];
return [tableViewMenu autorelease];
}
else
return [self menu];
}
2005-06-02 18:16:43 +00:00
- (void)keyDown:(NSEvent *)e
{
NSString *s;
unichar c;
s = [e charactersIgnoringModifiers];
if ([s length] != 1)
return;
c = [s characterAtIndex:0];
if (c == NSDeleteCharacter)
{
[playlistController remove:self];
}
else if (c == ' ')
{
2006-01-20 15:22:03 +00:00
[playbackController playPauseResume:self];
2005-06-02 18:16:43 +00:00
}
else if (c == NSEnterCharacter || c == NSCarriageReturnCharacter)
{
2006-01-20 15:22:03 +00:00
[playbackController play:self];
2005-06-02 18:16:43 +00:00
}
else
{
[super keyDown:e];
}
}
2006-05-29 23:03:58 +00:00
- (IBAction)sortByPath:(id)sender
{
[self setSortDescriptors:nil];
[playlistController sortByPath];
}
- (IBAction)shufflePlaylist:(id)sender
{
[self setSortDescriptors:nil];
[playlistController randomizeList];
}
2005-06-02 18:16:43 +00:00
@end