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"
|
|
|
|
|
2007-03-14 02:28:30 +00:00
|
|
|
#import "IndexFormatter.h"
|
|
|
|
#import "SecondsFormatter.h"
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@implementation PlaylistView
|
|
|
|
|
2006-04-28 23:19:14 +00:00
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
2007-02-17 18:29:20 +00:00
|
|
|
[super awakeFromNib];
|
|
|
|
|
2007-05-23 11:08:56 +00:00
|
|
|
[[self menu] setAutoenablesItems:NO];
|
|
|
|
|
2006-04-28 23:19:14 +00:00
|
|
|
NSControlSize s = NSSmallControlSize;
|
2007-02-17 18:29:20 +00:00
|
|
|
NSEnumerator *oe = [[self allTableColumns] objectEnumerator];
|
2006-04-28 23:19:14 +00:00
|
|
|
NSFont *f = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:s]];
|
2007-05-23 12:00:44 +00:00
|
|
|
NSFont *bf = [[NSFontManager sharedFontManager] convertFont:f toHaveTrait:NSBoldFontMask];
|
|
|
|
|
|
|
|
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
|
|
|
|
[self setRowHeight:[layoutManager defaultLineHeightForFont:bf]];
|
|
|
|
[layoutManager release];
|
2006-04-28 23:19:14 +00:00
|
|
|
|
|
|
|
//Resize the fonts
|
2007-02-17 18:29:20 +00:00
|
|
|
id c;
|
2006-04-28 23:19:14 +00:00
|
|
|
while (c = [oe nextObject])
|
|
|
|
{
|
|
|
|
[[c dataCell] setControlSize:s];
|
2007-05-23 12:00:44 +00:00
|
|
|
|
|
|
|
//Using the bold font defined from the default system font with the bold trait added seems to fix problems related to bold display with some fonts.
|
|
|
|
[[c dataCell] setFont:bf];
|
2006-04-28 23:19:14 +00:00
|
|
|
}
|
2007-03-14 02:28:30 +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];
|
2007-03-14 02:28:30 +00:00
|
|
|
|
2007-03-14 03:16:37 +00:00
|
|
|
//Set up formatters
|
2007-03-14 02:28:30 +00:00
|
|
|
NSFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
|
|
|
[[[self tableColumnWithIdentifier:@"length"] dataCell] setFormatter:secondsFormatter];
|
|
|
|
[secondsFormatter release];
|
|
|
|
|
|
|
|
NSFormatter *indexFormatter = [[IndexFormatter alloc] init];
|
|
|
|
[[[self tableColumnWithIdentifier:@"index"] dataCell] setFormatter:indexFormatter];
|
|
|
|
[indexFormatter release];
|
2007-03-14 03:16:37 +00:00
|
|
|
//end setting up formatters
|
|
|
|
|
2006-04-29 00:03:28 +00:00
|
|
|
[self setVerticalMotionCanBeginDrag:YES];
|
2007-03-14 03:16:37 +00:00
|
|
|
|
|
|
|
//Set up header context menu
|
|
|
|
headerContextMenu = [[NSMenu alloc] initWithTitle:@"Playlist Header Context Menu"];
|
|
|
|
|
|
|
|
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"headerCell.title" ascending:YES];
|
|
|
|
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
|
|
|
|
NSEnumerator *e = [[[[self allTableColumns] allObjects] sortedArrayUsingDescriptors: sortDescriptors] objectEnumerator];
|
|
|
|
|
|
|
|
int menuIndex = 0;
|
|
|
|
NSTableColumn *col;
|
|
|
|
while (col = [e nextObject]) {
|
|
|
|
NSMenuItem *contextMenuItem = [headerContextMenu insertItemWithTitle:[[col headerCell] title] action:@selector(toggleColumn:) keyEquivalent:@"" atIndex:menuIndex];
|
|
|
|
|
|
|
|
[contextMenuItem setTarget:self];
|
|
|
|
[contextMenuItem setRepresentedObject:col];
|
|
|
|
[contextMenuItem setState:([[self visibleTableColumns] containsObject:col] ? NSOnState : NSOffState)];
|
|
|
|
|
|
|
|
menuIndex++;
|
|
|
|
}
|
|
|
|
[sortDescriptor release];
|
|
|
|
|
|
|
|
[[self headerView] setMenu:headerContextMenu];
|
2006-06-19 00:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-17 19:33:31 +00:00
|
|
|
- (IBAction)toggleColumn:(id)sender
|
2006-06-19 00:39:41 +00:00
|
|
|
{
|
2007-02-17 19:33:31 +00:00
|
|
|
id tc = [sender representedObject];
|
2007-02-17 18:29:20 +00:00
|
|
|
|
|
|
|
if ([sender state] == NSOffState)
|
|
|
|
{
|
|
|
|
[sender setState:NSOnState];
|
2006-06-19 00:39:41 +00:00
|
|
|
|
2007-02-17 18:29:20 +00:00
|
|
|
[self showTableColumn:tc];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[sender setState:NSOffState];
|
|
|
|
[self hideTableColumn:tc];
|
|
|
|
}
|
2006-06-19 00:39:41 +00:00
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
2007-02-18 18:59:23 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
- (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
|
|
|
|
{
|
2007-03-10 14:23:35 +00:00
|
|
|
if ([e type] == NSLeftMouseDown && [e clickCount] == 2 && [self selectedRow] != -1)
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2006-01-20 15:22:03 +00:00
|
|
|
[playbackController play:self];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[super mouseDown:e];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-23 15:12:24 +00:00
|
|
|
// 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];
|
2007-05-23 11:08:56 +00:00
|
|
|
if (!currentRowIsSelected) {
|
|
|
|
if (row == -1)
|
|
|
|
{
|
|
|
|
[self deselectAll:self];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self selectRow:row byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NSLog(@"Number of selected rows: %i", [self numberOfSelectedRows]);
|
2006-05-23 15:12:24 +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;
|
2007-05-23 11:08:56 +00:00
|
|
|
for (i=0;i<[tableViewMenu numberOfItems];i++) {
|
2006-05-23 15:12:24 +00:00
|
|
|
[[tableViewMenu itemAtIndex:i] setEnabled:NO];
|
2007-05-23 11:08:56 +00:00
|
|
|
NSLog(@"Enabled: %@ %i", [[tableViewMenu itemAtIndex:i] title], [[tableViewMenu itemAtIndex:i] isEnabled]);
|
|
|
|
}
|
|
|
|
NSLog(@"All disabled!");
|
2006-05-23 15:12:24 +00:00
|
|
|
return [tableViewMenu autorelease];
|
|
|
|
}
|
|
|
|
else
|
2007-05-23 11:08:56 +00:00
|
|
|
{
|
2006-05-23 15:12:24 +00:00
|
|
|
return [self menu];
|
2007-05-23 11:08:56 +00:00
|
|
|
}
|
2006-05-23 15:12:24 +00:00
|
|
|
}
|
|
|
|
|
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];
|
2007-03-12 22:15:35 +00:00
|
|
|
|
|
|
|
if (c == NSDeleteCharacter || c == NSBackspaceCharacter || c == NSDeleteFunctionKey)
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
[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
|